/** Create a new exception API object. */ public static Value __construct( Env env, @This ObjectValue value, @Optional StringValue message, @Optional("0") int code) { value.putField(env, "message", message); value.putField(env, "code", LongValue.create(code)); Location location = env.getLocation(); if (location != null) { if (location.getFileName() != null) { value.putField(env, "file", env.createString(location.getFileName())); } else { value.putField(env, "file", env.createString("unknown")); } value.putField(env, "line", LongValue.create(location.getLineNumber())); } value.putField(env, "trace", ErrorModule.debug_backtrace(env, false)); BiancaException e = new BiancaException(); e.fillInStackTrace(); value.putField(env, "_biancaException", env.wrapJava(e)); return value; }
private static void addFormFile( Env env, ArrayValue files, String fileName, String tmpName, String mimeType, long fileLength, boolean addSlashesToValues, long maxFileSize) { ArrayValue entry = new ArrayValueImpl(); int error; // php/1667 long uploadMaxFilesize = env.getIniBytes("upload_max_filesize", 2 * 1024 * 1024); if (fileName.length() == 0) // php/0864 error = FileModule.UPLOAD_ERR_NO_FILE; else if (fileLength > uploadMaxFilesize) error = FileModule.UPLOAD_ERR_INI_SIZE; else if (fileLength > maxFileSize) error = FileModule.UPLOAD_ERR_FORM_SIZE; else error = FileModule.UPLOAD_ERR_OK; addFormValue(env, entry, "name", env.createString(fileName), null, addSlashesToValues); long size; if (error != FileModule.UPLOAD_ERR_INI_SIZE) { size = fileLength; } else { mimeType = ""; tmpName = ""; size = 0; } if (mimeType != null) { addFormValue(env, entry, "type", env.createString(mimeType), null, addSlashesToValues); entry.put("type", mimeType); } addFormValue(env, entry, "tmp_name", env.createString(tmpName), null, addSlashesToValues); addFormValue(env, entry, "error", LongValue.create(error), null, addSlashesToValues); addFormValue(env, entry, "size", LongValue.create(size), null, addSlashesToValues); addFormValue(env, files, null, entry, null, addSlashesToValues); }
public static Value objectToValue(Object obj) { if (obj == null) { return NullValue.NULL; } else if (Byte.class.equals(obj.getClass()) || Short.class.equals(obj.getClass()) || Integer.class.equals(obj.getClass()) || Long.class.equals(obj.getClass())) { return LongValue.create(((Number) obj).longValue()); } else if (Float.class.equals(obj.getClass()) || Double.class.equals(obj.getClass())) { return DoubleValue.create(((Number) obj).doubleValue()); } else if (String.class.equals(obj.getClass())) { // TODO: i18n return new StringValue((String) obj); } else { // TODO: unknown types, e.g. Character? return null; } }
public static void addFormValue( Env env, ArrayValue array, String key, Value formValue, String[] formValueList, boolean addSlashesToValues) { int p = -1; int q = -1; if (key != null) { p = key.indexOf('['); q = key.indexOf(']', p); } if (p >= 0 && p < q) { String index = key; Value keyValue; Value existingValue; if (p > 0) { key = key.substring(0, p); key = key.replaceAll("\\.", "_"); keyValue = env.createString(key); existingValue = array.get(keyValue); if (existingValue == null || !existingValue.isset()) { existingValue = new ArrayValueImpl(); array.put(keyValue, existingValue); } else if (!existingValue.isArray()) { // existing is overwritten // php/115g existingValue = new ArrayValueImpl(); array.put(keyValue, existingValue); } array = (ArrayValue) existingValue; } int p1; while ((p1 = index.indexOf('[', q)) > 0) { key = index.substring(p + 1, q); if (key.equals("")) { existingValue = new ArrayValueImpl(); array.put(existingValue); } else { keyValue = env.createString(key); existingValue = array.get(keyValue); if (existingValue == null || !existingValue.isset()) { existingValue = new ArrayValueImpl(); array.put(keyValue, existingValue); } else if (!existingValue.isArray()) { existingValue = new ArrayValueImpl().put(existingValue); array.put(keyValue, existingValue); } } array = (ArrayValue) existingValue; p = p1; q = index.indexOf(']', p); } if (q > 0) index = index.substring(p + 1, q); else index = index.substring(p + 1); if (index.equals("")) { if (formValueList != null) { for (int i = 0; i < formValueList.length; i++) { Value value; if (formValueList[i] != null) value = env.createString(formValueList[i]); else value = NullValue.NULL; put(array, null, value, addSlashesToValues); } } else array.put(formValue); } else if ('0' <= index.charAt(0) && index.charAt(0) <= '9') put(array, LongValue.create(StringValue.toLong(index)), formValue, addSlashesToValues); else put(array, env.createString(index), formValue, addSlashesToValues); } else { if (key != null) { key = key.replaceAll("\\.", "_"); put(array, env.createString(key), formValue, addSlashesToValues); } else { put(array, null, formValue, addSlashesToValues); } } }
private static void addFormFile( Env env, ArrayValue files, String name, String fileName, String tmpName, String mimeType, long fileLength, boolean addSlashesToValues, long maxFileSize) { int p = name.indexOf('['); String index = ""; if (p >= 0) { index = name.substring(p); name = name.substring(0, p); } StringValue nameValue = env.createString(name); Value v = files.get(nameValue).toValue(); ArrayValue entry = null; if (v instanceof ArrayValue) entry = (ArrayValue) v; if (entry == null) { entry = new ArrayValueImpl(); files.put(nameValue, entry); } int error; // php/1667 long uploadMaxFilesize = env.getIniBytes("upload_max_filesize", 2 * 1024 * 1024); if (fileName.length() == 0) // php/0864 error = FileModule.UPLOAD_ERR_NO_FILE; else if (fileLength > uploadMaxFilesize) error = FileModule.UPLOAD_ERR_INI_SIZE; else if (fileLength > maxFileSize) error = FileModule.UPLOAD_ERR_FORM_SIZE; else error = FileModule.UPLOAD_ERR_OK; addFormValue(env, entry, "name" + index, env.createString(fileName), null, addSlashesToValues); long size; if (error == FileModule.UPLOAD_ERR_OK) { size = fileLength; } else { mimeType = ""; tmpName = ""; size = 0; } if (mimeType != null) { addFormValue( env, entry, "type" + index, env.createString(mimeType), null, addSlashesToValues); } addFormValue( env, entry, "tmp_name" + index, env.createString(tmpName), null, addSlashesToValues); addFormValue(env, entry, "error" + index, LongValue.create(error), null, addSlashesToValues); addFormValue(env, entry, "size" + index, LongValue.create(size), null, addSlashesToValues); addFormValue(env, files, name, entry, null, addSlashesToValues); }
/** * Returns an object with the following fields: * * <p>name: The name of the column orgname: The original name if an alias was specified table: The * name of the table orgtable: The original name if an alias was specified def: default value for * this field, represented as a string max_length: The maximum width of the field for the result * set flags: An integer representing the bit-flags for the field type: An integer respresenting * the data type used for this field decimals: The number of decimals used (for integer fields) * * @param env the PHP executing environment * @param fieldLength the field length as defined in the table declaration. * @param name the field name * @param originalName the field original name * @param table the field table name * @param type the field type * @param scale the field scale * @return an object containing field metadata */ protected Value fetchFieldImproved( Env env, int fieldLength, String name, String originalName, String table, int jdbcType, String mysqlType, int scale) { Value result = env.createObject(); try { ResultSetMetaData md = getMetaData(); if (!_rs.next()) return BooleanValue.FALSE; result.putField(env, "name", env.createString(name)); result.putField(env, "orgname", env.createString(originalName)); result.putField(env, "table", env.createString(table)); // XXX: orgtable same as table result.putField(env, "orgtable", env.createString(table)); result.putField(env, "def", env.createString(_rs.getString(6))); // "max_length" is the maximum width of this field in this // result set. result.putField(env, "max_length", LongValue.ZERO); // "length" is the width of the field defined in the table // declaration. result.putField(env, "length", LongValue.create(fieldLength)); // generate flags long flags = 0; if (!isInResultString(4, "YES")) flags += MysqliModule.NOT_NULL_FLAG; if (isInResultString(5, "PRI")) { flags += MysqliModule.PRI_KEY_FLAG; flags += MysqliModule.PART_KEY_FLAG; } if (isInResultString(5, "MUL")) { flags += MysqliModule.MULTIPLE_KEY_FLAG; flags += MysqliModule.PART_KEY_FLAG; } if (isInResultString(2, "blob") || (jdbcType == Types.LONGVARCHAR) || (jdbcType == Types.LONGVARBINARY)) flags += MysqliModule.BLOB_FLAG; if (isInResultString(2, "unsigned")) flags += MysqliModule.UNSIGNED_FLAG; if (isInResultString(2, "zerofill")) flags += MysqliModule.ZEROFILL_FLAG; // php/1f73 - null check if (isInResultString(3, "bin") || (jdbcType == Types.LONGVARBINARY) || (jdbcType == Types.DATE) || (jdbcType == Types.TIMESTAMP)) flags += MysqliModule.BINARY_FLAG; if (isInResultString(2, "enum")) flags += MysqliModule.ENUM_FLAG; if (isInResultString(7, "auto")) flags += MysqliModule.AUTO_INCREMENT_FLAG; if (isInResultString(2, "set")) flags += MysqliModule.SET_FLAG; if ((jdbcType == Types.BIGINT) || (jdbcType == Types.BIT) || (jdbcType == Types.BOOLEAN) || (jdbcType == Types.DECIMAL) || (jdbcType == Types.DOUBLE) || (jdbcType == Types.REAL) || (jdbcType == Types.INTEGER) || (jdbcType == Types.SMALLINT)) flags += MysqliModule.NUM_FLAG; result.putField(env, "flags", LongValue.create(flags)); // generate PHP type int quercusType = 0; switch (jdbcType) { case Types.DECIMAL: quercusType = MysqliModule.MYSQLI_TYPE_DECIMAL; break; case Types.BIT: // Connector-J enables the tinyInt1isBit property // by default and converts TINYINT to BIT. Use // the mysql type name to tell the two apart. if (mysqlType.equals("BIT")) { quercusType = MysqliModule.MYSQLI_TYPE_BIT; } else { quercusType = MysqliModule.MYSQLI_TYPE_TINY; } break; case Types.SMALLINT: quercusType = MysqliModule.MYSQLI_TYPE_SHORT; break; case Types.INTEGER: { if (!isInResultString(2, "medium")) quercusType = MysqliModule.MYSQLI_TYPE_LONG; else quercusType = MysqliModule.MYSQLI_TYPE_INT24; break; } case Types.REAL: quercusType = MysqliModule.MYSQLI_TYPE_FLOAT; break; case Types.DOUBLE: quercusType = MysqliModule.MYSQLI_TYPE_DOUBLE; break; case Types.BIGINT: quercusType = MysqliModule.MYSQLI_TYPE_LONGLONG; break; case Types.DATE: if (mysqlType.equals("YEAR")) { quercusType = MysqliModule.MYSQLI_TYPE_YEAR; } else { quercusType = MysqliModule.MYSQLI_TYPE_DATE; } break; case Types.TINYINT: quercusType = MysqliModule.MYSQLI_TYPE_TINY; break; case Types.TIME: quercusType = MysqliModule.MYSQLI_TYPE_TIME; break; case Types.TIMESTAMP: if (mysqlType.equals("TIMESTAMP")) { quercusType = MysqliModule.MYSQLI_TYPE_TIMESTAMP; } else { quercusType = MysqliModule.MYSQLI_TYPE_DATETIME; } break; case Types.LONGVARBINARY: case Types.LONGVARCHAR: quercusType = MysqliModule.MYSQLI_TYPE_BLOB; break; case Types.BINARY: case Types.CHAR: quercusType = MysqliModule.MYSQLI_TYPE_STRING; break; case Types.VARBINARY: case Types.VARCHAR: quercusType = MysqliModule.MYSQLI_TYPE_VAR_STRING; break; // XXX: may need to revisit default default: quercusType = MysqliModule.MYSQLI_TYPE_NULL; break; } result.putField(env, "type", LongValue.create(quercusType)); result.putField(env, "decimals", LongValue.create(scale)); // The "charsetnr" field is an integer identifier // for the character set used to encode the field. // This integer is sent by the server to the JDBC client // and is stored as com.mysql.jdbc.Field.charsetIndex, // but this field is private and the class does not provide // any means to access the field. There is also no way // to lookup the mysql index given a Java or Mysql encoding // name. result.putField(env, "charsetnr", LongValue.ZERO); } catch (SQLException e) { log.log(Level.FINE, e.toString(), e); return BooleanValue.FALSE; } return result; }
protected Value fetchFieldImproved(Env env, ResultSetMetaData md, int offset) { Value result = env.createObject(); try { int jdbcType = md.getColumnType(offset); String catalogName = md.getCatalogName(offset); String fieldTable = md.getTableName(offset); String fieldSchema = md.getSchemaName(offset); String fieldName = md.getColumnName(offset); String fieldAlias = md.getColumnLabel(offset); String mysqlType = md.getColumnTypeName(offset); int fieldLength = md.getPrecision(offset); int scale = md.getScale(offset); if ((fieldTable == null || "".equals(fieldTable)) && ((Mysqli) getConnection()).isLastSqlDescribe()) fieldTable = "COLUMNS"; result.putField(env, "name", env.createString(fieldAlias)); result.putField(env, "orgname", env.createString(fieldName)); result.putField(env, "table", env.createString(fieldTable)); // XXX: orgtable same as table result.putField(env, "orgtable", env.createString(fieldTable)); result.putField(env, "def", env.createString("")); // "max_length" is the maximum width of this field in this // result set. result.putField(env, "max_length", LongValue.ZERO); // "length" is the width of the field defined in the table // declaration. result.putField(env, "length", LongValue.create(fieldLength)); // generate flags long flags = 0; result.putField(env, "flags", LongValue.create(flags)); // generate PHP type int quercusType = 0; switch (jdbcType) { case Types.DECIMAL: quercusType = MysqliModule.MYSQLI_TYPE_DECIMAL; break; case Types.BIT: // Connector-J enables the tinyInt1isBit property // by default and converts TINYINT to BIT. Use // the mysql type name to tell the two apart. if (mysqlType.equals("BIT")) { quercusType = MysqliModule.MYSQLI_TYPE_BIT; } else { quercusType = MysqliModule.MYSQLI_TYPE_TINY; } break; case Types.SMALLINT: quercusType = MysqliModule.MYSQLI_TYPE_SHORT; break; case Types.INTEGER: { if (!isInResultString(2, "medium")) quercusType = MysqliModule.MYSQLI_TYPE_LONG; else quercusType = MysqliModule.MYSQLI_TYPE_INT24; break; } case Types.REAL: quercusType = MysqliModule.MYSQLI_TYPE_FLOAT; break; case Types.DOUBLE: quercusType = MysqliModule.MYSQLI_TYPE_DOUBLE; break; case Types.BIGINT: quercusType = MysqliModule.MYSQLI_TYPE_LONGLONG; break; case Types.DATE: if (mysqlType.equals("YEAR")) { quercusType = MysqliModule.MYSQLI_TYPE_YEAR; } else { quercusType = MysqliModule.MYSQLI_TYPE_DATE; } break; case Types.TINYINT: quercusType = MysqliModule.MYSQLI_TYPE_TINY; break; case Types.TIME: quercusType = MysqliModule.MYSQLI_TYPE_TIME; break; case Types.TIMESTAMP: if (mysqlType.equals("TIMESTAMP")) { quercusType = MysqliModule.MYSQLI_TYPE_TIMESTAMP; } else { quercusType = MysqliModule.MYSQLI_TYPE_DATETIME; } break; case Types.LONGVARBINARY: case Types.LONGVARCHAR: quercusType = MysqliModule.MYSQLI_TYPE_BLOB; break; case Types.BINARY: case Types.CHAR: quercusType = MysqliModule.MYSQLI_TYPE_STRING; break; case Types.VARBINARY: case Types.VARCHAR: quercusType = MysqliModule.MYSQLI_TYPE_VAR_STRING; break; // XXX: may need to revisit default default: quercusType = MysqliModule.MYSQLI_TYPE_NULL; break; } result.putField(env, "type", LongValue.create(quercusType)); result.putField(env, "decimals", LongValue.create(scale)); // The "charsetnr" field is an integer identifier // for the character set used to encode the field. // This integer is sent by the server to the JDBC client // and is stored as com.mysql.jdbc.Field.charsetIndex, // but this field is private and the class does not provide // any means to access the field. There is also no way // to lookup the mysql index given a Java or Mysql encoding // name. result.putField(env, "charsetnr", LongValue.ZERO); } catch (SQLException e) { log.log(Level.FINE, e.toString(), e); return BooleanValue.FALSE; } return result; }