Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id B2F561337B4A for ; Thu, 7 Oct 2010 17:43:50 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 69177-04 for ; Thu, 7 Oct 2010 20:43:43 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from web31808.mail.mud.yahoo.com (web31808.mail.mud.yahoo.com [68.142.207.71]) by mail.postgresql.org (Postfix) with SMTP id 9015C1337B5D for ; Thu, 7 Oct 2010 17:43:42 -0300 (ADT) Received: (qmail 90554 invoked by uid 60001); 7 Oct 2010 20:43:41 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1286484221; bh=UlHkuarXsRwyv0WGnt9udoJ5HVH72lB77VDNZ3/5dBk=; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=l/5aopOm086JKTTw3LUsQWf/7YIFWVhrZcaCj1DVsbZJyJQWjCQ7g82SjgJd3QGu5qy3QH2b0QzPjOT7G2x16EYcsMWjy/cnwMCtbkIvdQnM97LzynXmQYrsDvjdeKAr/utoYaac7E2+bX8yMg4hMd9Pt79YxpfpI2ciOBDQOcA= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=G+CsdsOeode3qNVrJbOreVMM/14HIGGeemK5byWbiS8vP/uCy6EJIBx8G32hFosQf0ZjxZVEe/ODC72NhY+gXAkl/JrejJzlYOa94f5Rmf0g6b8oTjI5ppBmgDcbFJY6UO0zzfZjve4okOxki0cbGMt6oSHvLnq9UfPay+w60oA=; Message-ID: <622064.89478.qm@web31808.mail.mud.yahoo.com> X-YMail-OSG: _xoZstQVM1nV97fLRORzwYTZiXt4fBoPznPjAdwlnOO92P1 gewE- Received: from [98.226.3.245] by web31808.mail.mud.yahoo.com via HTTP; Thu, 07 Oct 2010 13:43:40 PDT X-Mailer: YahooMailClassic/11.4.9 YahooMailWebService/0.8.107.284920 Date: Thu, 7 Oct 2010 13:43:40 -0700 (PDT) From: Ryan Pfeiffer Subject: Re: INSERT INTO ... RETURNING id not behaving as expected with SQLNumResultCols To: pgsql-odbc@postgresql.org In-Reply-To: <707269.14190.qm@web31813.mail.mud.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201010/9 X-Sequence-Number: 10454 Ok, I believe I have found the problem. http://msdn.microsoft.com/en-us/library/ms711684(v=3DVS.85).aspx "The application can call SQLNumResultCols at any time after the statement = is prepared or executed. However, because some data sources cannot easily d= escribe the result sets that will be created by prepared statements, perfor= mance will suffer if SQLNumResultCols is called after a statement is prepar= ed but before it is executed." I suppose that's what I get for slapping an existing library into my softwa= re without completely understanding it. If I understand what I've read corr= ectly, SQLPrepare should only be used if I plan on repeating the same state= ment over and over with different variables. Since this is a simple wrapper, it seems that an error may have been made. = It calls SQLPrepare each time the wrapper classes are used, so even if it w= as repeated many times, SQLPrepare is still being called each time which I = think is not useful. Not sure on that though. At this point I moved up SQLE= xecute and I got the results I expected. --- On Thu, 10/7/10, Ryan Pfeiffer wrote: > From: Ryan Pfeiffer > Subject: Re: [ODBC] INSERT INTO ... RETURNING id not behaving as expected= with SQLNumResultCols > To: pgsql-odbc@postgresql.org > Date: Thursday, October 7, 2010, 12:51 PM > I'm writing it in visual c++. I've > been using DataLayer to interact with ODBC, here: http://www.codeproject.= com/KB/database/DataLayer.aspx >=20 > The code in question is: >=20 > ret =3D SQLPrepare(m_hstmt, (SQLCHAR*)selectStatement, > SQL_NTS); > if ( ( ret =3D=3D SQL_SUCCESS ) || ( ret =3D=3D > SQL_SUCCESS_WITH_INFO ) ) > { > =A0=A0=A0SQLSMALLINT numberColumns; >=20 > =A0=A0=A0// Get number of columns in the result > set > =A0=A0=A0ret =3D SQLNumResultCols(m_hstmt, > &numberColumns); >=20 > &numberColumns comes up as 0. Can SQLPrepare not be > used the way I want for INSERT INTO ... RETURNING? >=20 > And yes, I'm aware I could use another select statement, > and concurrency would *probably* not be an issue down the > road, but it bothers me that it is possible I could get the > wrong ID. I suppose I can just SELECT id WHERE val1 =3D x, > val2 =3D y, and so on as there should not be any exact > duplicates in my tables that I can think of at this point. > Still early on in development though. >=20 > Thanks, > Ryan >=20 > --- On Thu, 10/7/10, Gustavo Pinsard > wrote: >=20 > > From: Gustavo Pinsard > > Subject: Re: [ODBC] INSERT INTO ... RETURNING id not > behaving as expected with SQLNumResultCols > > To: pgsql-odbc@postgresql.org > > Date: Thursday, October 7, 2010, 6:11 AM > > Ryan, > >=20 > > What language are you writing your app? What is the > code > > you're using to=20 > > capture the returning id? > >=20 > > Also, are you aware that you can fire a new SELECT > > statement after=20 > > you're done inserting?=A0 In scenarios where you > > wouldn't have much=20 > > concurrency that can be a valid approach. > >=20 > > And don't forget that the OID column is there for you > to > > inspect. Ever=20 > > tried a SELECT OID FROM MyTable ORDER BY OID DESC > LIMIT 1 > > ? > >=20 > > Gustavo > >=20 > > On 07/10/2010 01:04, Ryan Pfeiffer wrote: > > > I'm using Postgres 8.4.1 and psqlodbc 08.04.0200. > I'm > > trying to execute a statement INSERT INTO > table/values > > RETURNING id to get the serial id. Problem is, > > SQLNumResultCols shows that there are zero columns. > The > > statement I used works fine in pgadmin. This seems > really > > basic and I am somewhat new to databases and odbc, but > does > > anyone have a solution? > > > > > > Thanks, > > > Ryan > > > > > > > > > > > > > >=20 > >=20 >=20 >=20 >=20 >=20 > --=20 > Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-odbc > =0A=0A=0A