[V6] DML does not work with TSmartQ and SELECT FROM SELECT
Posted: Tue 07 Jul 2009 16:29
I found another difference between ODAC 5 and 6. With ODAC 6 and TSmartQuery for exam. Append and Post does not work if the SQL statement contains a "SELECT * FROM (SELECT" statement. The first hurdle was that the PK field was readonly in contrast to ODAC 5, but that has something to do with the default value of SetFieldsReadOnly and so I set that to "False".
The test case for this is the following:
SQL for the test table
Delphi console application
Steps:
- create the table
- create a new console application in Delphi and paste the code
- adjust the constants cServer, cUserName and cPassword
- compile and run the example
expected: ORA-00001 on second post and one record in the DB
actual: no exceptions, but no record in the DB
- remove the first dot in "{.$DEFINE WITHOUT_SELECT_FROM_SELECT}"
- compile and run the example
expected: ORA-00001 on second post and one record in the DB
actual: ORA-00001 on second post and one record in the DB
The test case for this is the following:
SQL for the test table
Code: Select all
CREATE TABLE SMARTTESTTABLE (
PK INTEGER
);
ALTER TABLE SMARTTESTTABLE ADD CONSTRAINT PK_SMARTTESTTABLE PRIMARY KEY (PK);
Code: Select all
program SmartInsertTest;
{$APPTYPE CONSOLE}
{
CREATE TABLE SMARTTESTTABLE (
PK INTEGER
);
ALTER TABLE SMARTTESTTABLE ADD CONSTRAINT PK_SMARTTESTTABLE PRIMARY KEY (PK);
}
{.$DEFINE WITHOUT_SELECT_FROM_SELECT}
uses
Ora, OraSmart;
const
cServer = 'YourServer';
cUserName = 'YourUser';
cPassword = 'YourPassword';
var
S: TOraSession;
Q: TSmartQuery;
begin
S := TOraSession.Create(nil);
try
S.Server := cServer;
S.Username := cUserName;
S.Password := cPassword;
S.ConnectPrompt := False;
Q := TSmartQuery.Create(nil);
try
Q.Session := S;
{$IFDEF WITHOUT_SELECT_FROM_SELECT}
Q.SQL.Add('SELECT * FROM SMARTTESTTABLE');
{$ELSE ~WITHOUT_SELECT_FROM_SELECT}
Q.SQL.Add('SELECT * FROM (SELECT * FROM SMARTTESTTABLE)');
Q.Options.SetFieldsReadOnly := False;
{$ENDIF ~WITHOUT_SELECT_FROM_SELECT}
Q.KeyFields := 'PK';
Q.UpdatingTable := 'SMARTTESTTABLE';
Q.Open;
Q.Append;
Q.FieldByName('PK').AsInteger := 1;
Q.Post;
Q.Append;
Q.FieldByName('PK').AsInteger := 1;
Q.Post;
finally
Q.Free;
end;
finally
S.Free;
end;
end.
- create the table
- create a new console application in Delphi and paste the code
- adjust the constants cServer, cUserName and cPassword
- compile and run the example
expected: ORA-00001 on second post and one record in the DB
actual: no exceptions, but no record in the DB
- remove the first dot in "{.$DEFINE WITHOUT_SELECT_FROM_SELECT}"
- compile and run the example
expected: ORA-00001 on second post and one record in the DB
actual: ORA-00001 on second post and one record in the DB