X-Original-To: pgsql-interfaces@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 2D640474E44 for ; Thu, 3 Apr 2003 21:14:13 -0500 (EST) Received: from news.hub.org (news.hub.org [64.49.215.80]) by postgresql.org (Postfix) with ESMTP id A9593474E42 for ; Thu, 3 Apr 2003 21:14:12 -0500 (EST) Received: by news.hub.org (Postfix, from userid 8) id 9155743A89E; Thu, 3 Apr 2003 21:14:12 -0500 (EST) From: "Frankie Lam" X-Newsgroups: comp.databases.postgresql.interfaces Subject: Re: Segmentation Fault Date: Fri, 4 Apr 2003 10:16:07 +0800 Organization: Hub.Org Networking Services (http://www.hub.org) Lines: 38 Message-ID: References: X-Complaints-To: usenet@news.hub.org X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 To: pgsql-interfaces@postgresql.org X-Spam-Status: No, hits=-16.3 required=5.0 tests=BAYES_01,PRIORITY_NO_NAME,QUOTED_EMAIL_TEXT,QUOTE_TWICE_1, REFERENCES autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200304/24 X-Sequence-Number: 3963 Thanks all for replying. > > len =strlen(PQgetvalue(res, 0, i)) * 2 + 1; // <========= > Why not using PQgetlength(res, 0, i)? Actually I'm quite new to libPQ, that's why I didn't know there's a PQgetlength function. :-) > > PQescapeString(tmp2, PQgetvalue(res, 0, i), len); // <========= > One last question: > Why are you using PQescapeString on PQgetvalue? > > The doc says: > If you want to include strings that have been received from a source > that is not trustworthy (for example, because a random user entered > them), you cannot directly include them in SQL queries for security > reasons. Instead, you have to quote special characters that are > otherwise interpreted by the SQL parser. hmm.., I did this on purpose. Because I want to grab SQL commands I previously stored in a table from one database, then reformat them and store them into another database. E.g. the reformatted string looks like: INSERT INTO tableOnAnotherDB(sqlCMD) values('delete from test where name=''\\\\'''); I'm trying to implement a scale-down'ed version of synchronous replication, only limited to replicating between two databases. And this C program is responsible for synchronizing the two databases and keep them consistent, in case one of them failed and is up again later and other cases. (checking who's master, and who's slave, are they accepting requests etc, is done by the server side stored functions. VB + ODBC + PL/PGSQL in backend) Regards Frankie Lam