I just noticed that from a C or C++ program using libpq or libpq++, I can send *one* command that contains several SQL statements separated by semicolon. Something like:
PgDatabase db (" .... ");
const char * const sql = "insert into blah (...); insert into blah (...)";
if (db.Exec (sql) == PGRES_COMMAND_OK) { cout << "Fine!" << endl; }
And I verify the table, and all the inserts took place (and of course, the program outputs "Fine!").
But I'm wondering -- is this a PostgreSQL extension, or is it "legal SQL"? In particular, I'm wondering if it is a feature that in the future you might decide to eliminate for not being ANSI-SQL compliant.
What happens if the first command is ok but the second one fails? I guess PgDatabase::Exec would return an error code, and PgDatabase::ErrorMessage would return the error message corresponding to the second statement (the one that failed). Am I correct in thinking this?
Any reason why this should be avoided? (on the plus side, I think this might increase efficiency for transactions where one executes several insert or update statements).
Thanks for any comments,
Carlos --
---------------------------(end of broadcast)--------------------------- TIP 4: Don't 'kill -9' the postmaster