Package: libmyodbc
Version: 3.51.11-6.1
Severity: normal

Hello,

the attached sample code gives different results with myodbc than it
does with the sqlite and postgres ODBC drivers currently available in
Debian.

Some discussion about it can be found at the end of
http://bugs.debian.org/cgi-bin/pkgreport.cgi?pkg=odbc-postgresql;dist=unstable

This doesn't seem to break any application currently in Etch.


Ciao,

Enrico

-- System Information:
Debian Release: 4.0
  APT prefers testing
  APT policy: (500, 'testing')
Architecture: amd64 (x86_64)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.6.20.1enrico
Locale: LANG=it_IT.UTF-8, LC_CTYPE=it_IT.UTF-8 (charmap=UTF-8)

Versions of packages libmyodbc depends on:
ii  debconf [debconf-2.0]       1.5.11       Debian configuration management sy
ii  libc6                       2.3.6.ds1-13 GNU C Library: Shared libraries
ii  libltdl3                    1.5.22-4     A system independent dlopen wrappe
ii  libmysqlclient15off         5.0.32-7     mysql database client library
ii  odbcinst1debian1            2.2.11-13    Support library and helper program
ii  zlib1g                      1:1.2.3-13   compression library - runtime

Versions of packages libmyodbc recommends:
ii  unixodbc                      2.2.11-13  ODBC tools libraries

-- debconf information:
  libmyodbc/addtoodbc: false
#include <stdio.h>
#include <stdlib.h>
#include <sql.h>
#include <sqlext.h>

void check(SQLSMALLINT handletype, SQLHSTMT stm, int res)
{
	if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO))
	{
		static const int strsize = 200;
		char stat[10], msg[strsize];
		SQLINTEGER err;
		SQLSMALLINT mlen;
		SQLGetDiagRec(handletype, stm, 1, (unsigned char*)stat, &err, (unsigned char*)msg, strsize, &mlen);
		if (mlen > strsize) mlen = strsize;
		fprintf(stderr, "Error %d %s: %.*s\n", err, stat, mlen, msg);
		exit(1);
	}
}

void checkenv(SQLHENV stm, int res)
{
	check(SQL_HANDLE_ENV, stm, res);
}
void checkdbc(SQLHSTMT stm, int res)
{
	check(SQL_HANDLE_DBC, stm, res);
}
void checkstm(SQLHSTMT stm, int res)
{
	check(SQL_HANDLE_STMT, stm, res);
}

int main()
{
	SQLHENV dba_od_env;
	SQLHDBC od_conn;
	SQLHSTMT stm;
	int32_t foo;

	SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &dba_od_env);
	checkenv(dba_od_env, SQLSetEnvAttr(dba_od_env, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0));

	SQLAllocHandle(SQL_HANDLE_DBC, dba_od_env, &od_conn);

	printf("Connecting\n");
	checkdbc(od_conn, SQLConnect(od_conn, "test", SQL_NTS, "enrico", SQL_NTS, "", SQL_NTS));

	SQLAllocHandle(SQL_HANDLE_STMT, od_conn, &stm);

	printf("Creating table\n");
	checkstm(stm, SQLExecDirect(stm, "CREATE TABLE foo (id INTEGER)", SQL_NTS));
	printf("Populating table\n");
	checkstm(stm, SQLExecDirect(stm, "INSERT INTO foo VALUES (1)", SQL_NTS));

	/* Init foo with some garbage, to catch the case in which it's filled
	 * in only partially */
	foo=-1;

	checkstm(stm, SQLBindCol(stm, 1, SQL_C_SLONG, &foo, sizeof(foo), 0));
	printf("Querying table\n");
	checkstm(stm, SQLExecDirect(stm, "SELECT id FROM foo", SQL_NTS));

	if (SQLFetch(stm) == SQL_NO_DATA)
		fprintf(stderr, "No results for foo\n");

	printf("Foo is %ld\n", foo);

	checkstm(stm, SQLCloseCursor(stm));

	printf("Dropping table\n");
	checkstm(stm, SQLExecDirect(stm, "DROP TABLE foo", SQL_NTS));

	return 0;
}

Reply via email to