pg.ddx.io  pgsql-odbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
SQL_DATA_AT_EXEC fails for SQL_C_BIGINT and SQL_C_NUMERIC
3+ messages / 2 participants
[nested] [flat]

* SQL_DATA_AT_EXEC fails for SQL_C_BIGINT and SQL_C_NUMERIC
@ 2014-06-14 20:05 John Smith <nukemd@hotmail.com>
  2014-06-14 22:20 ` Re: SQL_DATA_AT_EXEC fails for SQL_C_BIGINT and SQL_C_NUMERIC John Smith <nukemd@hotmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: John Smith @ 2014-06-14 20:05 UTC (permalink / raw)
  To: pgsql-odbc

Hi,

I discovered that SQL_DATA_AT_EXEC does not work for the types SQLBIGINT and SQL_NUMERIC_STRUCT. It seems to work for other basic types, though.

Attaching a test case that demonstrates the problem.

 		 	   		  =

-- 
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc

Attachments:

dataatexec-basictypes-test.c (text/plain, 4.1K) download /* * Tests DATA_AT_EXEC for simple types */ #include <stdio.h> #include <stdlib.h> #include "common.h" int main(int argc, char** argv) { SQLRETURN rc, rc2; HSTMT hstmt = SQL_NULL_HSTMT; SQLCHAR *sql; SQLINTEGER myint = 1337, myint_get = 0; SQLBIGINT mybigint = 1337, mybigint_get = 0; SQL_NUMERIC_STRUCT mydecimal, mydecimal_get; memset(&mydecimal, 0, sizeof(mydecimal)); memset(&mydecimal_get, 0, sizeof(mydecimal_get)); mydecimal.scale = 4; mydecimal.sign = 1; mydecimal.scale = 14; //set to 1337.0000 mydecimal.val[0] = 0x90; mydecimal.val[1] = 0x02; mydecimal.val[2] = 0xCC; SQLINTEGER i1 = 1, i2 = 2, i3 = 3; SQLLEN ind = SQL_DATA_AT_EXEC; test_connect(); rc = SQLAllocHandle(SQL_HANDLE_STMT, conn, &hstmt); if (!SQL_SUCCEEDED(rc)) { print_diag("failed to allocate stmt handle", SQL_HANDLE_DBC, conn); exit(1); } sql = "DROP TABLE IF EXISTS dataatexec_basictypes"; rc = SQLExecDirect(hstmt, sql, SQL_NTS); CHECK_STMT_RESULT(rc, "SQLExecDirect failed while dropping previous table", hstmt); sql = "CREATE TABLE dataatexec_basictypes (myint int4, mybigint bigint, mydecimal decimal(14, 4))"; rc = SQLExecDirect(hstmt, sql, SQL_NTS); CHECK_STMT_RESULT(rc, "SQLExecDirect failed while creating table", hstmt); sql = "INSERT INTO dataatexec_basictypes VALUES(?, ?, ?)"; rc = SQLPrepare(hstmt, sql, SQL_NTS); CHECK_STMT_RESULT(rc, "SQLPrepare failed", hstmt); rc = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &i1, sizeof(SQLINTEGER), &ind); CHECK_STMT_RESULT(rc, "SQLBindParam (SQLINTEGER) failed", hstmt); rc = SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_SBIGINT, SQL_BIGINT, 0, 0, &i2, sizeof(SQLBIGINT), &ind); CHECK_STMT_RESULT(rc, "SQLBindParam (SQLBIGINT) failed", hstmt); rc = SQLBindParameter(hstmt, 3, SQL_PARAM_INPUT, SQL_C_NUMERIC, SQL_NUMERIC, 0, 0, &i3, sizeof(SQL_NUMERIC_STRUCT), &ind); CHECK_STMT_RESULT(rc, "SQLBindParam (SQL_NUMERIC_STRUCT) failed", hstmt); rc2 = SQLExecute(hstmt); if (rc2 != SQL_NEED_DATA) { printf("SQLExcecute should have returned SQL_NEED_DATA."); exit(1); } while (rc2 == SQL_NEED_DATA) { SQLPOINTER p = NULL; rc2 = SQLParamData(hstmt, &p); if (SQL_SUCCEEDED(rc2)) break; switch (*(SQLINTEGER*)p) { case 1: rc = SQLPutData(hstmt, &myint, sizeof(SQLINTEGER)); CHECK_STMT_RESULT(rc, "SQLPutData (SQLINTEGER) failed", hstmt); break; case 2: rc = SQLPutData(hstmt, &mybigint, sizeof(SQLBIGINT)); CHECK_STMT_RESULT(rc, "SQLPutData (SQLBIGINT) failed", hstmt); break; case 3: rc = SQLPutData(hstmt, &mydecimal, sizeof(SQL_NUMERIC_STRUCT)); CHECK_STMT_RESULT(rc, "SQLPutData (SQLINTEGER) failed", hstmt); break; default: printf("SQLParamData returned unexpected value.\n"); exit(1); break; } } rc = SQLFreeStmt(hstmt, SQL_CLOSE); CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); sql = "SELECT myint, mybigint, mydecimal FROM dataatexec_basictypes"; rc = SQLPrepare(hstmt, sql, SQL_NTS); CHECK_STMT_RESULT(rc, "SQLPrepare failed", hstmt); rc = SQLBindCol(hstmt, 1, SQL_C_SLONG, &myint_get, 0, NULL); CHECK_STMT_RESULT(rc, "SQLBindCol (SQLINTEGER) failed", hstmt); rc = SQLBindCol(hstmt, 2, SQL_C_SBIGINT, &mybigint_get, 0, NULL); CHECK_STMT_RESULT(rc, "SQLBindCol (SQLBIGINT) failed", hstmt); rc = SQLBindCol(hstmt, 3, SQL_C_NUMERIC, &mydecimal_get, 0, NULL); CHECK_STMT_RESULT(rc, "SQLBindCol (SQL_NUMERIC_STRUCT) failed", hstmt); rc = SQLExecute(hstmt); CHECK_STMT_RESULT(rc, "SQLExecute failed", hstmt); rc = SQLFetch(hstmt); CHECK_STMT_RESULT(rc, "SQLFetch failed", hstmt); int fail = 0; if (myint != myint_get) { printf("myint <> myint_get\n"); fail = 1; } if (mybigint != mybigint_get) { printf("mybigint <> mybigint_get\n"); fail = 1; } if (memcmp(mydecimal.val, mydecimal_get.val, SQL_MAX_NUMERIC_LEN) != 0) { printf("mydecimal <> mydecimal_get\n"); fail = 1; } if (fail) exit(1); SQLFreeStmt(hstmt, SQL_CLOSE); SQLFreeHandle(SQL_HANDLE_STMT, hstmt); test_disconnect(); }
^ permalink raw reply [nested|flat] 3+ messages in thread

* Re: SQL_DATA_AT_EXEC fails for SQL_C_BIGINT and SQL_C_NUMERIC
  2014-06-14 20:05 SQL_DATA_AT_EXEC fails for SQL_C_BIGINT and SQL_C_NUMERIC John Smith <nukemd@hotmail.com>
@ 2014-06-14 22:20 ` John Smith <nukemd@hotmail.com>
  2014-06-16 11:54   ` Re: SQL_DATA_AT_EXEC fails for SQL_C_BIGINT and SQL_C_NUMERIC Inoue, Hiroshi <inoue@tpf.co.jp>
  0 siblings, 1 reply; 3+ messages in thread

From: John Smith @ 2014-06-14 22:20 UTC (permalink / raw)
  To: pgsql-odbc

Hi again,

The problem seems to be in function ctype_length in pgtypes.c. It's missing the lengths for SQL_C_BIGINT and SQL_C_NUMERIC.

Attaching patch and revised test case.



----------------------------------------
From: nukemd@hotmail.com
To: pgsql-odbc@postgresql.org
Subject: [ODBC] SQL_DATA_AT_EXEC fails for SQL_C_BIGINT and SQL_C_NUMERIC
Date: Sat, 14 Jun 2014 22:05:58 +0200


Hi,

I discovered that SQL_DATA_AT_EXEC does not work for the types SQLBIGINT and SQL_NUMERIC_STRUCT. It seems to work for other basic types, though.

Attaching a test case that demonstrates the problem.



--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc
 		 	   		  =

-- 
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc

Attachments:

dataatexec-basictypes-test.c (text/plain, 4.1K) download /* * Tests DATA_AT_EXEC for simple types */ #include <stdio.h> #include <stdlib.h> #include "common.h" int main(int argc, char** argv) { SQLRETURN rc, rc2; HSTMT hstmt = SQL_NULL_HSTMT; SQLCHAR *sql; SQLINTEGER myint = 1337, myint_get = 0; SQLBIGINT mybigint = 1337, mybigint_get = 0; SQL_NUMERIC_STRUCT mydecimal, mydecimal_get; memset(&mydecimal, 0, sizeof(mydecimal)); memset(&mydecimal_get, 0, sizeof(mydecimal_get)); mydecimal.scale = 4; mydecimal.sign = 1; mydecimal.precision = 14; //set to 1337.0000 mydecimal.val[0] = 0x90; mydecimal.val[1] = 0x02; mydecimal.val[2] = 0xCC; SQLINTEGER i1 = 1, i2 = 2, i3 = 3; SQLLEN ind = SQL_DATA_AT_EXEC; test_connect(); rc = SQLAllocHandle(SQL_HANDLE_STMT, conn, &hstmt); if (!SQL_SUCCEEDED(rc)) { print_diag("failed to allocate stmt handle", SQL_HANDLE_DBC, conn); exit(1); } sql = "DROP TABLE IF EXISTS dataatexec_basictypes"; rc = SQLExecDirect(hstmt, sql, SQL_NTS); CHECK_STMT_RESULT(rc, "SQLExecDirect failed while dropping previous table", hstmt); sql = "CREATE TABLE dataatexec_basictypes (myint int4, mybigint bigint, mydecimal decimal(14, 4))"; rc = SQLExecDirect(hstmt, sql, SQL_NTS); CHECK_STMT_RESULT(rc, "SQLExecDirect failed while creating table", hstmt); sql = "INSERT INTO dataatexec_basictypes VALUES(?, ?, ?)"; rc = SQLPrepare(hstmt, sql, SQL_NTS); CHECK_STMT_RESULT(rc, "SQLPrepare failed", hstmt); rc = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &i1, sizeof(SQLINTEGER), &ind); CHECK_STMT_RESULT(rc, "SQLBindParam (SQLINTEGER) failed", hstmt); rc = SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_SBIGINT, SQL_BIGINT, 0, 0, &i2, sizeof(SQLBIGINT), &ind); CHECK_STMT_RESULT(rc, "SQLBindParam (SQLBIGINT) failed", hstmt); rc = SQLBindParameter(hstmt, 3, SQL_PARAM_INPUT, SQL_C_NUMERIC, SQL_NUMERIC, 0, 0, &i3, sizeof(SQL_NUMERIC_STRUCT), &ind); CHECK_STMT_RESULT(rc, "SQLBindParam (SQL_NUMERIC_STRUCT) failed", hstmt); rc2 = SQLExecute(hstmt); if (rc2 != SQL_NEED_DATA) { printf("SQLExcecute should have returned SQL_NEED_DATA.\n"); exit(1); } while (rc2 == SQL_NEED_DATA) { SQLPOINTER p = NULL; rc2 = SQLParamData(hstmt, &p); if (SQL_SUCCEEDED(rc2)) break; switch (*(SQLINTEGER*)p) { case 1: rc = SQLPutData(hstmt, &myint, sizeof(SQLINTEGER)); CHECK_STMT_RESULT(rc, "SQLPutData (SQLINTEGER) failed", hstmt); break; case 2: rc = SQLPutData(hstmt, &mybigint, sizeof(SQLBIGINT)); CHECK_STMT_RESULT(rc, "SQLPutData (SQLBIGINT) failed", hstmt); break; case 3: rc = SQLPutData(hstmt, &mydecimal, sizeof(SQL_NUMERIC_STRUCT)); CHECK_STMT_RESULT(rc, "SQLPutData (SQLINTEGER) failed", hstmt); break; default: printf("SQLParamData returned unexpected value.\n"); exit(1); break; } } rc = SQLFreeStmt(hstmt, SQL_CLOSE); CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); sql = "SELECT myint, mybigint, mydecimal FROM dataatexec_basictypes"; rc = SQLPrepare(hstmt, sql, SQL_NTS); CHECK_STMT_RESULT(rc, "SQLPrepare failed", hstmt); rc = SQLBindCol(hstmt, 1, SQL_C_SLONG, &myint_get, 0, NULL); CHECK_STMT_RESULT(rc, "SQLBindCol (SQLINTEGER) failed", hstmt); rc = SQLBindCol(hstmt, 2, SQL_C_SBIGINT, &mybigint_get, 0, NULL); CHECK_STMT_RESULT(rc, "SQLBindCol (SQLBIGINT) failed", hstmt); rc = SQLBindCol(hstmt, 3, SQL_C_NUMERIC, &mydecimal_get, 0, NULL); CHECK_STMT_RESULT(rc, "SQLBindCol (SQL_NUMERIC_STRUCT) failed", hstmt); rc = SQLExecute(hstmt); CHECK_STMT_RESULT(rc, "SQLExecute failed", hstmt); rc = SQLFetch(hstmt); CHECK_STMT_RESULT(rc, "SQLFetch failed", hstmt); int fail = 0; if (myint != myint_get) { printf("myint <> myint_get\n"); fail = 1; } if (mybigint != mybigint_get) { printf("mybigint <> mybigint_get\n"); fail = 1; } if (memcmp(mydecimal.val, mydecimal_get.val, SQL_MAX_NUMERIC_LEN) != 0) { printf("mydecimal <> mydecimal_get\n"); fail = 1; } if (fail) exit(1); SQLFreeStmt(hstmt, SQL_CLOSE); SQLFreeHandle(SQL_HANDLE_STMT, hstmt); test_disconnect(); }
dataatexec-basictypes.patch (application/octet-stream, 686B) download diff --git "a/C:\\Users\\John\\AppData\\Local\\Temp\\TortoiseGit\\pgtBCA1.tmp\\pgtypes-0ce3504-left.c" "b/D:\\Dokument\\projekt\\psqlodbc\\pgtypes.c" index d7bde0a..8e1e099 100644 --- "a/C:\\Users\\John\\AppData\\Local\\Temp\\TortoiseGit\\pgtBCA1.tmp\\pgtypes-0ce3504-left.c" +++ "b/D:\\Dokument\\projekt\\psqlodbc\\pgtypes.c" @@ -2372,6 +2372,11 @@ ctype_length(SQLSMALLINT ctype) case SQL_C_INTERVAL_HOUR_TO_SECOND: case SQL_C_INTERVAL_MINUTE_TO_SECOND: return sizeof(SQL_INTERVAL_STRUCT); + case SQL_C_NUMERIC: + return sizeof(SQL_NUMERIC_STRUCT); + case SQL_C_SBIGINT: + case SQL_C_UBIGINT: + return sizeof(SQLBIGINT); #endif /* ODBCVER */ case SQL_C_BINARY:
^ permalink raw reply [nested|flat] 3+ messages in thread

* Re: SQL_DATA_AT_EXEC fails for SQL_C_BIGINT and SQL_C_NUMERIC
  2014-06-14 20:05 SQL_DATA_AT_EXEC fails for SQL_C_BIGINT and SQL_C_NUMERIC John Smith <nukemd@hotmail.com>
  2014-06-14 22:20 ` Re: SQL_DATA_AT_EXEC fails for SQL_C_BIGINT and SQL_C_NUMERIC John Smith <nukemd@hotmail.com>
