Can you tell me if it's possible to retrieve primary key (generated by a trigger before insert) after my insert?
I set ParamType to Db::ptOutput. The retrieve value is empty : pOraSQL->ParamByName("ID")->AsString.
Can you help me?
retrieve primary key after insert
Hello,
To retrieve primary key (which is created in a trigger) you can use the following code:
TOraSession *OraSession = new TOraSession(NULL);
OraSession->Server = "SERVER";
OraSession->Username = "USER";
OraSession->Password = "PASSWD";
OraSession->Connect();
TOraSQL *OraSQL = new TOraSQL(NULL);
OraSQL->Session = OraSession;
OraSQL->SQL->Text = "INSERT INTO TEST(TEXT) VALUES(:TEXT) RETURNING ID INTO :ID";
OraSQL->ParamByName("TEXT")->ParamType = ptInput;
OraSQL->ParamByName("TEXT")->DataType = ftString;
OraSQL->ParamByName("TEXT")->AsString = "TEST";
OraSQL->ParamByName("ID")->ParamType = ptOutput;
OraSQL->ParamByName("ID")->DataType = ftInteger;
OraSQL->Execute();
ShowMessage(OraSQL->ParamByName("ID")->AsString);
To retrieve primary key (which is created in a trigger) you can use the following code:
TOraSession *OraSession = new TOraSession(NULL);
OraSession->Server = "SERVER";
OraSession->Username = "USER";
OraSession->Password = "PASSWD";
OraSession->Connect();
TOraSQL *OraSQL = new TOraSQL(NULL);
OraSQL->Session = OraSession;
OraSQL->SQL->Text = "INSERT INTO TEST(TEXT) VALUES(:TEXT) RETURNING ID INTO :ID";
OraSQL->ParamByName("TEXT")->ParamType = ptInput;
OraSQL->ParamByName("TEXT")->DataType = ftString;
OraSQL->ParamByName("TEXT")->AsString = "TEST";
OraSQL->ParamByName("ID")->ParamType = ptOutput;
OraSQL->ParamByName("ID")->DataType = ftInteger;
OraSQL->Execute();
ShowMessage(OraSQL->ParamByName("ID")->AsString);