Java Code Examples for java.sql.Types#LONGVARCHAR
The following examples show how to use
java.sql.Types#LONGVARCHAR .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TableJDBC.java From Rel with Apache License 2.0 | 6 votes |
@Override public void delete(Generator generator, ValueTuple tuple) { PreparedStatement preparedStatement; String[] values = CSVLineParse.parseTrimmed(tuple.toCSV()); StringBuffer line = new StringBuffer("delete from " + meta.getTable() + " where "); try { ResultSet resultSet = statement.executeQuery("select * from " + meta.getTable()); for (int i = 1; i <= resultSet.getMetaData().getColumnCount(); i++) { int type = resultSet.getMetaData().getColumnType(i); line.append(resultSet.getMetaData().getColumnName(i) + "="); if (type == Types.CHAR || type == Types.VARCHAR || type == Types.LONGVARCHAR || type == Types.NCHAR || type == Types.NVARCHAR) line.append("\'" + values[i - 1] + "\' AND "); else line.append(values[i - 1] + " AND "); } preparedStatement = connect.prepareStatement(line.substring(0, line.length() - 5) + ";"); preparedStatement.executeUpdate(); } catch (SQLException e) { System.out.println("TableJDBC[3]: error " + e); } }
Example 2
Source File: DatabaseMetaDataProvider.java From morf with Apache License 2.0 | 5 votes |
/** * Converts a given SQL data type to a {@link DataType}. * * @param typeCode JDBC data type. * @param typeName JDBC type name. * @param width JDBC column size. * @return Morf data type. */ protected DataType dataTypeFromSqlType(int typeCode, String typeName, int width) { switch (typeCode) { case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: return DataType.INTEGER; case Types.BIGINT: return DataType.BIG_INTEGER; case Types.FLOAT: case Types.REAL: case Types.DOUBLE: case Types.NUMERIC: case Types.DECIMAL: return DataType.DECIMAL; case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: case Types.LONGNVARCHAR: case Types.NVARCHAR: return DataType.STRING; case Types.BOOLEAN: case Types.BIT: return DataType.BOOLEAN; case Types.DATE: return DataType.DATE; case Types.BLOB: case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: return DataType.BLOB; case Types.NCLOB: case Types.CLOB: return DataType.CLOB; default: throw new UnexpectedDataTypeException("Unsupported data type [" + typeName + "] (type " + typeCode + " width " + width + ")"); } }
Example 3
Source File: SybasePlatform.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ protected void setStatementParameterValue(PreparedStatement statement, int sqlIndex, int typeCode, Object value) throws SQLException { if ((typeCode == Types.BLOB) || (typeCode == Types.LONGVARBINARY)) { // jConnect doesn't like the BLOB type, but works without problems with LONGVARBINARY // even when using the Blob class if (value instanceof byte[]) { byte[] data = (byte[])value; statement.setBinaryStream(sqlIndex, new ByteArrayInputStream(data), data.length); } else { // Sybase doesn't like the BLOB type, but works without problems with LONGVARBINARY // even when using the Blob class super.setStatementParameterValue(statement, sqlIndex, Types.LONGVARBINARY, value); } } else if (typeCode == Types.CLOB) { // Same for CLOB and LONGVARCHAR super.setStatementParameterValue(statement, sqlIndex, Types.LONGVARCHAR, value); } else { super.setStatementParameterValue(statement, sqlIndex, typeCode, value); } }
Example 4
Source File: GenericSQLGenerator.java From ontopia with Apache License 2.0 | 5 votes |
protected void referenceSQLPrimitive(SQLPrimitive primitive, StringBuilder sql, BuildInfo info) { switch (primitive.getSQLType()) { case Types.VARCHAR: case Types.LONGVARCHAR: case Types.CLOB: sql.append('\''); escapeString(primitive.getValue().toString(), sql); sql.append('\''); return; default: sql.append(primitive.getValue()); //! Object value = primitive.getValue(); //! return (value == null) ? null : value.toString(); } }
Example 5
Source File: TypeDescriptorImpl.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Read this object from a stream of stored objects. * * @param in read this. * * @exception IOException thrown on error * @exception ClassNotFoundException thrown on error */ public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException { typeId = (BaseTypeIdImpl) in.readObject(); precision = in.readInt(); //Scale does not apply to character data types. Starting 10.3 release, //the scale field in TypeDescriptor in SYSCOLUMNS will be used to save //the collation type of the character data types. Because of this, in //this method, we check if we are dealing with character types. If yes, //then read the on-disk scale field of TypeDescriptor into collation //type. In other words, the on-disk scale field has 2 different //meanings depending on what kind of data type we are dealing with. //For character data types, it really represents the collation type of //the character data type. For all the other data types, it represents //the scale of that data type. switch (typeId.getJDBCTypeId()) { case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: case Types.CLOB: scale = 0; collationType = in.readInt(); break; default: scale = in.readInt(); collationType = 0; break; } isNullable = in.readBoolean(); maximumWidth = in.readInt(); }
Example 6
Source File: Cursor.java From vertx-sql-client with Apache License 2.0 | 5 votes |
public final int getInt(int column) throws SQLException { switch (jdbcTypes_[column - 1]) { case Types.BOOLEAN: return CrossConverters.getIntFromBoolean(get_BOOLEAN(column)); case Types.SMALLINT: return (int) get_SMALLINT(column); case Types.INTEGER: return get_INTEGER(column); case Types.BIGINT: return CrossConverters.getIntFromLong(get_BIGINT(column)); case Types.REAL: return CrossConverters.getIntFromFloat(get_FLOAT(column)); case Types.DOUBLE: return CrossConverters.getIntFromDouble(get_DOUBLE(column)); case Types.DECIMAL: // For performance we don't materialize the BigDecimal, but convert directly from decimal bytes to a long. return CrossConverters.getIntFromLong( getLongFromDECIMAL(column, "int")); case Types.CHAR: return CrossConverters.getIntFromString(get_CHAR(column)); case Types.VARCHAR: case Types.LONGVARCHAR: return CrossConverters.getIntFromString(get_VARCHAR(column)); default: throw coercionError( "int", column ); } }
Example 7
Source File: JdbcBroker.java From geoportal-server-harvester with Apache License 2.0 | 4 votes |
private List<AttributeInjector> createAttributeInjectors(final String columnName, final int columnType) { List<AttributeInjector> attributeInjectors = new ArrayList<>(); switch (columnType) { case Types.VARCHAR: case Types.CHAR: case Types.LONGVARCHAR: case Types.LONGNVARCHAR: case Types.NVARCHAR: case Types.NCHAR: case Types.SQLXML: createAttributeNames("src_%s_txt", norm(columnName)).forEach( name -> attributeInjectors.add((a,x,r)->{ if (!name.endsWith("_xml")) { a.put(name, readValue(r, columnName, String.class)); } else { x.xml = readValue(r, columnName, String.class); } })); break; case Types.DOUBLE: createAttributeNames("src_%s_d", norm(columnName)).forEach( name -> attributeInjectors.add((a,x,r)->a.put(name, readValue(r, columnName, Double.class)))); break; case Types.FLOAT: createAttributeNames("src_%s_f", norm(columnName)).forEach( name -> attributeInjectors.add((a,x,r)->a.put(name, readValue(r, columnName, Float.class)))); break; case Types.INTEGER: createAttributeNames("src_%s_i", norm(columnName)).forEach( name -> attributeInjectors.add((a,x,r)->a.put(name, readValue(r, columnName, Integer.class)))); break; case Types.SMALLINT: case Types.TINYINT: createAttributeNames("src_%s_i", norm(columnName)).forEach( name -> attributeInjectors.add((a,x,r)->a.put(name, readValue(r, columnName, Short.class)))); break; case Types.BIGINT: case Types.DECIMAL: case Types.NUMERIC: createAttributeNames("src_%s_d", norm(columnName)).forEach( name -> attributeInjectors.add((a,x,r)->a.put(name, readValue(r, columnName, BigDecimal.class)))); break; case Types.BOOLEAN: createAttributeNames("src_%s_b", norm(columnName)).forEach( name -> attributeInjectors.add((a,x,r)->a.put(name, readValue(r, columnName, Boolean.class)))); break; case Types.DATE: createAttributeNames("src_%s_dt", norm(columnName)).forEach( name -> attributeInjectors.add((a,x,r)->a.put(name, formatIsoDate(r.getDate(columnName))))); break; case Types.TIME: createAttributeNames("src_%s_dt", norm(columnName)).forEach( name -> attributeInjectors.add((a,x,r)->a.put(name, formatIsoDate(r.getTime(columnName))))); break; case Types.TIMESTAMP: createAttributeNames("src_%s_dt", norm(columnName)).forEach( name -> attributeInjectors.add((a,x,r)->a.put(name, formatIsoDate(r.getTimestamp(columnName))))); break; case Types.CLOB: createAttributeNames("src_%s_txt", norm(columnName)).forEach( name -> attributeInjectors.add((a,x,r)->{ if (!name.endsWith("_xml")) { a.put(name, formatClob(r.getClob(columnName))); } else { x.xml = formatClob(r.getClob(columnName)); } })); break; case Types.BLOB: case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: if (columnMappings.containsKey(norm(columnName)) && columnMappings.get(norm(columnName)).endsWith("_txt")) { createAttributeNames("src_%s_txt", norm(columnName)).forEach( name -> attributeInjectors.add((a,x,r)->a.put(name, formatBlob(r.getBlob(columnName))))); } break; } return attributeInjectors; }
Example 8
Source File: SQLiteCursor.java From android-chromium with BSD 2-Clause "Simplified" License | 4 votes |
@Override public void fillWindow(int position, CursorWindow window) { if (position < 0 || position > getCount()) { return; } window.acquireReference(); try { int oldpos = mPos; mPos = position - 1; window.clear(); window.setStartPosition(position); int columnNum = getColumnCount(); window.setNumColumns(columnNum); while (moveToNext() && window.allocRow()) { for (int i = 0; i < columnNum; i++) { boolean hasRoom = true; switch (getColumnType(i)) { case Types.DOUBLE: hasRoom = fillRow(window, Double.valueOf(getDouble(i)), mPos, i); break; case Types.NUMERIC: hasRoom = fillRow(window, Long.valueOf(getLong(i)), mPos, i); break; case Types.BLOB: hasRoom = fillRow(window, getBlob(i), mPos, i); break; case Types.LONGVARCHAR: hasRoom = fillRow(window, getString(i), mPos, i); break; case Types.NULL: hasRoom = fillRow(window, null, mPos, i); break; } if (!hasRoom) { break; } } } mPos = oldpos; } catch (IllegalStateException e) { // simply ignore it } finally { window.releaseReference(); } }
Example 9
Source File: QueryTreeNode.java From spliceengine with GNU Affero General Public License v3.0 | 4 votes |
public int getConstantNodeType(DataTypeDescriptor type) throws StandardException { int constantNodeType; switch(type.getTypeId().getJDBCTypeId()){ case Types.VARCHAR: constantNodeType=C_NodeTypes.VARCHAR_CONSTANT_NODE; break; case Types.CHAR: constantNodeType=C_NodeTypes.CHAR_CONSTANT_NODE; break; case Types.TINYINT: constantNodeType=C_NodeTypes.TINYINT_CONSTANT_NODE; break; case Types.SMALLINT: constantNodeType=C_NodeTypes.SMALLINT_CONSTANT_NODE; break; case Types.INTEGER: constantNodeType=C_NodeTypes.INT_CONSTANT_NODE; break; case Types.BIGINT: constantNodeType=C_NodeTypes.LONGINT_CONSTANT_NODE; break; case Types.REAL: constantNodeType=C_NodeTypes.FLOAT_CONSTANT_NODE; break; case Types.DOUBLE: constantNodeType=C_NodeTypes.DOUBLE_CONSTANT_NODE; break; case Types.NUMERIC: case Types.DECIMAL: constantNodeType=C_NodeTypes.DECIMAL_CONSTANT_NODE; break; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: constantNodeType=C_NodeTypes.USERTYPE_CONSTANT_NODE; break; case Types.BINARY: constantNodeType=C_NodeTypes.BIT_CONSTANT_NODE; break; case Types.VARBINARY: constantNodeType=C_NodeTypes.VARBIT_CONSTANT_NODE; break; case Types.LONGVARCHAR: constantNodeType=C_NodeTypes.LONGVARCHAR_CONSTANT_NODE; break; case Types.CLOB: constantNodeType=C_NodeTypes.CLOB_CONSTANT_NODE; break; case Types.LONGVARBINARY: constantNodeType=C_NodeTypes.LONGVARBIT_CONSTANT_NODE; break; case Types.BLOB: constantNodeType=C_NodeTypes.BLOB_CONSTANT_NODE; break; case JDBC40Translation.SQLXML: constantNodeType=C_NodeTypes.XML_CONSTANT_NODE; break; case Types.BOOLEAN: constantNodeType=C_NodeTypes.BOOLEAN_CONSTANT_NODE; break; case Types.ARRAY: constantNodeType=C_NodeTypes.ARRAY_CONSTANT_NODE; break; default: if(type.getTypeId().userType()){ constantNodeType=C_NodeTypes.USERTYPE_CONSTANT_NODE; }else{ throw StandardException.newException(SQLState.LANG_NONULL_DATATYPE, type.getTypeId().getSQLTypeName()); } } return constantNodeType; }
Example 10
Source File: RawStoreResultSet.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public Reader getCharacterStream(int columnIndex) throws SQLException { if (columnIndex > 0 && columnIndex <= this.numColumns) { final TableMetaData metadata = getMetaData(); final int colType = metadata.getColumnType(columnIndex); switch (colType) { case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: case Types.CLOB: // Embedded and JCC extension break; // JDBC says to support these, we match JCC by returning the raw bytes. case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: case Types.BLOB: final InputStream is = getBinaryStream(columnIndex); if (is != null) { try { return new InputStreamReader(is, "UTF-16BE"); } catch (UnsupportedEncodingException uee) { throw TransactionResourceImpl.wrapInSQLException(uee); } } else { return null; } default: throw dataConversionException( metadata.getColumnTypeName(columnIndex), "Reader", columnIndex); } try { final String str; this.wasNull = false; if (this.currentRowBytes != null) { if (this.changedColumns == null) { str = this.formatter.getAsString(columnIndex, this.currentRowBytes, this); } else { str = this.formatter.getAsString( this.changedColumns[columnIndex - 1], this.currentRowBytes, this); } } else { if (this.changedColumns == null) { str = this.formatter.getAsString(columnIndex, this.currentRowByteArrays, this); } else { str = this.formatter.getAsString( this.changedColumns[columnIndex - 1], this.currentRowByteArrays, this); } } if (str != null) { return new StringReader(str); } else { return null; } } catch (StandardException se) { throw Util.generateCsSQLException(se); } } else { throw invalidColumnException(columnIndex); } }
Example 11
Source File: IntrospectedColumn.java From mybatis-generator-core-fix with Apache License 2.0 | 4 votes |
public boolean isJdbcCharacterColumn() { return jdbcType == Types.CHAR || jdbcType == Types.CLOB || jdbcType == Types.LONGVARCHAR || jdbcType == Types.VARCHAR || jdbcType == Types.LONGNVARCHAR || jdbcType == Types.NCHAR || jdbcType == Types.NCLOB || jdbcType == Types.NVARCHAR; }
Example 12
Source File: TypeId.java From sql-parser with Eclipse Public License 1.0 | 4 votes |
/** * Get a TypeId of the given JDBC type. This factory method is * intended to be used for built-in types. For user-defined types, * we will need a factory method that takes a Java type name. * * @param JDBCTypeId The JDBC Id of the type, as listed in * java.sql.Types * * @return The appropriate TypeId, or null if there is no such * TypeId. */ public static TypeId getBuiltInTypeId(int JDBCTypeId) { switch (JDBCTypeId) { case Types.TINYINT: return TINYINT_ID; case Types.SMALLINT: return SMALLINT_ID; case Types.INTEGER: return INTEGER_ID; case Types.BIGINT: return BIGINT_ID; case Types.FLOAT: case Types.REAL: return REAL_ID; case Types.DOUBLE: return DOUBLE_ID; case Types.DECIMAL: return DECIMAL_ID; case Types.NUMERIC: return NUMERIC_ID; case Types.CHAR: return CHAR_ID; case Types.VARCHAR: return VARCHAR_ID; case Types.DATE: return DATE_ID; case Types.TIME: return TIME_ID; case Types.TIMESTAMP: return TIMESTAMP_ID; case Types.BIT: case Types.BOOLEAN: return BOOLEAN_ID; case Types.BINARY: return BIT_ID; case Types.VARBINARY: return VARBIT_ID; case Types.LONGVARBINARY: return LONGVARBIT_ID; case Types.LONGVARCHAR: return LONGVARCHAR_ID; case Types.BLOB: return BLOB_ID; case Types.CLOB: return CLOB_ID; case Types.SQLXML: // 2009 return XML_ID; default: return null; } }
Example 13
Source File: SimpleStringOperatorNode.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * Bind this operator * * @param fromList The query's FROM list * @param subqueryList The subquery list being built as we find SubqueryNodes * @param aggregateVector The aggregate vector being built as we find AggregateNodes * * @return The new top of the expression tree. * * @exception StandardException Thrown on error */ public ValueNode bindExpression( FromList fromList, SubqueryList subqueryList, Vector aggregateVector) throws StandardException { TypeId operandType; bindOperand(fromList, subqueryList, aggregateVector); /* ** Check the type of the operand - this function is allowed only on ** string value (char and bit) types. */ operandType = operand.getTypeId(); switch (operandType.getJDBCTypeId()) { case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: case Types.CLOB: break; case Types.JAVA_OBJECT: case Types.OTHER: { throw StandardException.newException(SQLState.LANG_UNARY_FUNCTION_BAD_TYPE, methodName, operandType.getSQLTypeName()); } default: DataTypeDescriptor dtd = DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, true, operand.getTypeCompiler(). getCastToCharWidth( operand.getTypeServices())); operand = (ValueNode) getNodeFactory().getNode( C_NodeTypes.CAST_NODE, operand, dtd, getContextManager()); // DERBY-2910 - Match current schema collation for implicit cast as we do for // explicit casts per SQL Spec 6.12 (10) operand.setCollationUsingCompilationSchema(); ((CastNode) operand).bindCastNodeOnly(); operandType = operand.getTypeId(); } /* ** The result type of upper()/lower() is the type of the operand. */ setType(new DataTypeDescriptor(operandType, operand.getTypeServices().isNullable(), operand.getTypeCompiler(). getCastToCharWidth(operand.getTypeServices()) ) ); //Result of upper()/lower() will have the same collation as the //argument to upper()/lower(). setCollationInfo(operand.getTypeServices()); return this; }
Example 14
Source File: SingleTableSplitUtil.java From DataLink with Apache License 2.0 | 4 votes |
private static boolean isStringType(int type) { return type == Types.CHAR || type == Types.NCHAR || type == Types.VARCHAR || type == Types.LONGVARCHAR || type == Types.NVARCHAR; }
Example 15
Source File: DB2LengthOperatorNode.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
private int getConstantLength( ) throws StandardException { DataTypeDescriptor typeDescriptor = operand.getTypeServices(); switch( typeDescriptor.getJDBCTypeId()) { case Types.BIGINT: return 8; case Types.BOOLEAN: case Types.BIT: return 1; case Types.BINARY: case Types.CHAR: return typeDescriptor.getMaximumWidth(); case Types.DATE: return 4; case Types.DECIMAL: case Types.NUMERIC: return typeDescriptor.getPrecision()/2 + 1; case Types.DOUBLE: return 8; case Types.FLOAT: case Types.REAL: case Types.INTEGER: return 4; case Types.SMALLINT: return 2; case Types.TIME: return 3; case Types.TIMESTAMP: return 10; case Types.TINYINT: return 1; case Types.LONGVARCHAR: case Types.VARCHAR: case Types.LONGVARBINARY: case Types.VARBINARY: case Types.BLOB: return getConstantNodeLength(); default: return -1; } }
Example 16
Source File: Cursor.java From vertx-sql-client with Apache License 2.0 | 4 votes |
public final Object getObject(int column) { if (isNull(column)) return null; switch (jdbcTypes_[column - 1]) { case Types.BOOLEAN: return get_BOOLEAN(column); case Types.SMALLINT: // See Table 4 in JDBC 1 spec (pg. 932 in jdbc book) // @AGG since this is not JDBC, just return as a short //return Integer.valueOf(get_SMALLINT(column)); return get_SMALLINT(column); case Types.INTEGER: return get_INTEGER(column); case Types.BIGINT: return get_BIGINT(column); case Types.REAL: return get_FLOAT(column); case Types.DOUBLE: return get_DOUBLE(column); case Types.DECIMAL: return get_DECIMAL(column); case Types.DATE: return get_DATE(column); case Types.TIME: return get_TIME(column); case Types.TIMESTAMP: return get_TIMESTAMP(column); case Types.CHAR: return get_CHAR(column); case Types.VARCHAR: case Types.LONGVARCHAR: return get_VARCHAR(column); case ClientTypes.BINARY: return get_CHAR_FOR_BIT_DATA(column); case Types.VARBINARY: case Types.LONGVARBINARY: return get_VARCHAR_FOR_BIT_DATA(column); case Types.JAVA_OBJECT: return get_UDT( column ); case Types.ROWID: return get_ROWID(column); // case Types.BLOB: // return getBlobColumn_(column, agent_, true); // case Types.CLOB: // return getClobColumn_(column, agent_, true); default: throw coercionError("Object type: ", column ); } }
Example 17
Source File: ResultColumnList.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * Generate an RCL to match the contents of a ResultSetMetaData. * This is useful when dealing with VTIs. * * @param rsmd The ResultSetMetaData. * @param tableName The TableName for the BCNs. * @param javaClassName The name of the VTI * * @exception StandardException Thrown on error */ public void createListFromResultSetMetaData(ResultSetMetaData rsmd, TableName tableName, String javaClassName) throws StandardException { try { // JDBC columns #s are 1-based // Check to make sure # of columns >= 1 int numColumns = rsmd.getColumnCount(); if (numColumns <= 0) { throw StandardException.newException(SQLState.LANG_INVALID_V_T_I_COLUMN_COUNT, javaClassName, String.valueOf(numColumns)); } for (int index = 1; index <= numColumns; index++) { boolean nullableResult = (rsmd.isNullable(index) != ResultSetMetaData.columnNoNulls); TypeId cti; int jdbcColumnType = rsmd.getColumnType(index); switch (jdbcColumnType) { case Types.JAVA_OBJECT: case Types.OTHER: { cti = TypeId.getUserDefinedTypeId(rsmd.getColumnTypeName(index), false); break; } default: { cti = TypeId.getBuiltInTypeId(jdbcColumnType); break; } } // Handle the case where a VTI returns a bad column type if (cti == null) { throw StandardException.newException(SQLState.LANG_BAD_J_D_B_C_TYPE_INFO, Integer.toString(index)); } // Get the maximum byte storage for this column int maxWidth; /* Get maximum byte storage from rsmd for variable * width types, set it to MAXINT for the long types, * otherwise get it from the TypeId */ if (cti.variableLength()) { maxWidth = rsmd.getColumnDisplaySize(index); } else if (jdbcColumnType == Types.LONGVARCHAR || jdbcColumnType == Types.LONGVARBINARY) { maxWidth = Integer.MAX_VALUE; } else { maxWidth = 0; } int precision = cti.isDecimalTypeId() ? rsmd.getPrecision(index) : 0; int scale = cti.isDecimalTypeId() ? rsmd.getScale(index) : 0; DataTypeDescriptor dts = new DataTypeDescriptor(cti, precision, scale, nullableResult, maxWidth); addColumn( tableName, rsmd.getColumnName(index), dts ); } } catch (Throwable t) { if (t instanceof StandardException) { throw (StandardException) t; } else { throw StandardException.unexpectedUserException(t); } } }
Example 18
Source File: RawStoreResultSetWithByteSource.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public Reader getCharacterStream(int columnIndex) throws SQLException { if (columnIndex > 0 && columnIndex <= this.numColumns) { final TableMetaData metadata = getMetaData(); final int colType = metadata.getColumnType(columnIndex); switch (colType) { case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: case Types.CLOB: // Embedded and JCC extension break; // JDBC says to support these, we match JCC by returning the raw bytes. case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: case Types.BLOB: final InputStream is = getBinaryStream(columnIndex); if (is != null) { try { return new InputStreamReader(is, "UTF-16BE"); } catch (UnsupportedEncodingException uee) { throw TransactionResourceImpl.wrapInSQLException(uee); } } else { return null; } default: throw dataConversionException( metadata.getColumnTypeName(columnIndex), "Reader", columnIndex); } try { final String str; this.wasNull = false; if (this.changedColumns == null) { if (this.currentRowByteArrays != null) { str = this.formatter.getAsString(columnIndex, this.currentRowByteArrays, this); } else { str = this.formatter.getAsString(columnIndex, this.currentRowBytes, this); } } else { if (this.currentRowByteArrays != null) { str = this.formatter.getAsString( this.changedColumns[columnIndex - 1], this.currentRowByteArrays, this); } else { str = this.formatter.getAsString( this.changedColumns[columnIndex - 1], this.currentRowBytes, this); } } if (str != null) { return new StringReader(str); } else { return null; } } catch (StandardException se) { throw Util.generateCsSQLException(se); } } else { throw invalidColumnException(columnIndex); } }
Example 19
Source File: PostgreSqlModelReader.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ protected Column readColumn(DatabaseMetaDataWrapper metaData, Map values) throws SQLException { Column column = super.readColumn(metaData, values); if (column.getSize() != null) { if (column.getSizeAsInt() <= 0) { column.setSize(null); // PostgreSQL reports BYTEA and TEXT as BINARY(-1) and VARCHAR(-1) respectively // Since we cannot currently use the Blob/Clob interface with BYTEA, we instead // map them to LONGVARBINARY/LONGVARCHAR if (column.getTypeCode() == Types.BINARY) { column.setTypeCode(Types.LONGVARBINARY); } else if (column.getTypeCode() == Types.VARCHAR) { column.setTypeCode(Types.LONGVARCHAR); } } // fix issue DDLUTILS-165 as postgresql-8.2-504-jdbc3.jar seems to return Integer.MAX_VALUE // on columns defined as TEXT. else if (column.getSizeAsInt() == Integer.MAX_VALUE) { column.setSize(null); if (column.getTypeCode() == Types.VARCHAR) { column.setTypeCode(Types.LONGVARCHAR); } else if (column.getTypeCode() == Types.BINARY) { column.setTypeCode(Types.LONGVARBINARY); } } } String defaultValue = column.getDefaultValue(); if ((defaultValue != null) && (defaultValue.length() > 0)) { // If the default value looks like "nextval('ROUNDTRIP_VALUE_seq'::text)" // then it is an auto-increment column if (defaultValue.startsWith("nextval(")) { column.setAutoIncrement(true); defaultValue = null; } else { // PostgreSQL returns default values in the forms "-9000000000000000000::bigint" or // "'some value'::character varying" or "'2000-01-01'::date" switch (column.getTypeCode()) { case Types.INTEGER: case Types.BIGINT: case Types.DECIMAL: case Types.NUMERIC: defaultValue = extractUndelimitedDefaultValue(defaultValue); break; case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: case Types.DATE: case Types.TIME: case Types.TIMESTAMP: defaultValue = extractDelimitedDefaultValue(defaultValue); break; } if (TypeMap.isTextType(column.getTypeCode())) { // We assume escaping via double quote (see also the backslash_quote setting: // http://www.postgresql.org/docs/7.4/interactive/runtime-config.html#RUNTIME-CONFIG-COMPATIBLE) defaultValue = unescape(defaultValue, "'", "''"); } } column.setDefaultValue(defaultValue); } return column; }
Example 20
Source File: TableMetaParser.java From tddl with Apache License 2.0 | 4 votes |
public static String jdbcTypeToDataTypeString(int jdbcType) { String type = null; switch (jdbcType) { case Types.BIGINT: // 考虑unsigned type = "BIGINTEGER"; break; case Types.NUMERIC: case Types.DECIMAL: type = "BIGDECIMAL"; break; case Types.INTEGER: // 考虑unsigned type = "LONG"; break; case Types.TINYINT: case Types.SMALLINT: // 考虑unsigned type = "INT"; break; case Types.DATE: type = "DATE"; break; case Types.TIMESTAMP: type = "TIMESTAMP"; break; case Types.TIME: type = "TIME"; break; case Types.FLOAT: type = "FLOAT"; break; case Types.REAL: case Types.DOUBLE: type = "DOUBLE"; break; case Types.CHAR: case Types.VARCHAR: case Types.NCHAR: case Types.NVARCHAR: case Types.LONGNVARCHAR: case Types.LONGVARCHAR: case Types.CLOB: type = "STRING"; break; case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: type = "BYTES"; break; case Types.BLOB: type = "BLOB"; break; case Types.BIT: type = "BIT"; break; default: throw new IllegalArgumentException("不支持的类型:" + jdbcType); } return type; }