execSQL with POSTGRESQL

In this forum we will discuss things relating the ZEOSLib 6.6.x stable versions

Moderators: gto, EgonHugeist

Post Reply
danielf
Fresh Boarder
Fresh Boarder
Posts: 5
Joined: 15.12.2009, 18:24

execSQL with POSTGRESQL

Post 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
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post 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
Image
klchin
Senior Boarder
Senior Boarder
Posts: 65
Joined: 02.09.2005, 06:27

Post 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
User avatar
Pitfiend
Senior Boarder
Senior Boarder
Posts: 68
Joined: 12.12.2009, 07:27

Post 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.
danielf
Fresh Boarder
Fresh Boarder
Posts: 5
Joined: 15.12.2009, 18:24

Post 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
Post Reply