Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1afqWz-0005Ib-7u for pgsql-bugs@arkaria.postgresql.org; Tue, 15 Mar 2016 15:05:09 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1afqWy-0001j7-Qu for pgsql-bugs@arkaria.postgresql.org; Tue, 15 Mar 2016 15:05:08 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1afm9y-0004Ui-1Z for pgsql-bugs@postgresql.org; Tue, 15 Mar 2016 10:25:06 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1afm9u-0002xS-Rl for pgsql-bugs@postgresql.org; Tue, 15 Mar 2016 10:25:05 +0000 MIME-Version: 1.0 Subject: BUG #14023: pq odbc driver crashed while get data from boolean column To: pgsql-bugs@postgresql.org From: suzhengchun@gmail.com Date: Tue, 15 Mar 2016 10:24:03 +0000 Message-ID: <20160315102403.29365.79998@wrigleys.postgresql.org> X-Pg-Spam-Score: -0.3 (/) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org The following bug has been logged on the website: Bug reference: 14023 Logged by: suzhengchun Email address: suzhengchun@gmail.com PostgreSQL version: 9.3.3 Operating system: debian 8.2 x64 Description: Hello, there: I met a problem recently with pq odbc driver, when there's a boolean column, the program just crashed. The database is in the attachment "test.db". My system/db is: szc@szc:20160315 15:49:28:qttest$ uname -a Linux szc 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt11-1+deb8u3 (2015-08-04) x86_64 GNU/Linux szc@szc:20160315 17:24:35:qttest$ lsb_release -a No LSB modules are available. Distributor ID: Debian Description: Debian GNU/Linux 8.2 (jessie) Release: 8.2 Codename: jessie szc@szc:20160315 17:24:38:qttest$ dpkg -l postgresql-9.4 .... +++-==============-============-============-================================== ii postgresql-9.4 9.4.4-0+deb8 amd64 object-relational SQL database, ve szc@szc:20160315 17:24:54:qttest$ I used unixodbc and qsql which from qt to do my work, their version are: szc@szc:20160315 17:29:23:qttest$ dpkg -l unixodbc .... ||/ Name Version Architecture Description +++-===============-============-============-=================================== ii unixodbc 2.3.1-3 amd64 Basic ODBC tools Qt's version is 5.5. postgresql odbc version is 9.3.3. (In fact, 9.1.1 on my debian 7.8 has the same problem.) The output from my program: ------------------------------------------------------------------------------ 5 fields in "person" Field: 0 , field: QSqlField("id", int, length: 10, required: no, generated: yes, typeID: 4, autoValue: false, readOnly: false) Field type: QVariant::int Field: 1 , field: QSqlField("name", QString, length: 40, required: no, generated: yes, autoValue: false, readOnly: false) Field type: QVariant::QString Field: 2 , field: QSqlField("sex", QString, length: 40, required: no, generated: yes, autoValue: false, readOnly: false) Field type: QVariant::QString Field: 3 , field: QSqlField("age", int, length: 10, required: no, generated: yes, typeID: 4, autoValue: false, readOnly: false) Field type: QVariant::int Field: 4 , field: QSqlField("open", QString, length: 5, required: no, generated: yes, typeID: 12, autoValue: false, readOnly: false) Field type: QVariant::QString size(): -1 QVariant(int, 1) QVariant(QString, "aaa") QVariant(QString, "m") QVariant(int, 10) Segmentation fault (core dumped) 139 szc@szc:20160315 16:52:38:qttest$ ------------------------------------------------------------------------------ The call stacks in the core is: Program terminated with signal SIGSEGV, Segmentation fault. #0 strlen () at ../sysdeps/x86_64/strlen.S:106 106 ../sysdeps/x86_64/strlen.S: No such file or directory. (gdb) bt #0 strlen () at ../sysdeps/x86_64/strlen.S:106 #1 0x00007efbf71e39de in __GI___strdup (s=0x0) at strdup.c:41 #2 0x00007efbf30377a4 in copy_and_convert_field (stmt=0x15294e0, field_type=16, atttypmod=-1, valuei=0x1518b00, fCType=-8, precision=-1, rgbValue=0x0, cbValueMax=0, pcbValue=0x7ffc2c305b68, pIndicator=0x7ffc2c305b68) at convert.c:1457 #3 0x00007efbf305a819 in PGAPI_GetData (hstmt=0x15294e0, icol=4, fCType=-8, rgbValue=0x0, cbValueMax=0, pcbValue=0x7ffc2c305b68) at results.c:1076 #4 0x00007efbf307c5f2 in SQLGetData (StatementHandle=0x15294e0, ColumnNumber=5, TargetType=-8, TargetValue=0x0, BufferLength=0, StrLen_or_Ind=0x7ffc2c305b68) at odbcapi.c:540 #5 0x00007efbf3f0ffb0 in SQLGetData (statement_handle=0x14e7780, column_number=5, target_type=-8, target_value=0x0, buffer_length=0, strlen_or_ind=0x7ffc2c305b68) at SQLGetData.c:443 #6 0x00007efbf417b513 in qGetStringData (hStmt=0x14e7780, column=4, colSize=6, unicode=true) at ../../../sql/drivers/odbc/qsql_odbc.cpp:383 #7 0x00007efbf417f71e in QODBCResult::data (this=0x151d860, field=4) at ../../../sql/drivers/odbc/qsql_odbc.cpp:1219 #8 0x00007efbf7daf55b in QSqlQuery::value (this=0x7ffc2c305f80, index=4) at kernel/qsqlquery.cpp:424 #9 0x0000000000403bcc in OpenDatabase () at pq.cpp:129 #10 0x000000000040272a in main (argc=1, argv=0x7ffc2c306908) at pq.cpp:22 (gdb) f 2 #2 0x00007efbf30377a4 in copy_and_convert_field (stmt=0x15294e0, field_type=16, atttypmod=-1, valuei=0x1518b00, fCType=-8, precision=-1, rgbValue=0x0, cbValueMax=0, pcbValue=0x7ffc2c305b68, pIndicator=0x7ffc2c305b68) at convert.c:1457 1457 char *str = strdup(rgbValueBindRow); (gdb) p rgbValueBindRow $1 = 0x0 (gdb) I debugged this a lot, and finally found the problem, by default postgresql odbc treats boolean as char/string. That's showed in the call stack. After I added this to postgresql odbc dsn: BoolsAsChar = 0 postgresql odbc driver will treat boolean values as SQL_BIT values, qt treats this as integer, then everything is fine. I don't care the type of the data, I just need to read it out, as default BoolsAsChar is enabled, it should work, but my program crashed, I think maybe it's a bug. Hoping this will help the others who meet the same problem. Thanks. -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs