crash in psql unixodbc driver

From: "Amos Shapira" <amos(dot)shapira(at)gmail(dot)com>
To: sydpug(at)postgresql(dot)org
Subject: crash in psql unixodbc driver
Date: 2008-07-04 10:50:09
Message-ID: 9c2cca270807040350k61b3496dubdcc0ece21535ef2@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: sydpug

Hello,

We are having troubles with unixodbc postgresql driver on CentOS 5
x86_64 on a Xen DomU.

Digging through the net for a few days we couldn't find a solution,
only some hints for a similar problem hitting other clients (php
interpreter, for instance).

Here is a sample program which demonstrates the problem:

#include <stdio.h>
#include <string.h>
#include <sql.h>
#include <sqlext.h>
#include <string.h>

void extract_error(
char *fn,
SQLHANDLE handle,
SQLSMALLINT type)
{
SQLINTEGER i = 0;
SQLINTEGER native;
SQLCHAR state[ 7 ];
SQLCHAR text[256];
SQLSMALLINT len;
SQLRETURN ret;
fprintf(stderr,
"\n"
"The driver reported the following diagnostics whilst
running "
"%s\n\n",
fn);

do
{
ret = SQLGetDiagRec(type, handle, ++i, state, &native, text,
sizeof(text), &len );
if (SQL_SUCCEEDED(ret))
printf("%s:%ld:%ld:%s\n", state, i, native, text);
}
while( ret == SQL_SUCCESS );
}

main() {
SQLHENV env;
SQLHDBC dbc;
SQLHSTMT stmt;
SQLRETURN ret; /* ODBC API return status */
SQLSMALLINT columns; /* number of columns in result-set */
int row = 0;

/* Allocate an environment handle */
SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env);
/* We want ODBC 3 support */
SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void *)
SQL_OV_ODBC2, 0);
/* Allocate a connection handle */
SQLAllocHandle(SQL_HANDLE_DBC, env, &dbc);

char *szDSN = "TEMPLATE_1";
char *szUserName = "ayin";
char *szPassword = "";
/* Connect to the DSN mydsn */
ret = ::SQLConnect( dbc , (SQLCHAR *)szDSN ,
(SQLSMALLINT)strlen( szDSN ) , (SQLCHAR *)szUserName ,
(SQLSMALLINT)strlen( szUserName ) , (SQLCHAR *)szPassword ,
(SQLSMALLINT)strlen( szPassword ) );

/* Allocate a statement handle */
SQLAllocHandle(SQL_HANDLE_STMT, dbc, &stmt);

ret = SQLExecDirect(stmt, (SQLCHAR *)"select * from
not_existing_table", SQL_NTS);
if ( !SQL_SUCCEEDED(ret) )
extract_error( "Error SQLExecDirect" , stmt,
SQL_HANDLE_STMT );

ret = ::SQLDisconnect( dbc );

}

Here is some output with info about the environment:

[dare(at)dev1 ~]$ uname -a
Linux dev1.dev 2.6.18-5-xen-amd64 #1 SMP Tue Dec 18 23:16:23 UTC 2007
x86_64 x86_64 x86_64 GNU/Linux

[dare(at)dev1 ~]$ g++ -v
Reading specs from /usr/lib/gcc/x86_64-redhat-linux/3.4.6/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-languages=c,c++,f77
--disable-libgcj --host=x86_64-redhat-linux
Thread model: posix
gcc version 3.4.6 20060404 (Red Hat 3.4.6-4)

[dare(at)dev1 ~]$

built and installed unixODBC out of the box

i.e.
./configure
./make
./make install

then configured the "ini" files to setup the driver and DNS

[dare(at)dev1 etc]$ pwd
/usr/local/etc

[dare(at)dev1 etc]$ more odbcinst.ini
[PostgreSQL]
Description = PostgreSQL driver for Linux
Driver = /usr/local/lib/libodbcpsql.so
Setup = /usr/local/lib/libodbcpsqlS.so
FileUsage = 1
UsageCount = 1

[dare(at)dev1 etc]$ more odbc.ini
[TEMPLATE_1]
Driver = PostgreSQL
Description = Postgres template db
Trace = No
TraceFile = /tmp/sql.log
Database = template1
Servername = localhost
UserName = ayin
Password =
Port = 5432
Protocol = 6.4
ReadOnly = No
RowVersioning = No
ShowSystemTables = No
ShowOidColumn = No
FakeOidIndex = No
ConnSettings =
ExtraSysTablePrefixes =

[dare(at)dev1 etc]$ isql -v TEMPLATE1 ayin
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL> quit

I cannot login to our development server to get a sample output right now.

Does anyone know what this is all about?

If you are in a position to work on it for money then we are willing
to pay, but it'll have to be fast (we need to resolve it by July
11th).

Thanks,

--Amos

Responses

Browse sydpug by date

  From Date Subject
Next Message Charles Duffy 2008-07-07 02:40:36 Re: crash in psql unixodbc driver
Previous Message Charles Duffy 2008-06-02 13:45:13 SydPUG for Tuesday 3rd June cancelled