public void insertRow() throws SQLException {
synchronized (getConnectionSynchronization()) {
checksBeforeInsert();
setupContextStack();
LanguageConnectionContext lcc = getEmbedConnection().getLanguageConnection();
StatementContext statementContext = null;
try {
/*
* construct the insert statement
*
* If no values have been supplied for a column, it will be set
* to the column's default value, if any.
* If no default value had been defined, the default value of a
* nullable column is set to NULL.
*/
boolean foundOneColumnAlready = false;
StringBuffer insertSQL = new StringBuffer("INSERT INTO ");
StringBuffer valuesSQL = new StringBuffer("VALUES (");
CursorActivation activation = lcc.lookupCursorActivation(getCursorName());
ExecCursorTableReference targetTable =
activation.getPreparedStatement().getTargetTable();
// got the underlying (schema.)table name
insertSQL.append(getFullBaseTableName(targetTable));
ResultDescription rd = theResults.getResultDescription();
insertSQL.append(" (");
// in this for loop we are constructing list of column-names
// and values (?) ,... part of the insert sql
for (int i=1; i<=rd.getColumnCount(); i++) {
if (foundOneColumnAlready) {
insertSQL.append(",");
valuesSQL.append(",");
}
// using quotes around the column name
// to preserve case sensitivity
insertSQL.append(IdUtil.normalToDelimited(
rd.getColumnDescriptor(i).getName()));
if (columnGotUpdated[i-1]) {
valuesSQL.append("?");
} else {
valuesSQL.append("DEFAULT");
}
foundOneColumnAlready = true;
}
insertSQL.append(") ");
valuesSQL.append(") ");
insertSQL.append(valuesSQL);
// Context used for preparing, don't set any timeout (use 0)
statementContext = lcc.pushStatementContext(
isAtomic,
false,
insertSQL.toString(),
null,
false,
0L);
org.apache.derby.iapi.sql.PreparedStatement ps =
lcc.prepareInternalStatement(insertSQL.toString());
Activation act = ps.getActivation(lcc, false);
statementContext.setActivation(act);
// in this for loop we are assigning values for parameters
//in sql constructed earlier VALUES (?, ..)
for (int i=1, paramPosition=0; i<=rd.getColumnCount(); i++) {
// if the column got updated, do following