@Test public void testGetFieldDefinition() { assertEquals( "FOO TIMESTAMP", nativeMeta.getFieldDefinition( new ValueMetaDate( "FOO" ), "", "", false, true, false ) ); assertEquals( "TIMESTAMP", nativeMeta.getFieldDefinition( new ValueMetaTimestamp( "FOO" ), "", "", false, false, false ) ); String[] typeCk = new String[] { "CHAR(1)", "BOOLEAN", "CHAR(1)" }; int i = ( nativeMeta.supportsBooleanDataType() ? 1 : 0 ); assertEquals( typeCk[i], nativeMeta.getFieldDefinition( new ValueMetaBoolean( "FOO" ), "", "", false, false, false ) ); odbcMeta.setSupportsBooleanDataType( !( odbcMeta.supportsBooleanDataType() ) ); assertEquals( typeCk[ i + 1 ], odbcMeta.getFieldDefinition( new ValueMetaBoolean( "FOO" ), "", "", false, false, false ) ); odbcMeta.setSupportsBooleanDataType( !( odbcMeta.supportsBooleanDataType() ) ); assertEquals( "SERIAL", nativeMeta.getFieldDefinition( new ValueMetaBigNumber( "FOO", 8, 0 ), "", "FOO", true, false, false ) ); assertEquals( "BIGINT", nativeMeta.getFieldDefinition( new ValueMetaNumber( "FOO", 10, 0 ), "FOO", "", false, false, false ) ); assertEquals( "BIGINT", nativeMeta.getFieldDefinition( new ValueMetaInteger( "FOO", 8, 0 ), "", "FOO", false, false, false ) ); assertEquals( "BIGINT", nativeMeta.getFieldDefinition( new ValueMetaInteger( "FOO", 8, 0 ), "", "", false, false, false ) ); assertEquals( "BIGINT", nativeMeta.getFieldDefinition( new ValueMetaNumber( "FOO", 10, 0 ), "", "", false, false, false ) ); assertEquals( "DECIMAL(19)", nativeMeta.getFieldDefinition( new ValueMetaBigNumber( "FOO", 19, 0 ), "", "", false, false, false ) ); assertEquals( "DOUBLE", nativeMeta.getFieldDefinition( new ValueMetaNumber( "FOO", 8, 0 ), "", "", false, false, false ) ); assertEquals( "DECIMAL(19, 5)", nativeMeta.getFieldDefinition( new ValueMetaBigNumber( "FOO", 19, 5 ), "", "", false, false, false ) ); assertEquals( "DECIMAL(19)", nativeMeta.getFieldDefinition( new ValueMetaBigNumber( "FOO", 19, -5 ), "", "", false, false, false ) ); assertEquals( "DOUBLE", nativeMeta.getFieldDefinition( new ValueMetaBigNumber( "FOO", 11, 5 ), "", "", false, false, false ) ); assertEquals( "VARCHAR(10)", nativeMeta.getFieldDefinition( new ValueMetaString( "FOO", 10, 0 ), "", "", false, false, false ) ); assertEquals( "VARCHAR()", nativeMeta.getFieldDefinition( new ValueMetaString( "FOO", nativeMeta.getMaxVARCHARLength() + 1, 0 ), "", "", false, false, false ) ); assertEquals( "VARCHAR()", nativeMeta.getFieldDefinition( new ValueMetaString( "FOO", -2, 0 ), "", "", false, false, false ) ); MonetDBDatabaseMeta.safeModeLocal.set( new Boolean( true ) ); assertEquals( "VARCHAR(100)", nativeMeta.getFieldDefinition( new ValueMetaString( "FOO", -2, 0 ), "", "", false, false, false ) ); assertEquals( " UNKNOWN", nativeMeta.getFieldDefinition( new ValueMetaInternetAddress( "FOO" ), "", "", false, false, false ) ); assertEquals( " UNKNOWN" + System.getProperty( "line.separator" ), nativeMeta.getFieldDefinition( new ValueMetaInternetAddress( "FOO" ), "", "", false, false, true ) ); }
@Override public String getFieldDefinition( ValueMetaInterface v, String tk, String pk, boolean use_autoinc, boolean add_fieldname, boolean add_cr ) { StringBuilder retval = new StringBuilder(); String fieldname = v.getName(); int length = v.getLength(); int precision = v.getPrecision(); Boolean mode = MonetDBDatabaseMeta.safeModeLocal.get(); boolean safeMode = mode != null && mode.booleanValue(); if ( add_fieldname ) { if ( safeMode ) { fieldname = getSafeFieldname( fieldname ); } retval.append( fieldname + " " ); } int type = v.getType(); switch ( type ) { case ValueMetaInterface.TYPE_TIMESTAMP: case ValueMetaInterface.TYPE_DATE: retval.append( "TIMESTAMP" ); break; case ValueMetaInterface.TYPE_BOOLEAN: if ( supportsBooleanDataType() ) { retval.append( "BOOLEAN" ); } else { retval.append( "CHAR(1)" ); } break; case ValueMetaInterface.TYPE_NUMBER: case ValueMetaInterface.TYPE_INTEGER: case ValueMetaInterface.TYPE_BIGNUMBER: if ( fieldname.equalsIgnoreCase( tk ) || fieldname.equalsIgnoreCase( pk ) ) { if ( use_autoinc ) { retval.append( "SERIAL" ); } else { retval.append( "BIGINT" ); } } else { if ( precision == 0 ) { if ( length > 9 ) { if ( length < 19 ) { retval.append( "BIGINT" ); } else { retval.append( "DECIMAL(" ).append( length ).append( ")" ); } } else if ( type == ValueMetaInterface.TYPE_NUMBER ) { retval.append( "DOUBLE" ); } else { retval.append( "BIGINT" ); } } else { if ( length > 15 ) { retval.append( "DECIMAL(" ).append( length ); if ( precision > 0 ) { retval.append( ", " ).append( precision ); } retval.append( ")" ); } else { retval.append( "DOUBLE" ); } } } break; case ValueMetaInterface.TYPE_STRING: if ( length > getMaxVARCHARLength() ) { retval.append( "CLOB" ); } else { retval.append( "VARCHAR(" ); if ( length > 0 ) { retval.append( length ); } else { if ( safeMode ) { retval.append( DEFAULT_VARCHAR_LENGTH ); } } retval.append( ")" ); } break; default: retval.append( " UNKNOWN" ); break; } if ( add_cr ) { retval.append( Const.CR ); } return retval.toString(); }
MonetDBDatabaseMeta extends BaseDatabaseMeta implements DatabaseInterface { @Override public String getFieldDefinition( ValueMetaInterface v, String tk, String pk, boolean use_autoinc, boolean add_fieldname, boolean add_cr ) { StringBuilder retval = new StringBuilder(); String fieldname = v.getName(); int length = v.getLength(); int precision = v.getPrecision(); Boolean mode = MonetDBDatabaseMeta.safeModeLocal.get(); boolean safeMode = mode != null && mode.booleanValue(); if ( add_fieldname ) { if ( safeMode ) { fieldname = getSafeFieldname( fieldname ); } retval.append( fieldname + " " ); } int type = v.getType(); switch ( type ) { case ValueMetaInterface.TYPE_TIMESTAMP: case ValueMetaInterface.TYPE_DATE: retval.append( "TIMESTAMP" ); break; case ValueMetaInterface.TYPE_BOOLEAN: if ( supportsBooleanDataType() ) { retval.append( "BOOLEAN" ); } else { retval.append( "CHAR(1)" ); } break; case ValueMetaInterface.TYPE_NUMBER: case ValueMetaInterface.TYPE_INTEGER: case ValueMetaInterface.TYPE_BIGNUMBER: if ( fieldname.equalsIgnoreCase( tk ) || fieldname.equalsIgnoreCase( pk ) ) { if ( use_autoinc ) { retval.append( "SERIAL" ); } else { retval.append( "BIGINT" ); } } else { if ( precision == 0 ) { if ( length > 9 ) { if ( length < 19 ) { retval.append( "BIGINT" ); } else { retval.append( "DECIMAL(" ).append( length ).append( ")" ); } } else if ( type == ValueMetaInterface.TYPE_NUMBER ) { retval.append( "DOUBLE" ); } else { retval.append( "BIGINT" ); } } else { if ( length > 15 ) { retval.append( "DECIMAL(" ).append( length ); if ( precision > 0 ) { retval.append( ", " ).append( precision ); } retval.append( ")" ); } else { retval.append( "DOUBLE" ); } } } break; case ValueMetaInterface.TYPE_STRING: if ( length > getMaxVARCHARLength() ) { retval.append( "CLOB" ); } else { retval.append( "VARCHAR(" ); if ( length > 0 ) { retval.append( length ); } else { if ( safeMode ) { retval.append( DEFAULT_VARCHAR_LENGTH ); } } retval.append( ")" ); } break; default: retval.append( " UNKNOWN" ); break; } if ( add_cr ) { retval.append( Const.CR ); } return retval.toString(); } }
MonetDBDatabaseMeta extends BaseDatabaseMeta implements DatabaseInterface { @Override public String getFieldDefinition( ValueMetaInterface v, String tk, String pk, boolean use_autoinc, boolean add_fieldname, boolean add_cr ) { StringBuilder retval = new StringBuilder(); String fieldname = v.getName(); int length = v.getLength(); int precision = v.getPrecision(); Boolean mode = MonetDBDatabaseMeta.safeModeLocal.get(); boolean safeMode = mode != null && mode.booleanValue(); if ( add_fieldname ) { if ( safeMode ) { fieldname = getSafeFieldname( fieldname ); } retval.append( fieldname + " " ); } int type = v.getType(); switch ( type ) { case ValueMetaInterface.TYPE_TIMESTAMP: case ValueMetaInterface.TYPE_DATE: retval.append( "TIMESTAMP" ); break; case ValueMetaInterface.TYPE_BOOLEAN: if ( supportsBooleanDataType() ) { retval.append( "BOOLEAN" ); } else { retval.append( "CHAR(1)" ); } break; case ValueMetaInterface.TYPE_NUMBER: case ValueMetaInterface.TYPE_INTEGER: case ValueMetaInterface.TYPE_BIGNUMBER: if ( fieldname.equalsIgnoreCase( tk ) || fieldname.equalsIgnoreCase( pk ) ) { if ( use_autoinc ) { retval.append( "SERIAL" ); } else { retval.append( "BIGINT" ); } } else { if ( precision == 0 ) { if ( length > 9 ) { if ( length < 19 ) { retval.append( "BIGINT" ); } else { retval.append( "DECIMAL(" ).append( length ).append( ")" ); } } else if ( type == ValueMetaInterface.TYPE_NUMBER ) { retval.append( "DOUBLE" ); } else { retval.append( "BIGINT" ); } } else { if ( length > 15 ) { retval.append( "DECIMAL(" ).append( length ); if ( precision > 0 ) { retval.append( ", " ).append( precision ); } retval.append( ")" ); } else { retval.append( "DOUBLE" ); } } } break; case ValueMetaInterface.TYPE_STRING: if ( length > getMaxVARCHARLength() ) { retval.append( "CLOB" ); } else { retval.append( "VARCHAR(" ); if ( length > 0 ) { retval.append( length ); } else { if ( safeMode ) { retval.append( DEFAULT_VARCHAR_LENGTH ); } } retval.append( ")" ); } break; default: retval.append( " UNKNOWN" ); break; } if ( add_cr ) { retval.append( Const.CR ); } return retval.toString(); }  }
MonetDBDatabaseMeta extends BaseDatabaseMeta implements DatabaseInterface { @Override public String getFieldDefinition( ValueMetaInterface v, String tk, String pk, boolean use_autoinc, boolean add_fieldname, boolean add_cr ) { StringBuilder retval = new StringBuilder(); String fieldname = v.getName(); int length = v.getLength(); int precision = v.getPrecision(); Boolean mode = MonetDBDatabaseMeta.safeModeLocal.get(); boolean safeMode = mode != null && mode.booleanValue(); if ( add_fieldname ) { if ( safeMode ) { fieldname = getSafeFieldname( fieldname ); } retval.append( fieldname + " " ); } int type = v.getType(); switch ( type ) { case ValueMetaInterface.TYPE_TIMESTAMP: case ValueMetaInterface.TYPE_DATE: retval.append( "TIMESTAMP" ); break; case ValueMetaInterface.TYPE_BOOLEAN: if ( supportsBooleanDataType() ) { retval.append( "BOOLEAN" ); } else { retval.append( "CHAR(1)" ); } break; case ValueMetaInterface.TYPE_NUMBER: case ValueMetaInterface.TYPE_INTEGER: case ValueMetaInterface.TYPE_BIGNUMBER: if ( fieldname.equalsIgnoreCase( tk ) || fieldname.equalsIgnoreCase( pk ) ) { if ( use_autoinc ) { retval.append( "SERIAL" ); } else { retval.append( "BIGINT" ); } } else { if ( precision == 0 ) { if ( length > 9 ) { if ( length < 19 ) { retval.append( "BIGINT" ); } else { retval.append( "DECIMAL(" ).append( length ).append( ")" ); } } else if ( type == ValueMetaInterface.TYPE_NUMBER ) { retval.append( "DOUBLE" ); } else { retval.append( "BIGINT" ); } } else { if ( length > 15 ) { retval.append( "DECIMAL(" ).append( length ); if ( precision > 0 ) { retval.append( ", " ).append( precision ); } retval.append( ")" ); } else { retval.append( "DOUBLE" ); } } } break; case ValueMetaInterface.TYPE_STRING: if ( length > getMaxVARCHARLength() ) { retval.append( "CLOB" ); } else { retval.append( "VARCHAR(" ); if ( length > 0 ) { retval.append( length ); } else { if ( safeMode ) { retval.append( DEFAULT_VARCHAR_LENGTH ); } } retval.append( ")" ); } break; default: retval.append( " UNKNOWN" ); break; } if ( add_cr ) { retval.append( Const.CR ); } return retval.toString(); }  @Override int[] getAccessTypeList(); @Override int getDefaultDatabasePort(); @Override int getNotFoundTK( boolean use_autoinc ); @Override String getDriverClass(); @Override String getURL( String hostname, String port, String databaseName ); @Override boolean isFetchSizeSupported(); @Override boolean supportsBitmapIndex(); @Override boolean supportsAutoInc(); @Override boolean supportsBatchUpdates(); @Override boolean supportsSetMaxRows(); @Override String getTruncateTableStatement( String tableName ); @Override String getAddColumnStatement( String tablename, ValueMetaInterface v, String tk, boolean use_autoinc,
    String pk, boolean semicolon ); @Override String getModifyColumnStatement( String tablename, ValueMetaInterface v, String tk, boolean use_autoinc,
    String pk, boolean semicolon ); @Override String[] getReservedWords(); @Override String getFieldDefinition( ValueMetaInterface v, String tk, String pk, boolean use_autoinc,
    boolean add_fieldname, boolean add_cr ); @Override String[] getUsedLibraries(); @Override String getSQLQueryFields( String tableName ); @Override boolean supportsResultSetMetadataRetrievalOnly(); @Override int getMaxVARCHARLength(); @Override boolean supportsSequences(); @Override String getSQLListOfSequences(); @Override String getSQLSequenceExists( String sequenceName ); @Override String getSQLCurrentSequenceValue( String sequenceName ); @Override String getSQLNextSequenceValue( String sequenceName ); }
