Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZmhDH-0006y6-4D for pgsql-odbc@arkaria.postgresql.org; Thu, 15 Oct 2015 12:00:51 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZmhDG-0004s9-DP for pgsql-odbc@arkaria.postgresql.org; Thu, 15 Oct 2015 12:00:50 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZmhCr-0004SG-SV for pgsql-odbc@postgresql.org; Thu, 15 Oct 2015 12:00:26 +0000 Received: from orx-mxprd.serena.com ([205.142.227.27]) by makus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1ZmhCj-0004gl-SB for pgsql-odbc@postgresql.org; Thu, 15 Oct 2015 12:00:23 +0000 Received: from [10.130.41.54] (stal-dev-lx1.serena.com [10.130.41.54]) by orx-mxprd.serena.com (8.14.7/8.14.7) with ESMTP id t9FC0EAZ031106 for ; Thu, 15 Oct 2015 05:00:15 -0700 Reply-To: pgsql-odbc@postgresql.org To: pgsql-odbc@postgresql.org From: Vadym Krevs Subject: SQL_DATA_AT_EXEC processing broken for large objects in nightly git Organization: Serena Software Europe Ltd Message-ID: <561F954E.7020808@serena.com> Date: Thu, 15 Oct 2015 13:00:14 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------050404020709030306020904" X-Pg-Spam-Score: -1.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 This is a multi-part message in MIME format. --------------050404020709030306020904 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Hi, the nightly git of the psqlODBC driver appears to no longer support insertion into LO columns when using SQL_DATA_AT_EXEC mode. The latest released driver version - psqlodbc-09.03.0400 - works. I've tested this against both PostgreSQL 9.4.4 and 9.4.5 on openSUSE 13.2. An adapted variant of the large-object-test.c program that uses SQL_DATA_AT_EXEC mode is attached. When run as part of the regression test suite against psqlodbc-09.03.0400, both the large-object-data-at-exec-test.c test completes successfully, just like large-object-test.c, and produces the following output in test/results/large-object-data-at-exec.out: \! "./src/large-object-data-at-exec-test" connected inserting large object... reading it back... hex: 0102030405060708 disconnecting However, when run as part of the regression test suite against nightly git build of psqlodbc, the large-object-data-at-exec-test.c test fails, unlike large-object-test.c, and produces the following output in test/results/large-object-data-at-exec.out: connected inserting large object... SQLParamData failed (final call) HY000=unexpected NULL parameter value Regards, Vadym --------------050404020709030306020904 Content-Type: text/x-csrc; name="large-object-data-at-exec-test.c" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="large-object-data-at-exec-test.c" #include #include #include #include "common.h" static void printhex(unsigned char *b, int len) { int i; printf("hex: "); for (i = 0; i < len; i++) printf("%02X", b[i]); } #define CHECK_STMT_RESULT2(rc, msg, hstmt)\ if (SQL_SUCCESS != rc && SQL_SUCCESS_WITH_INFO != rc && SQL_NEED_DATA != rc) \ { \ print_diag(msg, SQL_HANDLE_STMT, hstmt);\ exit(1);\ } int main(int argc, char **argv) { int rc; HSTMT hstmt = SQL_NULL_HSTMT; char param1[20] = { 1, 2, 3, 4, 5, 6, 7, 8 }; SQLLEN cbParam1; char buf[100]; SQLLEN ind; 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); } /**** Insert a Large Object */ printf("inserting large object...\n"); rc = SQLPrepare(hstmt, (SQLCHAR *) "INSERT INTO lo_test_tab VALUES (1, ?)", SQL_NTS); CHECK_STMT_RESULT(rc, "SQLPrepare failed", hstmt); /* bind LO param as a data at execution parameter */ cbParam1 = SQL_DATA_AT_EXEC; rc = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_BINARY, /* value type */ SQL_LONGVARBINARY, /* param type */ 0, /* column size */ 0, /* dec digits */ param1, /* param value ptr */ 0, /* buffer len */ &cbParam1 /* StrLen_or_IndPtr */); CHECK_STMT_RESULT(rc, "SQLBindParameter failed", hstmt); /* Execute */ rc = SQLExecute(hstmt); CHECK_STMT_RESULT2(rc, "SQLExecute failed", hstmt); /* Check for data-at-execute parameters */ if (SQL_NEED_DATA == rc) { SQLLEN lobByteSize = 8; // sizeof param1 SQLLEN lobChunkSize = 4096; SQLPOINTER pParamId = 0; const char *what = 0; /* Get the parameter that needs data */ what = "SQLParamData failed (first call)"; rc = SQLParamData(hstmt, &pParamId); int error = SQL_SUCCESS != rc && SQL_SUCCESS_WITH_INFO != rc && SQL_NEED_DATA != rc; if (SQL_NEED_DATA == rc) { /* Send parameter data in chunks */ what = "SQLPutData failed (next chunk)"; while (!error && lobByteSize > lobChunkSize) { rc = SQLPutData(hstmt, (SQLPOINTER)pParamId, lobChunkSize); lobByteSize -= lobChunkSize; error = SQL_SUCCESS != rc && SQL_SUCCESS_WITH_INFO != rc && SQL_NEED_DATA != rc; } /* Send final chunk */ if (!error) { what = "SQLPutData failed (final chunk)"; rc = SQLPutData(hstmt, (SQLPOINTER)pParamId, lobByteSize); error = SQL_SUCCESS != rc && SQL_SUCCESS_WITH_INFO != rc && SQL_NEED_DATA != rc; } /* Make final call */ if (!error) { what = "SQLParamData failed (final call)"; rc = SQLParamData(hstmt, &pParamId); error = SQL_SUCCESS != rc && SQL_SUCCESS_WITH_INFO != rc; } } CHECK_STMT_RESULT(rc, (char*)what, hstmt); } rc = SQLFreeStmt(hstmt, SQL_CLOSE); CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); /**** Read it back ****/ printf("reading it back...\n"); SQLExecDirect(hstmt, (SQLCHAR *) "SELECT id, large_data FROM lo_test_tab WHERE id = 1", SQL_NTS); rc = SQLFetch(hstmt); CHECK_STMT_RESULT(rc, "SQLFetch failed", hstmt); rc = SQLGetData(hstmt, 2, SQL_C_BINARY, buf, sizeof(buf), &ind); CHECK_STMT_RESULT(rc, "SQLGetData failed", hstmt); printhex(buf, ind); printf("\n"); /* Clean up */ test_disconnect(); return 0; } --------------050404020709030306020904 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-odbc --------------050404020709030306020904--