Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WIFpZ-00050x-9w for pgsql-odbc@arkaria.postgresql.org; Tue, 25 Feb 2014 11:05:45 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WIFpY-0007hl-LE for pgsql-odbc@arkaria.postgresql.org; Tue, 25 Feb 2014 11:05:44 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WIFpW-0007hc-Jg for pgsql-odbc@postgresql.org; Tue, 25 Feb 2014 11:05:42 +0000 Received: from smtp-outbound-1.vmware.com ([208.91.2.12]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WIFpQ-0006SG-Vw for pgsql-odbc@postgresql.org; Tue, 25 Feb 2014 11:05:41 +0000 Received: from sc9-mailhost1.vmware.com (sc9-mailhost1.vmware.com [10.113.161.71]) by smtp-outbound-1.vmware.com (Postfix) with ESMTP id 8275B286D6; Tue, 25 Feb 2014 03:05:33 -0800 (PST) Received: from zcs-prod-ext-mta-1.vmware.com (zcs-prod-ext-mta-1.vmware.com [10.113.62.223]) by sc9-mailhost1.vmware.com (Postfix) with ESMTP id 65DE31819A; Tue, 25 Feb 2014 03:05:33 -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 11633120030; Tue, 25 Feb 2014 03:05:32 -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 03:05:30 -0800 (PST) Message-ID: <530C78F7.5050304@vmware.com> Date: Tue, 25 Feb 2014 13:05:27 +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: "Inoue, Hiroshi" 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> In-Reply-To: <530C177F.2030906@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 06:09 AM, Inoue, Hiroshi wrote: > (2014/02/14 21:54), Heikki Linnakangas wrote: >> Microsoft has a table of SQL_C_* codes and which C types they correspond >> to (http://msdn.microsoft.com/en-us/library/ms714556%28v=vs.85%29.aspx), >> but that's not taking into account other operating systems where the >> widths of C integer types are different. We didn't explicitly discuss in >> that psqlodbc mailing list thread if it's sane that SQL_C_LONG means a >> 32-bit integer regardless of how wide the C "long" type actually is. > > I don't think so. > Where do you find references to OS native C types in ODBC's spec? > ODBC uses its own SQL types in its spec and each SQL_C_xxxxxxx > stands for one of them not a native one. See the page I linked to above. It has a table with a one-to-one-to-one relationship between the SQL_C_xxx, ODBC C typedef, and the native C type. For example, for SQL_C_LONG, it says that the corresponding ODBC type is SQLINTEGER, which equals to C "long int". Such a one-to-one-to-one relationship is clear as far as Microsoft is concerned, as in Windows "long int" is always a 32-bit integer. From the SQL_C_xxx names it's quite clear that SQL_C_LONG refers to the native C type, "long". And as long as you're working in a Microsoft environment, there's no confusion because sizeof(long) == sizeof(SQLINTEGER). But on other platforms, it's a different story. Looking at my draft copy of the SQL 2011 standard, "Part 3: Call-Level Interface (SQL/CLI)", I don't see any mention of the SQL_C_* data types. It was probably left out of the standard, precisely because it would've caused confusion on non-Microsoft platforms. > For 32bit integers, use SQL_C_LONG (SQLINTEGER). > For 64bit integers, use SQL_C_BIGINT (SQLBIGINT). > There's no type named SQLxxLONGxx. > > I can see the following line in sqlext.h provided by Microsoft or unixODBC. > > #define SQL_C_LONG SQL_INTEGER /* INTEGER > */ > > It means that those driver manager think SQL_C_LONG means SQLINTEGER. > What meaning does it have to take different way from the driver manager > whose APIs ODBC applications call? Yeah, that's how unixODBC has resolved the situation, but it's not obvious. In fact, I'd argue that most applications are *not* written that way. For example, look at this code example from Microsoft: http://technet.microsoft.com/en-us/library/aa177876%28v=sql.80%29.aspx It does this: long lEmpID; ... SQLBindCol(hStmt, 1, SQL_C_LONG, (SQLPOINTER) &lEmpID, sizeof(long), &pIndicators[0]); That sample code will *not* work with unixodbc on a big-endian platform where sizeof(long) == 8. See also http://mailman.unixodbc.org/pipermail/unixodbc-support/2008-June/001756.html. According to that post, while unixODBC takes the stance that SQL_C_LONG corresponds to a 32-bit SQLINTEGER, iodbc has taken a different view. On iodbc, SQL_C_LONG means C native type "long", whether it's 32-bits or 64-bits wide. That's reasonable; thanks to that decision, the above sample code would work on iodbc without modifications. (However, now that I actually look at the iODBC code in their git repository, ISTM they're also defining SQL_C_LONG to bit 32-bits, ie. the same as unixODBC. Weird, maybe they changed their mind at some point..) Just to be clear, I agree with the decision that SQL_C_LONG means a 32-bit type, regardless of sizeof(long). But it's not obvious! That decision will break applications. In summary: 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.. - Heikki -- Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-odbc