Java Code Examples for java.sql.ResultSetMetaData#columnNoNulls()

The following examples show how to use java.sql.ResultSetMetaData#columnNoNulls() . 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: PostgresJavaRoutineJsonOutputter.java    From sql-layer with GNU Affero General Public License v3.0 6 votes vote down vote up
protected DataTypeDescriptor resultColumnSQLType(ResultSetMetaData metaData, int i)
        throws SQLException {
    TypeId typeId = TypeId.getBuiltInTypeId(metaData.getColumnType(i));
    if (typeId == null) {
        try {
            typeId = TypeId.getUserDefinedTypeId(metaData.getColumnTypeName(i),
                                                 false);
        }
        catch (StandardException ex) {
            throw new SQLParserInternalException(ex);
        }
    }
    if (typeId.isDecimalTypeId()) {
        return new DataTypeDescriptor(typeId,
                                      metaData.getPrecision(i),
                                      metaData.getScale(i),
                                      metaData.isNullable(i) != ResultSetMetaData.columnNoNulls,
                                      metaData.getColumnDisplaySize(i));
        }
    else {
        return new DataTypeDescriptor(typeId,
                                      metaData.isNullable(i) != ResultSetMetaData.columnNoNulls,
                                      metaData.getColumnDisplaySize(i));
    }
}
 
Example 2
Source File: RowSetMetaDataTests.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name = "validSetNullableValues")
private Object[][] validSetNullableValues() {
    return new Object[][]{
        {ResultSetMetaData.columnNoNulls},
        {ResultSetMetaData.columnNullable},
        {ResultSetMetaData.columnNullableUnknown}
    };
}
 
Example 3
Source File: RowSetMetaDataTests.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name = "validSetNullableValues")
private Object[][] validSetNullableValues() {
    return new Object[][]{
        {ResultSetMetaData.columnNoNulls},
        {ResultSetMetaData.columnNullable},
        {ResultSetMetaData.columnNullableUnknown}
    };
}
 
Example 4
Source File: RowSetMetaDataTests.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name = "validSetNullableValues")
private Object[][] validSetNullableValues() {
    return new Object[][]{
        {ResultSetMetaData.columnNoNulls},
        {ResultSetMetaData.columnNullable},
        {ResultSetMetaData.columnNullableUnknown}
    };
}
 
Example 5
Source File: RowSetMetaDataTests.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name = "validSetNullableValues")
private Object[][] validSetNullableValues() {
    return new Object[][]{
        {ResultSetMetaData.columnNoNulls},
        {ResultSetMetaData.columnNullable},
        {ResultSetMetaData.columnNullableUnknown}
    };
}
 
Example 6
Source File: WiscMetaData.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public int isNullable(int column) throws SQLException {
	if (column < 1 || column > 16) {
		throw new SQLException(
				"isNullable: column number " + column + " out of range.");
	}

	return ResultSetMetaData.columnNoNulls;
}
 
Example 7
Source File: RowSetMetaDataTests.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name = "validSetNullableValues")
private Object[][] validSetNullableValues() {
    return new Object[][]{
        {ResultSetMetaData.columnNoNulls},
        {ResultSetMetaData.columnNullable},
        {ResultSetMetaData.columnNullableUnknown}
    };
}
 
Example 8
Source File: TdsCore.java    From jTDS with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Process TDS 5 Sybase 12+ Dynamic results parameter descriptor.
 * <p>When returning output parameters this token will be followed
 * by a TDS5_PARAMS_TOKEN with the actual data.
 * @throws IOException
 * @throws ProtocolException
 */
