Skip to content

Commit

Permalink
0002027: Firebird detection of auto increment columns should look for…
Browse files Browse the repository at this point in the history
… existence of trigger, not the generator itself
  • Loading branch information
chenson42 committed Oct 27, 2014
1 parent f454c5e commit bc8d34e
Showing 1 changed file with 16 additions and 14 deletions.
Expand Up @@ -23,7 +23,6 @@
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -145,38 +144,41 @@ protected Column readColumn(DatabaseMetaDataWrapper metaData, Map<String,Object>
*/
protected void determineAutoIncrementColumns(Connection connection, Table table)
throws SQLException {
// Since for long table and column names, the generator name will be
// shortened
// we have to determine for each column whether there is a generator for
// it
/*
* Since for long table and column names, the trigger name will be
* shortened we have to determine for each column whether there is a
* trigger on it
*/
Column[] columns = table.getColumns();
HashMap<String, Column> names = new HashMap<String, Column>();
String name;

for (int idx = 0; idx < columns.length; idx++) {
name = ((FirebirdDdlBuilder) getPlatform().getDdlBuilder()).getGeneratorName(table,
name = ((FirebirdDdlBuilder) getPlatform().getDdlBuilder()).getTriggerName(table,
columns[idx]);
if (!getPlatform().getDdlBuilder().isDelimitedIdentifierModeOn()) {
name = name.toUpperCase();
}
names.put(name, columns[idx]);
}

Statement stmt = connection.createStatement();

PreparedStatement stmt = connection.prepareStatement("SELECT RDB$TRIGGER_NAME FROM RDB$TRIGGERS WHERE RDB$RELATION_NAME=?");
stmt.setString(1, table.getName());
ResultSet rs = null;
try {
ResultSet rs = stmt.executeQuery("SELECT RDB$GENERATOR_NAME FROM RDB$GENERATORS");

rs = stmt.executeQuery();
while (rs.next()) {
String generatorName = rs.getString(1).trim();
Column column = (Column) names.get(generatorName);

String triggerName = rs.getString(1).trim();
Column column = (Column) names.get(triggerName);
if (column != null) {
column.setAutoIncrement(true);
}
}
rs.close();

} finally {
if (rs != null) {
rs.close();
}
stmt.close();
}
}
Expand Down

0 comments on commit bc8d34e

Please sign in to comment.