@ 2014-06-16 11:54   ` Inoue, Hiroshi <inoue@tpf.co.jp>
  0 siblings, 0 replies; 3+ messages in thread

From: Inoue, Hiroshi @ 2014-06-16 11:54 UTC (permalink / raw)
  To: John Smith <nukemd@hotmail.com>; +Cc: pgsql-odbc

Hi John,

Applied the patch.

Thanks.
Hiroshi Inoue

(2014/06/15 7:20), John Smith wrote:
> Hi again,
>
> The problem seems to be in function ctype_length in pgtypes.c. It's missing the lengths for SQL_C_BIGINT and SQL_C_NUMERIC.
>
> Attaching patch and revised test case.
>
>
>
> ----------------------------------------
> From: nukemd@hotmail.com
> To: pgsql-odbc@postgresql.org
> Subject: [ODBC] SQL_DATA_AT_EXEC fails for SQL_C_BIGINT and SQL_C_NUMERIC
> Date: Sat, 14 Jun 2014 22:05:58 +0200
>
>
> Hi,
>
> I discovered that SQL_DATA_AT_EXEC does not work for the types SQLBIGINT and SQL_NUMERIC_STRUCT. It seems to work for other basic types, though.
>
> Attaching a test case that demonstrates the problem.
>
>
>
> --
> Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-odbc
>   		 	   		
>
>
>
>


-- 
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2014-06-16 11:54 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2014-06-14 20:05 SQL_DATA_AT_EXEC fails for SQL_C_BIGINT and SQL_C_NUMERIC John Smith <nukemd@hotmail.com>
2014-06-14 22:20 ` John Smith <nukemd@hotmail.com>
2014-06-16 11:54   ` Inoue, Hiroshi <inoue@tpf.co.jp>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox