Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id E183B1337B5B for ; Thu, 7 Oct 2010 14:52:08 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 78356-01 for ; Thu, 7 Oct 2010 17:52:00 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from web31813.mail.mud.yahoo.com (web31813.mail.mud.yahoo.com [68.142.207.76]) by mail.postgresql.org (Postfix) with SMTP id 675651336DB6 for ; Thu, 7 Oct 2010 14:52:00 -0300 (ADT) Received: (qmail 29693 invoked by uid 60001); 7 Oct 2010 17:51:59 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1286473919; bh=O30qImrzVwg4s3LGFsgWpzYOWhvDTwudklFvHZy4aDs=; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=NtP7SRdomdLXuV/wuXYPh+4LgK5d6peyuPH+r6jh/+Y8Z7R6fHPBdbH1wAPMlJ+2UhiOhwjvJjTYvTksKIYsXIVQ2Fo1IMEkyLk88rVTPblcq2E5eAhAIWIOMO7S+3ERQUuUV04l1kX42Wn0Vf7p4ynbSBp9mdQse4SzelzMMH0= 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=17CJlDlgkIZtgSy1W9+ZZ/FNEXGOmdBRDpbyfnz6cnACY9uldgU0LBOk5G//SkyyuU60svVjsZgMOBn7SyuAybPGJ0bup1gZ2yKDvHfvygygBZIaCHJJAkeC9ArKFzcB0JbsyJZJW/ThRFG5d3wwoSQToeBu/UjvlgE5QWA3vBs=; Message-ID: <707269.14190.qm@web31813.mail.mud.yahoo.com> X-YMail-OSG: cCoHIjIVM1kerAKxEggVCVCKqN0SoyEyex23Z.BUoRGjkg5 pGlo5su02CF4U.3tsCC1nMblgpZWUjMEeBxE1vxL7VxYcUHPScdhjNOugQ_w Bf0bxhrBBOMvNCh8jVUMrkjBRCGqdqpf5HeN6QjDkTLoxQNpXCW6Tx1Hud_8 kqWwQYfy0d76P9xwDbZgRUkA.mxxCAsRhPoZO1ucrkik8TMomPVW7D_tVCCg mJkYjetfIL7ybhH2YLl.nBRBADRgEhFA9LS9Dhx5xndtCTxW9L995swtPkVQ w2UUcRn4tcvXDPPStXzrF3tY93vZuKlBbDLfMBvUDDAuhmRTPiEMSpBlm5Yq 7irZPTUwlyRB0WNeCpyO.WQjvpsUi8p85 Received: from [98.226.3.245] by web31813.mail.mud.yahoo.com via HTTP; Thu, 07 Oct 2010 10:51:59 PDT X-Mailer: YahooMailClassic/11.4.9 YahooMailWebService/0.8.107.284920 Date: Thu, 7 Oct 2010 10:51:59 -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: <4CADAAFD.2020501@rocksolid.com.br> 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/7 X-Sequence-Number: 10452 I'm writing it in visual c++. I've been using DataLayer to interact with OD= BC, here: http://www.codeproject.com/KB/database/DataLayer.aspx The code in question is: ret =3D SQLPrepare(m_hstmt, (SQLCHAR*)selectStatement, SQL_NTS); if ( ( ret =3D=3D SQL_SUCCESS ) || ( ret =3D=3D SQL_SUCCESS_WITH_INFO ) ) { SQLSMALLINT numberColumns; // Get number of columns in the result set ret =3D SQLNumResultCols(m_hstmt, &numberColumns); &numberColumns comes up as 0. Can SQLPrepare not be used the way I want for= INSERT INTO ... RETURNING? And yes, I'm aware I could use another select statement, and concurrency wo= uld *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 val= 1 =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 developme= nt though. Thanks, Ryan --- On Thu, 10/7/10, Gustavo Pinsard wrote: > 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 > =0A=0A=0A