private void tds5ParamFmt2Token() throws IOException, ProtocolException {
    in.readInt(); // Packet length
    int paramCnt = in.readShort();
    ColInfo[] params = new ColInfo[paramCnt];
    for (int i = 0; i < paramCnt; i++) {
        //
        // Get the parameter details using the
        // ColInfo class as the server format is the same.
        //
        ColInfo col = new ColInfo();
        int colNameLen = in.read();
        col.realName = in.readNonUnicodeString(colNameLen);
        int column_flags = in.readInt();   /*  Flags */
        col.isCaseSensitive = false;
        col.nullable    = ((column_flags & 0x20) != 0)?
                                    ResultSetMetaData.columnNullable:
                                    ResultSetMetaData.columnNoNulls;
        col.isWriteable = (column_flags & 0x10) != 0;
        col.isIdentity  = (column_flags & 0x40) != 0;
        col.isKey       = (column_flags & 0x02) != 0;
        col.isHidden    = (column_flags & 0x01) != 0;

        col.userType    = in.readInt();
        TdsData.readType(in, col);
        // Skip locale information
        in.skip(1);
        params[i] = col;
    }
    currentToken.dynamParamInfo = params;
    currentToken.dynamParamData = new Object[paramCnt];
}
 
Example 9
Source File: Inspector.java    From GeoTriples with Apache License 2.0 5 votes vote down vote up
public List<ColumnDef> describeSelectStatement(String sqlQuery) {
	List<ColumnDef> result = new ArrayList<ColumnDef>();
	try {
		PreparedStatement stmt = connection.prepareStatement(sqlQuery);
		try {
			ResultSetMetaData meta = stmt.getMetaData();
			for (int i = 1; i <= meta.getColumnCount(); i++) {
				String name = meta.getColumnLabel(i);
				int type = meta.getColumnType(i);
				String typeName = meta.getColumnTypeName(i);
				int size = meta.getPrecision(i);
				DataType dataType = vendor.getDataType(type, typeName, size);
				if (dataType == null) {
					log.warn("Unknown datatype '" + 
							(size == 0 ? typeName : (typeName + "(" + size + ")")) + 
							"' (" + type + ")");
				}
				boolean isNullable = meta.isNullable(i) != ResultSetMetaData.columnNoNulls;
				result.add(new ColumnDef(
						Identifier.createDelimited(name), dataType, isNullable));
			}
			return result;
		} finally {
			stmt.close();
		}
	} catch (SQLException ex) {
		throw new D2RQException(ex, D2RQException.D2RQ_SQLEXCEPTION);
	}
}
 
Example 10
Source File: CloudSpannerResultSetMetaDataTest.java    From spanner-jdbc with MIT License 4 votes vote down vote up
private Builder withNotNull() {
  this.nulls = ResultSetMetaData.columnNoNulls;
  return this;
}
 
Example 11
Source File: ClickHouseResultSetMetaData.java    From ClickHouse-Native-JDBC with Apache License 2.0 4 votes vote down vote up
@Override
public int isNullable(int index) throws SQLException {
    return (header.getByPosition(index - 1).type() instanceof DataTypeNullable) ?
        ResultSetMetaData.columnNullable : ResultSetMetaData.columnNoNulls;
}
 
Example 12
Source File: TdsCore.java    From jTDS with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Process TDS 5 Dynamic results parameter descriptors.
 * <p>
 * With Sybase 12+ this has been superseded by the TDS5_PARAMFMT2_TOKEN
 * except when used to return extended error information.
 *
 * @throws IOException
 * @throws ProtocolException
 */
private void tds5ParamFmtToken() throws IOException, ProtocolException {
    in.readShort(); // Packet length
    int paramCnt = in.readShort();
    ColInfo[] params = new ColInfo[paramCnt];
    for (int i = 0; i < paramCnt; i++) {
        //
        // Get the parameter details using the
        // ColInfo class as the server format is the same.
        //
        ColInfo col = new ColInfo();
        int colNameLen = in.read();
        col.realName = in.readNonUnicodeString(colNameLen);
        int column_flags = in.read();   /*  Flags */
        col.isCaseSensitive = false;
        col.nullable    = ((column_flags & 0x20) != 0)?
                                    ResultSetMetaData.columnNullable:
                                    ResultSetMetaData.columnNoNulls;
        col.isWriteable = (column_flags & 0x10) != 0;
        col.isIdentity  = (column_flags & 0x40) != 0;
        col.isKey       = (column_flags & 0x02) != 0;
        col.isHidden    = (column_flags & 0x01) != 0;

        col.userType    = in.readInt();
        if ((byte)in.peek() == TDS_DONE_TOKEN) {
            // Sybase 11.92 bug data type missing!
            currentToken.dynamParamInfo = null;
            currentToken.dynamParamData = null;
            // error trapped in sybasePrepare();
            messages.addDiagnostic(9999, 0, 16,
                                    "Prepare failed", "", "", 0);

            return; // Give up
        }
        TdsData.readType(in, col);
        // Skip locale information
        in.skip(1);
        params[i] = col;
    }
    currentToken.dynamParamInfo = params;
    currentToken.dynamParamData = new Object[paramCnt];
}
 
Example 13
Source File: DremioColumnMetaDataList.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
public void updateColumnMetaData(String catalogName, String schemaName,
                                 String tableName, BatchSchema schema,
                                 List<Class<?>> getObjectClasses ) {
  final List<ColumnMetaData> newColumns =
      new ArrayList<>(schema.getFieldCount());
  for (int colOffset = 0; colOffset < schema.getFieldCount(); colOffset++) {
    final Field field = schema.getColumn(colOffset);
    Class<?> objectClass = getObjectClasses.get( colOffset );

    final String columnName = field.getName();

    final MajorType rpcDataType = getMajorTypeForField(field);
    final AvaticaType bundledSqlDataType = getAvaticaType(rpcDataType);
    final String columnClassName = objectClass.getName();

    final int nullability;
    switch ( rpcDataType.getMode() ) {
      case OPTIONAL: nullability = ResultSetMetaData.columnNullable; break;
      case REQUIRED: nullability = ResultSetMetaData.columnNoNulls;  break;
      // Should REPEATED still map to columnNoNulls? or to columnNullable?
      case REPEATED: nullability = ResultSetMetaData.columnNoNulls;  break;
      default:
        throw new AssertionError( "Unexpected new DataMode value '"
                                  + rpcDataType.getMode() + "'" );
    }
    final boolean isSigned = Types.isJdbcSignedType( rpcDataType );

    // TODO(DRILL-3355):  TODO(DRILL-3356):  When string lengths, precisions,
    // interval kinds, etc., are available from RPC-level data, implement:
    // - precision for ResultSetMetadata.getPrecision(...) (like
    //   getColumns()'s COLUMN_SIZE)
    // - scale for getScale(...), and
    // - and displaySize for getColumnDisplaySize(...).
    final int precision = Types.getPrecision(rpcDataType);
    final int scale = Types.getScale(rpcDataType);
    final int displaySize = Types.getJdbcDisplaySize(rpcDataType);

    ColumnMetaData col = new ColumnMetaData(
        colOffset,    // (zero-based ordinal (for Java arrays/lists).)
        false,        /* autoIncrement */
        false,        /* caseSensitive */
        true,         /* searchable */
        false,        /* currency */
        nullability,
        isSigned,
        displaySize,
        columnName,   /* label */
        columnName,   /* columnName */
        schemaName,
        precision,
        scale,
        tableName,
        catalogName,
        bundledSqlDataType,
        true,         /* readOnly */
        false,        /* writable */
        false,        /* definitelyWritable */
        columnClassName
       );
    newColumns.add(col);
  }
  columns = newColumns;
}
 
Example 14
Source File: PhoenixResultSetMetaData.java    From phoenix with Apache License 2.0 4 votes vote down vote up
@Override
public int isNullable(int column) throws SQLException {
    return rowProjector.getColumnProjector(column-1).getExpression().isNullable() ? ResultSetMetaData.columnNullable : ResultSetMetaData.columnNoNulls;
}
 
Example 15
Source File: FBResultSetMetaData.java    From jaybird with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public int isNullable(int column) throws SQLException {
    return (getFieldDescriptor(column).getType() & 1) == 1
            ? ResultSetMetaData.columnNullable
            : ResultSetMetaData.columnNoNulls;
}
 
Example 16
Source File: MockResultSetMetaData.java    From tddl with Apache License 2.0 4 votes vote down vote up
public int isNullable(int column) throws SQLException {
    return ResultSetMetaData.columnNoNulls;
}
 
