@Override public void set(PreparedStatement prep, int parameterIndex) throws SQLException { prep.setNull(parameterIndex, DataType.convertTypeToSQLType(NULL)); }
/** * Adds a column to the result set. * All columns must be added before adding rows. * This method uses the default SQL type names. * * @param name null is replaced with C1, C2,... * @param sqlType the value returned in getColumnType(..) * @param precision the precision * @param scale the scale */ public void addColumn(String name, int sqlType, int precision, int scale) { int valueType = DataType.convertSQLTypeToValueType(sqlType); addColumn(name, sqlType, DataType.getDataType(valueType).name, precision, scale); }
private Value convertToUnknownValue(Object x) { checkClosed(); return DataType.convertToValue(x, Value.UNKNOWN); }
/** * Returns the Java class name if this column. * * @param columnIndex (1,2,...) * @return the class name */ @Override public String getColumnClassName(int columnIndex) throws SQLException { int type = DataType.getValueTypeFromResultSet(this, columnIndex); return DataType.getTypeClassName(type); }
/** * Convert a value type to a SQL type. * * @param type the value type * @return the SQL type */ public static int convertTypeToSQLType(int type) { return getDataType(type).sqlType; }
"" + DataType.convertTypeToSQLType(c.getType()), identifier(DataType.getDataType(c.getType()).name), for (DataType t : DataType.getTypes()) { if (t.hidden || t.sqlType == Value.NULL) { continue;
/** * Sets the value of a parameter. The object is converted, if required, to * the specified data type before sending to the database. * Objects of unknown classes are serialized (on the client side). * * @param parameterIndex the parameter index (1, 2, ...) * @param x the value, null is allowed * @param targetSqlType the type as defined in java.sql.Types * @throws SQLException if this object is closed */ @Override public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException { try { if (isDebugEnabled()) { debugCode("setObject(" + parameterIndex + ", x, " + targetSqlType + ");"); } int type = DataType.convertSQLTypeToValueType(targetSqlType); if (x == null) { setParameter(parameterIndex, ValueNull.INSTANCE); } else { Value v = DataType.convertToValue(x, type); setParameter(parameterIndex, v.convertTo(type)); } } catch (Exception e) { throw logAndConvert(e); } }
@Override public Row get() { if (current == null) { current = createRow(); for (int i = 0; i < current.getColumnCount(); i++) { Value v = DataType.readValue(rs, i + 1, cols[i].getType()); current.setValue(i, v); } } return current; }
@Override public String getString() { try { StatementBuilder buff = new StatementBuilder("("); result.beforeFirst(); ResultSetMetaData meta = result.getMetaData(); int columnCount = meta.getColumnCount(); for (int i = 0; result.next(); i++) { if (i > 0) { buff.append(", "); } buff.append('('); buff.resetCount(); for (int j = 0; j < columnCount; j++) { buff.appendExceptFirst(", "); int t = DataType.getValueTypeFromResultSet(meta, j + 1); Value v = DataType.readValue(result, j + 1, t); buff.append(v.getString()); } buff.append(')'); } result.beforeFirst(); return buff.append(')').toString(); } catch (SQLException e) { throw DbException.convert(e); } }
scale = convertScale(sqlType, scale); int displaySize = MathUtils.convertLongToInt(precision); int type = DataType.convertSQLTypeToValueType(sqlType); Column col = new Column(n, type, precision, scale, displaySize); col.setTable(this, i++); scale = convertScale(sqlType, scale); int displaySize = rsMeta.getColumnDisplaySize(i + 1); int type = DataType.getValueTypeFromResultSet(rsMeta, i + 1); Column col = new Column(n, type, precision, scale, displaySize); col.setTable(this, i++);
DataType.getDataType(l).name + " " + getOperationToken() + " " + DataType.getDataType(r).name); } else { dataType = Value.getHigherOrder(l, r); if (DataType.isStringType(dataType) && session.getDatabase().getMode().allowPlusForStringConcat) { opType = CONCAT;
/** * Convert a SQL type to a value type using SQL type name, in order to * manage SQL type extension mechanism. * * @param sqlType the SQL type * @param sqlTypeName the SQL type name * @return the value type */ private static int convertSQLTypeToValueType(int sqlType, String sqlTypeName) { return convertSQLTypeToValueType(sqlType); }
/** * Gets the Java class name of the object that will be returned * if ResultSet.getObject is called. * * @param column the column index (1,2,...) * @return the Java class name * @throws SQLException if the result set is closed or invalid */ @Override public String getColumnClassName(int column) throws SQLException { try { debugCodeCall("getColumnClassName", column); checkColumnIndex(column); int type = result.getColumnType(--column); return DataType.getTypeClassName(type); } catch (Exception e) { throw logAndConvert(e); } }
} else if (!DataType.supportsAdd(dataType)) { throw DbException.get(ErrorCode.SUM_OR_AVG_ON_WRONG_DATATYPE_1, getSQL()); } else { dataType = DataType.getAddProofType(dataType); if (!DataType.supportsAdd(dataType)) { throw DbException.get(ErrorCode.SUM_OR_AVG_ON_WRONG_DATATYPE_1, getSQL());
private static DataType createString(boolean caseSensitive) { DataType dataType = new DataType(); dataType.prefix = "'"; dataType.suffix = "'"; dataType.params = "LENGTH"; dataType.caseSensitive = caseSensitive; dataType.supportsPrecision = true; dataType.maxPrecision = Integer.MAX_VALUE; dataType.defaultPrecision = Integer.MAX_VALUE; dataType.defaultDisplaySize = Integer.MAX_VALUE; return dataType; }
private static DataType createLob() { DataType t = createString(true); t.maxPrecision = Long.MAX_VALUE; t.defaultPrecision = Long.MAX_VALUE; return t; }
case Aggregate.AVG: if (value == null) { value = v.convertTo(DataType.getAddProofType(dataType)); } else { v = v.convertTo(value.getType());
public Column(String name, int type, long precision, int scale, int displaySize) { this.name = name; this.type = type; if (precision == -1 && scale == -1 && displaySize == -1) { DataType dt = DataType.getDataType(type); precision = dt.defaultPrecision; scale = dt.defaultScale; displaySize = dt.defaultDisplaySize; } this.precision = precision; this.scale = scale; this.displaySize = displaySize; }
/** * Construct a local result set by reading all data from a regular result * set. * * @param session the session * @param rs the result set * @param maxrows the maximum number of rows to read (0 for no limit) * @return the local result set */ public static LocalResult read(Session session, ResultSet rs, int maxrows) { Expression[] cols = Expression.getExpressionColumns(session, rs); int columnCount = cols.length; LocalResult result = new LocalResult(session, cols, columnCount); try { for (int i = 0; (maxrows == 0 || i < maxrows) && rs.next(); i++) { Value[] list = new Value[columnCount]; for (int j = 0; j < columnCount; j++) { int type = result.getColumnType(j); list[j] = DataType.readValue(rs, j + 1, type); } result.addRow(list); } } catch (SQLException e) { throw DbException.convert(e); } result.done(); return result; }
/** * Get the SQL type from the result set meta data for the given column. This * method uses the SQL type and type name. * * @param meta the meta data * @param columnIndex the column index (1, 2,...) * @return the value type */ public static int getValueTypeFromResultSet(ResultSetMetaData meta, int columnIndex) throws SQLException { return convertSQLTypeToValueType( meta.getColumnType(columnIndex), meta.getColumnTypeName(columnIndex)); }