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 7E0A452879 for ; Sat, 4 Jun 2005 05:22:42 -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 80391-04 for ; Sat, 4 Jun 2005 08:22:37 +0000 (GMT) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.201]) by svr1.postgresql.org (Postfix) with ESMTP id B9D9D52854 for ; Sat, 4 Jun 2005 05:22:36 -0300 (ADT) Received: by wproxy.gmail.com with SMTP id 69so518593wra for ; Sat, 04 Jun 2005 01:22:38 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=hIiYEV7/e07/5hLpPRt7hVRQJaoV35qq2j/X4iZG8ONhQ8+qopBMBAJH8X1cK2pwdE8pS3uFOkPPVnBcpfCGLUMOB6PA344+tRwc+OO6/tUlpHEsAJ6RGcTRCsKETz7kFduKNooWHH/VRIOxOkk/8FnuqrlL/cMPuPG+t7/Y48I= Received: by 10.54.13.66 with SMTP id 66mr1823104wrm; Sat, 04 Jun 2005 01:22:38 -0700 (PDT) Received: by 10.54.30.45 with HTTP; Sat, 4 Jun 2005 01:22:35 -0700 (PDT) Message-ID: <7104a73705060401222c6cc5d2@mail.gmail.com> Date: Sat, 4 Jun 2005 11:22:38 +0300 From: Volkan YAZICI Reply-To: Volkan YAZICI To: David Hinkle Subject: Re: libpq, PQExecParams and the inserting of binary data Cc: pgsql-interfaces@postgresql.org In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <7104a7370506030943662e4be@mail.gmail.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.167 tagged_above=0 required=5 tests=AWL, RCVD_BY_IP X-Spam-Level: X-Archive-Number: 200506/19 X-Sequence-Number: 5587 Hi, On 6/3/05, David Hinkle wrote: > [snipped] > What I'm asking for is an expample or a document showing me how to do > it. While trying to prepare an example for your question, I scracthed sth. like this: {{{ Code snippet const char *command =3D "INSERT INTO tbl1 VALUES ($1)"; int nParams =3D 1; const Oid paramTypes[] =3D {17}; // 17, for bytea type's OID. const char * const paramValues[] =3D {"\\101\\102\\103"}; // "ABC" const int *paramLengths =3D NULL; // Letting the backend to const int *paramFormats =3D NULL; // deduce these params. int resultFormat =3D 0; // Result will be in text format. conn =3D PQconnectdb("dbname=3Dtest"); if ( PQstatus(conn) !=3D CONNECTION_OK ) { fprintf(stderr, "Connection failed!\n%s", PQerrorMessage(conn)); exit_nicely(conn); } printf("Command: \"%s\",\n", command); printf("Param. : \"%s\".\n", paramValues[0]); res =3D PQexecParams(conn, command, nParams, paramTypes, paramValues, paramLengths, paramFormats, resultFormat); if ( PQresultStatus(res) !=3D PGRES_COMMAND_OK ) { fprintf(stderr, "Insert failed!\n%s", PQresultErrorMessage(res)); PQclear(res); exit_nicely(conn); } else { printf("Insert succeeded.\n"); PQclear(res); } }}} Above code is working well for me. But while trying some other combinations (out of NULL usage) for PQexecParams parameters, I realized that when we use "const int paramFormats[] =3D {1};" execution dumps SegFault: {{{ Command output snippet $ gcc -g -Wall -lpq binIns.c && ./a.out=20 Command: "INSERT INTO tbl1 VALUES ($1)", Param. : "\101\102\103". Segmentation fault $ gdb ./a.out=20 [snipped] Using host libthread_db library "/lib/tls/libthread_db.so.1". (gdb) run Starting program: /home/knt/temp/a.out=20 Command: "INSERT INTO tbl1 VALUES ($1)", Param. : "\101\102\103". Program received signal SIGSEGV, Segmentation fault. 0xb7fcee05 in PQsendQueryGuts () from /usr/lib/libpq.so.4 (gdb) bt #0 0xb7fcee05 in PQsendQueryGuts () from /usr/lib/libpq.so.4 #1 0xb7fce902 in PQsendQueryParams () from /usr/lib/libpq.so.4 #2 0xb7fcf420 in PQexecParams () from /usr/lib/libpq.so.4 #3 0x08048811 in main () at binIns.c:34 }}} [Line 34: "res =3D PQexecParams(conn, ..."] Is this an expected behaviour or did I miss sth. important? Regards.