Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WILJ1-0000Un-Od for pgsql-odbc@arkaria.postgresql.org; Tue, 25 Feb 2014 16:56:31 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WILJ1-0005fV-8a for pgsql-odbc@arkaria.postgresql.org; Tue, 25 Feb 2014 16:56:31 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WILJ0-0005fP-Ov for pgsql-odbc@postgresql.org; Tue, 25 Feb 2014 16:56:30 +0000 Received: from smtp-outbound-2.vmware.com ([208.91.2.13]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WILIu-0005Aj-Aj for pgsql-odbc@postgresql.org; Tue, 25 Feb 2014 16:56:30 +0000 Received: from sc9-mailhost3.vmware.com (sc9-mailhost3.vmware.com [10.113.161.73]) by smtp-outbound-2.vmware.com (Postfix) with ESMTP id D9673287EC; Tue, 25 Feb 2014 08:56:20 -0800 (PST) Received: from zcs-prod-ext-mta-1.vmware.com (zcs-prod-ext-mta-1.vmware.com [10.113.62.223]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id D5DC5401DB; Tue, 25 Feb 2014 08:56:20 -0800 (PST) Received: from zcs-prod-ext-mta-1.vmware.com (localhost.localdomain [127.0.0.1]) by zcs-prod-ext-mta-1.vmware.com (Postfix) with ESMTP id 77371120034; Tue, 25 Feb 2014 08:56:19 -0800 (PST) Received: from [192.168.1.90] (zimbra-prod-ext-proxy-vip.vmware.com [10.113.63.87]) by zcs-prod-ext-mta-1.vmware.com (Postfix) with ESMTPSA; Tue, 25 Feb 2014 08:56:17 -0800 (PST) Message-ID: <530CCB30.8090606@vmware.com> Date: Tue, 25 Feb 2014 18:56:16 +0200 From: Heikki Linnakangas Organization: VMware User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20131103 Icedove/17.0.10 MIME-Version: 1.0 To: Hiroshi Inoue CC: Christoph Berg , PostgreSQL ODBC , psqlodbc@packages.debian.org Subject: Re: 09.03.0100 cursor failures on various architectures References: <20140212104524.GA4409@msgid.credativ.de> <52FE1220.9050205@vmware.com> <530C177F.2030906@tpf.co.jp> <530C78F7.5050304@vmware.com> <530CB308.6030507@tpf.co.jp> In-Reply-To: <530CB308.6030507@tpf.co.jp> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -6.9 (------) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-odbc Precedence: bulk Sender: pgsql-odbc-owner@postgresql.org On 02/25/2014 05:13 PM, Hiroshi Inoue wrote: >> >1. Most applications are written with the assumption that SQL_C_LONG >> >means the native C data type "long". That's clearly what SQL_C_LONG was >> >supposed to mean when the ODBC specification was written, and that's >> >what Microsoft's sample code does. >> > >> >2. That's*not* how psqlODBC or unixODBC interprets it. With unixODBC, >> >you should use the C data type "SQLINTEGER" with SQL_C_LONG. >> > >> >3. For maximum portability, an application should avoid using SQL_C_xx. >> >Instead, always use SQL_INTEGER or SQL_BIGINT, with an SQLINTEGER or >> >SQLBIGINT variable, and cast to native C types. >> > >> >We should document this somewhere, like in the FAQ.. > Unfortunately I'm not happy with your summary. > > My point is simple. > Use ODBC data type variables instead of native C data ones when calling > ODBC APIs. Hmm, isn't that the same as my point 3? I was thinking of something like below for the docs: ---- Don't use SQL_C_xxx. They are not part of the SQL/CLI specification, and hence not reliably portable across platforms. Instead, use the ODBC variable data types, like SQLINTEGER and SQLBIGINT, and the corresponding type codes (e.g. SQL_INTEGER and SQL_BIGINT). For example, the following code is not portable: long empID; ... SQLBindCol(stmt, 1, SQL_C_LONG, (SQLPOINTER) &empID, sizeof(long), &indicator); Instead, do this: SQLINTEGER empID; ... SQLBindCol(stmt, 1, SQL_INTEGER, (SQLPOINTER) &empID, sizeof(SQLINTEGER), &indicator); And if necessary, cast to the C type: long lEmpID = (long) empID; SQL_C_LONG, SQL_C_SLONG and SQL_C_ULONG in particular are known to be a problem, as the width of the C datatype "long" varies, but unixODBC and the psqlODBC driver always maps SQL_C_LONG to a 32-bit data type, regardless of the width of "long" on the platform. An application using SQL_C_LONG and "long" will not work correctly on a platform where sizeof(long) == 8. It is easily seen on big-endian systems, where the values returned will be off by 2^32, but can also lead to difficult to find bugs on little-endian systems, as the driver will not initialize the high 4 bytes. ---- - Heikki -- Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-odbc