final String[][] fieldDefinitions = impl_getFieldTypeDefinitions();
final String[] keyTypes = fieldDefinitions[0];
final String[] keyCreationArgs = fieldDefinitions[1];
Vector< HsqlColumnDescriptor > foreignKeyColumns = new Vector< HsqlColumnDescriptor >();
foreignKeyColumns.add( new HsqlColumnDescriptor( "ID", "integer", HsqlColumnDescriptor.PRIMARY ) );
Vector< String[] > foreignKeyValues = new Vector< String[] >();
StringBuffer foreignKeyInsertSQL = new StringBuffer();
foreignKeyInsertSQL.append( "INSERT INTO \"" + m_foreignKeyTableName + "\" VALUES (?" );
final String[] displayValues = impl_getDisplayValues();
for ( int i=0; i<keyTypes.length; ++i )
{
final String tableName = keyTypes[i] + "_pk";
final String columnPKName = keyTypes[i] + "_pk";
final String columnFKName = keyTypes[i] + "_fk";
final String columnType = keyTypes[i] + ( keyCreationArgs[i] != null ? keyCreationArgs[i] : "" );
m_database.createTable( new HsqlTableDescriptor( tableName,
new HsqlColumnDescriptor[] {
new HsqlColumnDescriptor( columnPKName, columnType, HsqlColumnDescriptor.PRIMARY ),
new HsqlColumnDescriptor( "content", "varchar(50)" )
}
) );
// insert a few rows
StringBuffer sql = new StringBuffer();
sql.append( "INSERT INTO \"" );
sql.append( tableName );
sql.append( "\" VALUES (?, ?)");
XPreparedStatement statement = connection.prepareStatement( sql.toString() );
XParameters statementParameters = UnoRuntime.queryInterface( XParameters.class, statement );
final String[] keyValues = impl_getTypedValue( keyTypes[i], 0 );
for ( int row=0; row<displayValues.length; ++row )
{
statementParameters.setString( 1, keyValues[row] );
statementParameters.setString( 2, displayValues[row] );
statement.execute();
}
// remember a column descriptor for later creation of the table with the foreign keys
foreignKeyColumns.add( new HsqlColumnDescriptor( columnFKName, columnType, HsqlColumnDescriptor.REQUIRED,
tableName, columnPKName ) );
// remember the data to fill into this table
foreignKeyValues.add( keyValues );
foreignKeyInsertSQL.append( ", ?" );