mysqlmodule.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 1,189 行 · 第 1/3 页
JAVA
1,189 行
else return BooleanValue.FALSE; } /** * Returns a row from the connection */ @ReturnNullAsFalse public static ArrayValue mysql_fetch_assoc(Env env, @NotNull MysqliResult result) { if (result == null) return null; return result.fetch_array(env, MYSQL_ASSOC); } /** * Returns an object containing field information. * On success, this method increments the field offset * (see {@link #mysql_field_seek}). * * <h3>ERRATA</h3> * <ul> * <li>quercus returns "int" for BIT type, php returns "unknown" * <li>quercus always returns int(0) for unique_key * <li>quercus always returns int(0) for zerofill * <li>quercus always returns int(0) for multiple_key * </ul> * */ public static Value mysql_fetch_field(Env env, @NotNull MysqliResult result, @Optional("-1") int fieldOffset) { /** * ERRATA is also documented in php/142s.qa * There is probably a mysql specific query or API that would be better * for getting this information */ if (result == null) return BooleanValue.FALSE; // php/142v.qa - call must succeed even if some info not available try { if (fieldOffset == -1) { fieldOffset = result.field_tell(env); result.setFieldOffset(fieldOffset + 1); } ResultSetMetaData md = result.getMetaData(); if (md.getColumnCount() <= fieldOffset || fieldOffset < 0) { return BooleanValue.FALSE; } int jdbcField = fieldOffset + 1; int jdbcColumnType = md.getColumnType(jdbcField); String catalogName = md.getCatalogName(jdbcField); String tableName = md.getTableName(jdbcField); String schemaName = md.getSchemaName(jdbcField); String columnName = md.getColumnName(jdbcField); String columnLabel = md.getColumnLabel(jdbcField); if (schemaName == null || "".equals(schemaName)) schemaName = tableName; if ((tableName == null || "".equals(tableName)) && result.isLastSqlDescribe()) tableName = "COLUMNS"; // some information is not available from the ResultSetMetaData JdbcColumnMetaData columnMd = null; JdbcConnectionResource conn = getConnection(env).validateConnection(); // php/141p JdbcTableMetaData tableMd = conn.getTableMetaData(catalogName, null, tableName); if (tableMd != null) columnMd = tableMd.getColumn(columnName); // XXX: maxlen note from PHP comments: // the length of the longest value for that field in the returned dataset, // NOT the maximum length of data that column is designed to hold. int maxLength = 0; int notNull = md.isNullable(jdbcField) == ResultSetMetaData.columnNullable ? 0 : 1; int numeric = JdbcColumnMetaData.isNumeric(jdbcColumnType) ? 1 : 0; int blob = JdbcColumnMetaData.isBlob(jdbcColumnType) ? 1 : 0; String type = result.getFieldType(fieldOffset, jdbcColumnType); int unsigned = md.isSigned(jdbcField) ? 0 : numeric; if (jdbcColumnType == Types.BOOLEAN || jdbcColumnType == Types.BIT) unsigned = 0; else if (jdbcColumnType == Types.DECIMAL) numeric = 1; int zerofill = 0; int primaryKey = 0; int multipleKey = 0; int uniqueKey = 0; if (columnMd != null) { zerofill = columnMd.isZeroFill() ? 1 : 0; primaryKey = columnMd.isPrimaryKey() ? 1 : 0; // XXX: not sure what multipleKey is supposed to be // multipleKey = columnMd.isIndex() && !columnMd.isPrimaryKey() ? 1 : 0; uniqueKey = columnMd.isUnique() ? 1 : 0; } else notNull = 1; ObjectValue fieldResult = env.createObject(); fieldResult.putField(env, "name", columnLabel); fieldResult.putField(env, "table", tableName); fieldResult.putField(env, "def", ""); fieldResult.putField(env, "max_length", maxLength); fieldResult.putField(env, "not_null", notNull); fieldResult.putField(env, "primary_key", primaryKey); fieldResult.putField(env, "multiple_key", multipleKey); fieldResult.putField(env, "unique_key", uniqueKey); fieldResult.putField(env, "numeric", numeric); fieldResult.putField(env, "blob", blob); fieldResult.putField(env, "type", type); fieldResult.putField(env, "unsigned", unsigned); fieldResult.putField(env, "zerofill", zerofill); return fieldResult; } catch (SQLException e) { log.log(Level.FINE, e.toString(), e); return BooleanValue.FALSE; } } /** * Executes a query and returns a result set. * * Returns true on update success, false on failure, and a result set * for a successful select */ public static Value mysql_query(Env env, StringValue sql, @Optional Mysqli conn) { if (conn == null) conn = getConnection(env); return conn.query(env, sql, MYSQL_STORE_RESULT); } /** * Returns an array of lengths. */ public static Value mysql_fetch_lengths(Env env, @NotNull MysqliResult result) { if (result == null) return BooleanValue.FALSE; return result.fetch_lengths(); } /** * Returns an object with properties that correspond to the fetched row * and moves the data pointer ahead. */ public static Value mysql_fetch_object(Env env, @NotNull MysqliResult result) { if (result == null) return BooleanValue.FALSE; Value value = result.fetch_object(env); // php/142t // must return FALSE for mediawiki if (value.isNull()) value = BooleanValue.FALSE; return value; } /** * Returns a numerical row from the result, FALSE if no more rows. */ @ReturnNullAsFalse public static ArrayValue mysql_fetch_row(Env env, @NotNull MysqliResult result) { if (result == null) return null; return result.fetch_row(env); } /** * Returns the field flags of the specified field. The flags are reported as * a space separated list of words, the returned value can be split using explode(). * * The following flages are reported, older version of MySQL may not report all flags: * <ul> * <li> not_null * <li> primary_key * <li> multiple_key * <li> blob * <li> unsigned * <li> zerofill * <li> binary * <li> enum * <li> auto_increment * <li> timestamp * </ul> */ public static Value mysql_field_flags(Env env, @NotNull MysqliResult result, int fieldOffset) { if (result == null) return BooleanValue.FALSE; Value fieldName = result.getFieldName(env, fieldOffset); if (fieldName == BooleanValue.FALSE) return BooleanValue.FALSE; Value fieldTable = result.getFieldTable(env, fieldOffset); Value fieldJdbcType = result.getJdbcType(fieldOffset); String fieldMysqlType = result.getMysqlType(fieldOffset); if ((fieldTable == BooleanValue.FALSE) || (fieldJdbcType == BooleanValue.FALSE) || (fieldMysqlType == null)) return BooleanValue.FALSE; String sql = "SHOW FULL COLUMNS FROM " + fieldTable.toString() + " LIKE \'" + fieldName.toString() + "\'"; Mysqli conn = getConnection(env); Value resultV = conn.validateConnection().realQuery(env, sql); Object metaResult = resultV.toJavaObject(); if (metaResult instanceof MysqliResult) return ((MysqliResult) metaResult).getFieldFlagsImproved( env, fieldJdbcType.toInt(), fieldMysqlType); return BooleanValue.FALSE; } /** * Returns field name at given offset. */ public static Value mysql_field_name(Env env, @NotNull MysqliResult result, int fieldOffset) { if (result == null) return BooleanValue.FALSE; // XXX : This method can't detect when mysql_field_name() // is invoked with just 2 arguments instead of 3. The // value 0 is passed for fieldOffsetValue when only // two arguments are found. It is not possible to change // to a Value argument since a NullValue is passed for // both the missing argument and NULL literal argument // cases. Also, Vlaue.isset() can't be used since it // returns false for the default NULL and the literal. return result.getFieldName(env, fieldOffset); } /** * Deprecated alias for mysql_field_name. */ public static Value mysql_fieldname(Env env, @NotNull MysqliResult result, int fieldOffset) { return mysql_field_name(env, result, fieldOffset); } /** * Seeks to the specified field offset, the field offset is * is used as the default for the next call to {@link #mysql_fetch_field}. */ public static boolean mysql_field_seek(Env env, @NotNull MysqliResult result, int fieldOffset) { if (result == null) return false; return result.field_seek(env, fieldOffset); } /** * Returns the table corresponding to the field. */ public static Value mysql_field_table(Env env, @NotNull MysqliResult result, int fieldOffset) { if (result == null) return BooleanValue.FALSE; return result.getFieldTable(env, fieldOffset); } /** * Deprecated alias for mysql_field_table. */ public static Value mysql_fieldtable(Env env, @NotNull MysqliResult result, int fieldOffset) { return mysql_field_table(env, result, fieldOffset); } /** * Returns the field type. */ public static Value mysql_field_type(Env env, @NotNull MysqliResult result, Value fieldOffset) { if (result == null) { return NullValue.NULL; } if (! fieldOffset.isset()) return NullValue.NULL; return result.getFieldType(env, fieldOffset.toInt()); } /** * Deprecated alias for mysql_field_type. */ public static Value mysql_fieldtype(Env env, @NotNull MysqliResult result, Value fieldOffset) { return mysql_field_type(env, result, fieldOffset); } /** * Returns the length of the specified field */ public static Value mysql_field_len(Env env, @NotNull MysqliResult result, @Optional("0") int fieldOffset) { // gallery2 calls this function with 1 arg, so fieldOffset is optional if (result == null) return BooleanValue.FALSE; // ERRATUM: Returns 10 for datatypes DEC and NUMERIC instead of 11 return result.getFieldLength(env, fieldOffset); } /** * Frees a mysql result. */ public static boolean mysql_free_result(@NotNull MysqliResult result) { if (result == null) return false; result.close(); return true; } /** * Alias for mysql_free_result. */ public static boolean mysql_freeresult(@NotNull MysqliResult result) { return mysql_free_result(result); } /** * Returns the MySQL client version. */ public static StringValue mysql_get_client_info(Env env) { return Mysqli.getClientInfo(env);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?