pg.ddx.io  pgsql-odbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Gustavo Pinsard <pinsard@rocksolid.com.br>
To: pgsql-odbc@postgresql.org
Subject: Re: INSERT INTO ... RETURNING id not behaving as expected with SQLNumResultCols
Date: Thu, 07 Oct 2010 15:31:13 -0300
Message-ID: <4CAE11F1.9060700@rocksolid.com.br> (raw)
In-Reply-To: <707269.14190.qm@web31813.mail.mud.yahoo.com>
References: <707269.14190.qm@web31813.mail.mud.yahoo.com>

Ryan,

You seem to have a buffer problem.  As you know you have to declare 
which columns you want returned from the INSERT statement. Thus, you 
need a compatible buffer to receive each column declared.

As you didn't inform how you're mounting your statement, nor the struct 
to hold the results of it, I can't say for sure.

But here is an example of how I deal with INSERT RETURNING, in my 
language of choice: Clarion.

   PROGRAM

   MAP
   END

szDBConn      CSTRING( 512 )
tblDummy      FILE, DRIVER( 'ODBC' ), NAME( 'dummy' ), OWNER( szDBConn )
RECORD          RECORD
id                ULONG
                 END
               END


   ! Clarion has roots in Cobol, and the following statement
   ! declares the executable part of the program
   CODE

   ! Lets prepare the connection string
   szDBConn = 'Driver={{PostgreSQL ANSI};database=test;uid=test;pwd=test'

   ! Lets open the "file", which is in reality just a buffer pointing
   ! to a table in a server, according to the "OWNER" modifier
   OPEN( tblDummy, 42h )

   ! Here I send the command I want - " & | " instructs to continue
   ! on the next line.  Clarion doesn't use ";" as an end of statement
   ! marker, but the \n\r sequence, and when we need, well, you figured.
   tblDummy{ PROP:SQL } = 'INSERT INTO customers ' & |
                          'VALUES ( 'GUSTAVO' ) ' & |
                          'RETURNING id'

   ! HERE IT IS - read whatever the server returned
   NEXT( tblDummy )

   ! This is a MessageBox() alright.
   MESSAGE( tblDummy.id )

   ! Ends program
   RETURN 0

The above code holds a complete program that will connect to a server 
(given teh connection strings is valid, off course), and issue an INSERT 
command against an existing "customers" table.

Now, how do I SEND the SQL command to de server? Using the transport 
buffer I declared: tblDummy.  This buffer reflects an existing table (or 
view) in the database.  In this case, a table called "dummy".

In Clarion, when I issue a PROP:SQL command attached to a buffer, the 
server responds back the informed buffer.  Then, a simple NEXT() will 
read the contents of the buffer, which is a struct at the end of the 
day, and I'm all set.

This tip of having a dummy table or view declared may help you to 
collect different types of information from the server, not always 
related to data tables.  You can, for that matter, ask the server who is 
logged, for how long, its version etc.

It is just a matter of having a compatible buffer to receive whatever 
the server sends back in response to a command.

HTH

Gustavo

Attachments:

  smime.p7s (application/pkcs7-signature, 5.5K) download

view thread (5+ messages)  latest in thread

Message-ID: <4CAE11F1.9060700@rocksolid.com.br>
Permalink:  ../4CAE11F1.9060700@rocksolid.com.br/
Also on:    postgresql.org/message-id/4CAE11F1.9060700@rocksolid.com.br

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-odbc@postgresql.org
  Cc: pinsard@rocksolid.com.br
  Subject: Re: INSERT INTO ... RETURNING id not behaving as expected with SQLNumResultCols
  In-Reply-To: <4CAE11F1.9060700@rocksolid.com.br>
  References: <707269.14190.qm@web31813.mail.mud.yahoo.com> <4CAE11F1.9060700@rocksolid.com.br>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox