I do create a new dataset. But the information seems to still be cached.
Here is my sample code:
// Table Test = create table TEST (f1 number not null default 0, f2 number not null default 0, f3 number not null default 0);
AnsiString Table = "TEST";
// Rename the existing table
SQLExec( frmMain->Session, "ALTER TABLE " + Owner + "." + Table + " RENAME TO " + Table + "_OLD" );
// Create the table and add the constraints
SQLExec( frmMain->Session, "create table TEST (f1 number not null default 0, f2 number not null default 0, f3 number not null default 0, nf1 number not null default 0)"
// Select from newly created table
TOracleDataSet *qryNewTable = new TOracleDataSet(Application);
DBSetup( frmMain->Session, qryNewTable );
qryNewTable->Close();
qryNewTable->SQL->Text = "SELECT " + Table + ".*, ROWID FROM " + Table;
qryNewTable->Open();
qryNewTable->Append();
// Now when I check "qryNewTable->FieldByName("NF1")->AsString" it is NULL when it should be "0"
// When I check "qryNewTable->FieldByName("F1")->AsString" it is "0"
// I have checked the structure in Oracle and everything is correct
void __fastcall DBSetup( TOracleSession *Session, TOracleDataSet *DB )
{
DB->Session = Session;
DB->CachedUpdates = false;
DB->CommitOnPost = false;
DB->CountAllRecords = false;
DB->QueryAllRecords = false;
DB->LockingMode = lmLockImmediate;
DB->ReadBuffer = 200;
DB->OracleDictionary->DefaultValues = true;
DB->OracleDictionary->DynamicDefaults = true;
}
int __fastcall SQLExec( TOracleSession *Session, AnsiString SQL )
{
bool status = true;
TOracleDataSet *q = new TOracleDataSet(Application);
try
{
DBSetup( Session, q );
q->SQL->Text = SQL;
q->ExecSQL();
q->Session->Commit();
}
catch( Exception &e )
{
ShowMessage( "SQLExec Error: " + e.Message.Trim() + "\nSQL = " + SQL );
status = false;
}
delete q;
Application->ProcessMessages();
return( status );
}