MonetDBDatabaseMeta extends BaseDatabaseMeta implements DatabaseInterface { @Override public String getFieldDefinition( ValueMetaInterface v, String tk, String pk, boolean use_autoinc, boolean add_fieldname, boolean add_cr ) { StringBuilder retval = new StringBuilder(); String fieldname = v.getName(); int length = v.getLength(); int precision = v.getPrecision(); Boolean mode = MonetDBDatabaseMeta.safeModeLocal.get(); boolean safeMode = mode != null && mode.booleanValue(); if ( add_fieldname ) { if ( safeMode ) { fieldname = getSafeFieldname( fieldname ); } retval.append( fieldname + " " ); } int type = v.getType(); switch ( type ) { case ValueMetaInterface.TYPE_TIMESTAMP: case ValueMetaInterface.TYPE_DATE: retval.append( "TIMESTAMP" ); break; case ValueMetaInterface.TYPE_BOOLEAN: if ( supportsBooleanDataType() ) { retval.append( "BOOLEAN" ); } else { retval.append( "CHAR(1)" ); } break; case ValueMetaInterface.TYPE_NUMBER: case ValueMetaInterface.TYPE_INTEGER: case ValueMetaInterface.TYPE_BIGNUMBER: if ( fieldname.equalsIgnoreCase( tk ) || fieldname.equalsIgnoreCase( pk ) ) { if ( use_autoinc ) { retval.append( "SERIAL" ); } else { retval.append( "BIGINT" ); } } else { if ( precision == 0 ) { if ( length > 9 ) { if ( length < 19 ) { retval.append( "BIGINT" ); } else { retval.append( "DECIMAL(" ).append( length ).append( ")" ); } } else if ( type == ValueMetaInterface.TYPE_NUMBER ) { retval.append( "DOUBLE" ); } else { retval.append( "BIGINT" ); } } else { if ( length > 15 ) { retval.append( "DECIMAL(" ).append( length ); if ( precision > 0 ) { retval.append( ", " ).append( precision ); } retval.append( ")" ); } else { retval.append( "DOUBLE" ); } } } break; case ValueMetaInterface.TYPE_STRING: if ( length > getMaxVARCHARLength() ) { retval.append( "CLOB" ); } else { retval.append( "VARCHAR(" ); if ( length > 0 ) { retval.append( length ); } else { if ( safeMode ) { retval.append( DEFAULT_VARCHAR_LENGTH ); } } retval.append( ")" ); } break; default: retval.append( " UNKNOWN" ); break; } if ( add_cr ) { retval.append( Const.CR ); } return retval.toString(); }  @Override int[] getAccessTypeList(); @Override int getDefaultDatabasePort(); @Override int getNotFoundTK( boolean use_autoinc ); @Override String getDriverClass(); @Override String getURL( String hostname, String port, String databaseName ); @Override boolean isFetchSizeSupported(); @Override boolean supportsBitmapIndex(); @Override boolean supportsAutoInc(); @Override boolean supportsBatchUpdates(); @Override boolean supportsSetMaxRows(); @Override String getTruncateTableStatement( String tableName ); @Override String getAddColumnStatement( String tablename, ValueMetaInterface v, String tk, boolean use_autoinc,
    String pk, boolean semicolon ); @Override String getModifyColumnStatement( String tablename, ValueMetaInterface v, String tk, boolean use_autoinc,
    String pk, boolean semicolon ); @Override String[] getReservedWords(); @Override String getFieldDefinition( ValueMetaInterface v, String tk, String pk, boolean use_autoinc,
    boolean add_fieldname, boolean add_cr ); @Override String[] getUsedLibraries(); @Override String getSQLQueryFields( String tableName ); @Override boolean supportsResultSetMetadataRetrievalOnly(); @Override int getMaxVARCHARLength(); @Override boolean supportsSequences(); @Override String getSQLListOfSequences(); @Override String getSQLSequenceExists( String sequenceName ); @Override String getSQLCurrentSequenceValue( String sequenceName ); @Override String getSQLNextSequenceValue( String sequenceName ); static ThreadLocal<Boolean> safeModeLocal; static final int DEFAULT_VARCHAR_LENGTH; }