TransactionController.MODE_RECORD,
TransactionController.ISOLATION_SERIALIZABLE);
// Create a 1 column row. int column = 1.
T_AccessRow r1 = new T_AccessRow(1);
SQLInteger c1 = new SQLInteger(1);
r1.setCol(0, c1);
// Get a location template
RowLocation rowloc1 = cc.newRowLocationTemplate();
// Insert the row and remember its location.
cc.insertAndFetchLocation(r1.getRowArray(), rowloc1);
// create another 1 column row. int column = 2.
// Get a location template
r1.setCol(0, new SQLInteger(2));
RowLocation rowloc2 = cc.newRowLocationTemplate();
// Insert the row and remember its location.
cc.insertAndFetchLocation(r1.getRowArray(), rowloc2);
// At this point the table looks like:
// col1
// ----
// 1
// 2
// RESOLVE - currently the store can't catch the following error:
/*
// Test that we can't alter while it is open.
try
{
tc.addColumnToConglomerate(conglomid, 1, c1);
throw T_Fail.testFailMsg(
"(alterTable) Allowed alter table while table was open.");
}
catch (StandardException t)
{
// expected error continue the test.
}
*/
// Test that we can't add data to columns that don't exist
// Currently we only error check in debug code.
// RESOLVE - should this be a runtime error?
if (SanityManager.DEBUG)
{
try
{
T_AccessRow two_column_row = new T_AccessRow(2);
SQLInteger col1 = new SQLInteger(3);
SQLInteger col2 = new SQLInteger(3);
cc.insert(two_column_row.getRowArray());
throw T_Fail.testFailMsg(
"(alterTable) Allowed insert of bad row.");
}
catch (StandardException t)
{
// expected error continue the test.
}
}
// Test that we can't fetch data columns that don't exist
// Currently we only error check for this in sanity code.
// RESOLVE - (mikem) should we check for this in released runtime?
if (SanityManager.DEBUG)
{
try
{
T_AccessRow two_column_row = new T_AccessRow(2);
if (!cc.fetch(
rowloc1, two_column_row.getRowArray(), (FormatableBitSet) null))
{
throw T_Fail.testFailMsg(
"(alterTable) Allowed fetch of bad row, bad ret val.");
}
throw T_Fail.testFailMsg(
"(alterTable) Allowed fetch of bad row.");
}
catch (StandardException t)
{
// expected error continue the test.
}
}
// Test that we can't fetch data columns that don't exist
// Currently we only error check for this in sanity code.
// RESOLVE - (mikem) should we check for this in released runtime?
if (SanityManager.DEBUG)
{
try
{
DataValueDescriptor[] third_column_row =
new DataValueDescriptor[3];
third_column_row[2] = new SQLInteger(3);
FormatableBitSet fetch_desc = new FormatableBitSet(3);
fetch_desc.set(2);
if (!cc.fetch(
rowloc1, third_column_row, fetch_desc))
{
throw T_Fail.testFailMsg(
"(alterTable) Allowed fetch of bad row, bad ret val.");
}
throw T_Fail.testFailMsg(
"(alterTable) Allowed fetch of bad row.");
}
catch (StandardException t)
{
// expected error continue the test.
}
}
// Test that we can't replace data columns that don't exist
// Currently we only error check for this in sanity code.
// RESOLVE - (mikem) should we check for this in released runtime?
if (SanityManager.DEBUG)
{
try
{
T_AccessRow two_column_row = new T_AccessRow(2);
SQLInteger col1 = new SQLInteger(3);
SQLInteger col2 = new SQLInteger(3);
cc.replace(rowloc1, two_column_row.getRowArray(), null);
throw T_Fail.testFailMsg(
"(alterTable) Allowed replace of bad row.");
}
catch (StandardException t)
{
// expected error continue the test.
}
}
// Test that we can't replace data columns that don't exist
if (SanityManager.DEBUG)
{
try
{
DataValueDescriptor[] second_column_row =
new DataValueDescriptor[2];
second_column_row[1] = new SQLInteger(3);
FormatableBitSet update_desc = new FormatableBitSet(2);
update_desc.set(1);
cc.replace(rowloc1, second_column_row, update_desc);
throw T_Fail.testFailMsg(
"(alterTable) Allowed partial row update of bad column.");
}
catch (StandardException t)
{
// expected error continue the test.
}
}
// Make sure commitNoSync gets executed sometimes.
tc.commitNoSync(TransactionController.RELEASE_LOCKS);
// now alter the conglomerate, add another int column
tc.addColumnToConglomerate(
conglomid, 1, c1, StringDataValue.COLLATION_TYPE_UCS_BASIC);
// Open the table after the close done by commit.
cc = tc.openConglomerate(
conglomid,
false,
TransactionController.OPENMODE_FORUPDATE,
TransactionController.MODE_RECORD,
TransactionController.ISOLATION_SERIALIZABLE);
T_AccessRow two_column_row = new T_AccessRow(2);
SQLInteger col1 = new SQLInteger(3);
SQLInteger col2 = new SQLInteger(3);
// fetch the rows and make sure you get null's in new fields.
if (!cc.fetch(
rowloc1, two_column_row.getRowArray(), (FormatableBitSet) null))
{
throw T_Fail.testFailMsg(
"(alterTable) Row not there.");
}
if ((((SQLInteger)two_column_row.getCol(0)).getInt() != 1) ||
(!two_column_row.getCol(1).isNull()))
{
throw T_Fail.testFailMsg(
"(alterTable) Bad column value after alter.");
}
if (!cc.fetch(
rowloc2, two_column_row.getRowArray(), (FormatableBitSet) null))
{
throw T_Fail.testFailMsg(
"(alterTable) Row not there.");
}
if ((((SQLInteger)two_column_row.getCol(0)).getInt() != 2) ||
(!two_column_row.getCol(1).isNull()))
{
throw T_Fail.testFailMsg(
"(alterTable) Bad column value after alter.");
}
// make sure insert of 2 column row works.
two_column_row = new T_AccessRow(2);
two_column_row.setCol(0, new SQLInteger(3));
two_column_row.setCol(1, new SQLInteger(300));
cc.insert(two_column_row.getRowArray());
// At this point the table looks like:
// col1 col2
// ---- ----
// 1 NA
// 2 NA
// 3 300
ScanController scan = tc.openScan(
conglomid,
false, // don't hold
TransactionController.OPENMODE_FORUPDATE, // for update
TransactionController.MODE_RECORD,
TransactionController.ISOLATION_SERIALIZABLE,
(FormatableBitSet) null, // all columns, all as objects
null, // start position - first row in conglomerate
0, // unused if start position is null.
null, // qualifier - accept all rows
null, // stop position - last row in conglomerate
0); // unused if stop position is null.
while (scan.next())
{
scan.fetch(two_column_row.getRowArray());
key_value = ((SQLInteger)two_column_row.getCol(0)).getInt();
switch(key_value)
{
case 1:
{
// Set non-existent column value to 100
if (!two_column_row.getCol(1).isNull())
{
throw T_Fail.testFailMsg(
"(alterTable) Bad column value after alter.");
}
// test that replace field works on alter added column
// make result row be: (1, 100)
two_column_row.setCol(1, new SQLInteger(100));
scan.replace(two_column_row.getRowArray(), (FormatableBitSet) null);
break;
}
case 2:
{
if (!two_column_row.getCol(1).isNull())
{
throw T_Fail.testFailMsg(
"(alterTable) Bad column value after alter.");
}
// test that replace row works on alter added column row.
// make result row be: (2, 200)
two_column_row.setCol(1, new SQLInteger(200));
scan.replace(two_column_row.getRowArray(), (FormatableBitSet) null);
break;
}