insert fail after table creation
Posted: Thu 28 Jul 2011 15:43
I have a strange behaviour in a procedure i'm writing for automatic update of a database.
If i run multiple query one after the other inside a transaction it seems i can't insert data in a table create within the same transaction
this is an extremely simplified code to show what i'm talking about, i'm testing this on a firebird 2.5 database:
when executing the code, i get this error when the program try to insert some data in the created table:
it can't fine the table, but the table has just been created in the previous script (and i can see it if i check the database with an external tool)
i think it has something to do with transaction management, does anyone has a clue about this?
If i run multiple query one after the other inside a transaction it seems i can't insert data in a table create within the same transaction
this is an extremely simplified code to show what i'm talking about, i'm testing this on a firebird 2.5 database:
Code: Select all
procedure databaseUpdate;
var
DB: TUniConnection;
Q: TUniQuery;
begin
DB := TUniConnection.Create(nil);
Q := TUniQuery.Create(nil);
Q.Connection := DB;
try
// some code here to initialize database connection parameters: provider, host, database, user, password
DB.Open;
DB.StartTransaction;
Q.SQL.Clear;
Q.SQL.Add('CREATE TABLE TEST_TABLE (ID INTEGER, FIELD_01 INTEGER)');
Q.Execute;
Q.SQL.Clear;
Q.SQL.Add('INSERT INTO TEST_TABLE (ID, FIELD_01) VALUES (1, 117)');
Q.Execute; // <== here comes the error
Q.Commit;
finally
Q.Close;
Q.Free;
DB.Close;
DB.Free;
end;
end;
Code: Select all
Dynamic SQL Error
SQL error code = -204
Table unknown
TEST_TABLE
At line 1, column 14
i think it has something to do with transaction management, does anyone has a clue about this?