Example 17
Source File: PhoenixParameterMetaData.java    From phoenix with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public int isNullable(int index) throws SQLException {
    return getParam(index).isNullable() ? ResultSetMetaData.columnNullable : ResultSetMetaData.columnNoNulls;
}
 
Example 18
Source File: TdsCore.java    From jTDS with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
* Process Sybase 12+ wide result token which provides enhanced
* column meta data.
*
* @throws IOException
*/
private void tds5WideResultToken()
    throws IOException, ProtocolException
{
    in.readInt(); // Packet length
    int colCnt   = in.readShort();
    columns = new ColInfo[colCnt];
    rowData = new Object[colCnt];
    tables  = null;

    for (int colNum = 0; colNum < colCnt; ++colNum) {
        ColInfo col = new ColInfo();
        //
        // Get the alias name
        //
        int nameLen = in.read();
        col.name  = in.readNonUnicodeString(nameLen);
        //
        // Get the catalog name
        //
        nameLen = in.read();
        col.catalog = in.readNonUnicodeString(nameLen);
        //
        // Get the schema name
        //
        nameLen = in.read();
        col.schema = in.readNonUnicodeString(nameLen);
        //
        // Get the table name
        //
        nameLen = in.read();
        col.tableName = in.readNonUnicodeString(nameLen);
        //
        // Get the column name
        //
        nameLen = in.read();
        col.realName  = in.readNonUnicodeString(nameLen);
        if (col.name == null || col.name.length() == 0) {
            col.name = col.realName;
        }
        int column_flags = in.readInt();   /*  Flags */
        col.isCaseSensitive = false;
        col.nullable    = ((column_flags & 0x20) != 0)?
                               ResultSetMetaData.columnNullable:
                                    ResultSetMetaData.columnNoNulls;
        col.isWriteable = (column_flags & 0x10) != 0;
        col.isIdentity  = (column_flags & 0x40) != 0;
        col.isKey       = (column_flags & 0x02) != 0;
        col.isHidden    = (column_flags & 0x01) != 0;

        col.userType    = in.readInt();
        TdsData.readType(in, col);
        // Skip locale information
        in.skip(1);
        columns[colNum] = col;
    }
    endOfResults = false;
}
 
Example 19
Source File: TdsCore.java    From jTDS with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Process a TDS 4.2 column format token.
 *
 * @throws IOException
 * @throws ProtocolException
 */
private void tds4ColFormatToken()
    throws IOException, ProtocolException {

    final int pktLen = in.readShort();

    int bytesRead = 0;
    int numColumns = 0;
    while (bytesRead < pktLen) {
        if (numColumns > columns.length) {
            throw new ProtocolException("Too many columns in TDS_COL_FMT packet");
        }
        ColInfo col = columns[numColumns];

        if (serverType == Driver.SQLSERVER) {
            col.userType = in.readShort();

            int flags = in.readShort();

            col.nullable = ((flags & 0x01) != 0)?
                                ResultSetMetaData.columnNullable:
                                   ResultSetMetaData.columnNoNulls;
            col.isCaseSensitive = (flags & 0x02) != 0;
            col.isWriteable = (flags & 0x0C) != 0;
            col.isIdentity = (flags & 0x10) != 0;
        } else {
            // Sybase does not send column flags
            col.isCaseSensitive = false;
            col.isWriteable = true;

            if (col.nullable == ResultSetMetaData.columnNoNulls) {
                col.nullable = ResultSetMetaData.columnNullableUnknown;
            }

            col.userType = in.readInt();
        }
        bytesRead += 4;

        bytesRead += TdsData.readType(in, col);

        numColumns++;
    }

    if (numColumns != columns.length) {
        throw new ProtocolException("Too few columns in TDS_COL_FMT packet");
    }

    endOfResults = false;
}
 
Example 20
Source File: DataTypeUtilities.java    From gemfirexd-oss with Apache License 2.0 2 votes vote down vote up
/**
 * Is the data type nullable.
 * 
 * @param dtd
 *          data type descriptor
 */
public static int isNullable(DataTypeDescriptor dtd) {
  return dtd.isNullable() ? ResultSetMetaData.columnNullable
      : ResultSetMetaData.columnNoNulls;
}