pglib and long queries - Mailing list pgsql-hackers

From Marc Tardif
Subject pglib and long queries
Date
Msg-id Pine.BSF.4.10.10001221305580.22701-100000@server.b0x.com
Whole thread Raw
List pgsql-hackers
I am using a c program to insert the contents of mail messages into
postgresql. First, I copy the message from stdin into a char pointer which
I malloc at every line, then I use the following code to insert into a
table:

char query[1024];
PGresult *res;
...
sprint(query, "insert into mail_msg values ('%s'), message);
res = PQexec(conn, query);
...

There is obviously more than one problem here, the most important being
I'm inserting a message of undetermined length into a char array of 1024
bytes. Second, I'm not parsing the message for apostrophes or other
characters which would mess-up my query.

I'd appreciate if someone could suggest a solution to either problem, or
point me towards sample source code I could learn from. Please do not
suggest using Perl, I enjoy c even though I am still not very proficient
at it and this is a good opportunity to practice.

Thanks again,
Marc



pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: [HACKERS] off topic
Next
From: "Ansley, Michael"
Date:
Subject: Explain output