X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 03FF4D1B17A for ; Wed, 2 Jun 2004 06:14:35 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 40056-07 for ; Wed, 2 Jun 2004 09:14:36 +0000 (GMT) Received: from shwurzbung.mniam.net (shwurzbung.mniam.net [81.210.98.198]) by svr1.postgresql.org (Postfix) with ESMTP id B6787D1B181 for ; Wed, 2 Jun 2004 06:14:32 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by shwurzbung.mniam.net (Postfix) with ESMTP id A5BF12343B for ; Wed, 2 Jun 2004 11:15:24 +0200 (CEST) Received: from shwurzbung.mniam.net ([127.0.0.1]) by localhost (shwurzbung.mniam.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 12146-10 for ; Wed, 2 Jun 2004 11:15:23 +0200 (CEST) Received: by shwurzbung.mniam.net (Postfix, from userid 1000) id 7D0902343D; Wed, 2 Jun 2004 11:15:23 +0200 (CEST) To: pgsql-interfaces@postgresql.org Subject: 'execute immediate' problem X-mniam: I am a daemon! ]=) From: Kamil Andrusz Date: Wed, 02 Jun 2004 11:15:23 +0200 Message-ID: <8765aa5nis.fsf@shwurzbung.mniam.net> User-Agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new at mniam.net X-Virus-Scanned: by amavisd-new at hub.org X-Archive-Number: 200406/1 X-Sequence-Number: 4929 Hello list, I've go a litlle test program, that should transfer data from one db to another. It's just a quick hack to check if it would work at all. ---- #include #include #include #include #include #include int main(int argc, char *argv[]) { EXEC SQL BEGIN DECLARE SECTION; char node_name[255]; char node_type[255]; char stmt[1024]; char ins[1024]; EXEC SQL END DECLARE SECTION; EXEC SQL WHENEVER SQLERROR sqlprint; EXEC SQL WHENEVER NOT FOUND continue; EXEC SQL CONNECT TO test1 AS src_link USER test; EXEC SQL CONNECT TO test2 AS dst_link USER test; sprintf(stmt, "SELECT node_name, node_type FROM node ORDER BY node_type"); EXEC SQL PREPARE node_p FROM :stmt; EXEC SQL AT src_link DECLARE node_c CURSOR FOR node_p; EXEC SQL AT src_link OPEN node_c; EXEC SQL WHENEVER SQLERROR sqlprint; EXEC SQL WHENEVER NOT FOUND goto _done; for (;;) { EXEC SQL AT src_link FETCH node_c INTO :node_name, :node_type; sprintf(ins, "INSERT INTO node (node_name, node_type) VALUES ('%s', '%s')", node_name, node_type); printf("%s;\n", ins); EXEC SQL AT dst_link EXECUTE IMMEDIATE :ins; } _done: EXEC SQL AT src_link CLOSE node_c; EXEC SQL AT src_link FREE node_p; EXEC SQL DISCONNECT dst_link; EXEC SQL DISCONNECT src_link; exit(0); } ---- The problem is, the 'EXEC SQL AT dst_link EXECUTE IMMEDIATE :ins;' doesn't seem to work. When I do a 'select * from node' on the test2 database it shows 0 rows. The 'debug' printf shows, that the :ins statement is correct. The node table in both db's have two columns, node_name and node_type. I'm running PostgreSQL 7.3.5 on OpenBSD 3.5. I think I'm missing something obvious. Any hints? Regards, Kamil Andrusz -- It's just a matter of opinion.