Page 1 of 1

execSQL with POSTGRESQL

Posted: 15.12.2009, 18:45
by danielf
Hi all,
i have been using zeos version 6.1.5 for quite some time, i have been having trouble trying to migrate one of my old applications to use the new version of zeos 6.6.5.

One of the problems, is that i cant do a simple insert in the following way.

Iam using c++builder 6, with postgresql 8.2.13, zeos component 6.6.5, protocol "postgresql-8".

ZQuery1->SQL->Text = "INSERT INTO cars(model) VALUES('A3');";
ZQuery1->ExecSQL();

i get an memory access error.

I can execute the query in this way thow, but iam under the impression this is not correct way to execute i INSERT, UPDATE OR DELETE query.

ZQuery1->Close();
ZQuery1->SQL->Text = "INSERT INTO cars(model) VALUES('A3');";
ZQuery1->Open();

because this way the zquery remains Active, after executing the SQL code.

Hope someone can point me to the right direction.

Thanks in advanced

Posted: 16.12.2009, 22:31
by mdaems
Hi,

I can't tell you what's wrong with the first solution. It 'should work' the way you tried. I've no experience wit c++builder, nor postgresql.
You could try the 'shorthand' ZConnectio.ExecuteDirect function.

Mark

Posted: 17.12.2009, 08:37
by klchin
Hi,

I think you using the wrong command,

ZQuery1->Close();
ZQuery1->SQL->Text = "INSERT INTO cars(model) VALUES('A3');";
ZQuery1->Open(); <-- sohuld be ZQuery1->ExecSQL( );

Regards,
KL Chin

Posted: 17.12.2009, 22:50
by Pitfiend
After my previous experience using queries, I can tell that you need to close, clear, assign new command to SQL property, and then call ExecSQL for anything else than a SELECT command. Because they didn't return record sets to be shown, only the number of affected rows.

When you send a SELECT command, you create a cursor view that allows you to explore or examine a record set, that's why you open a SELECT to keep the recordset alive.

By the way, that works the same with BDE, and I even see same behavior in PowerBuilder or VB. You must expect that C/C++ does the same.

Posted: 18.12.2009, 11:54
by danielf
Thank you for your reply's

>I think you using the wrong command,
>ZQuery1->Close();
>ZQuery1->SQL->Text = "INSERT INTO cars(model) VALUES('A3');";
>ZQuery1->Open(); <-- sohuld be ZQuery1->ExecSQL( );

i know that's why i post this.

>... I can tell that you need to close, >clear, assign new command to SQL property, and then call ExecSQL for >anything else than a SELECT command. Because they didn't return record >sets to be shown, only the number of affected rows.

when using ZQuery1->SQL->Text = "";
it closes the zquery anyway, the problem is when executing the ExecSQL(), memory access error appears.

thank you all