Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZtvrM-00060M-GD for pgsql-odbc@arkaria.postgresql.org; Wed, 04 Nov 2015 11:04:08 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZtvrM-0003Kp-1e for pgsql-odbc@arkaria.postgresql.org; Wed, 04 Nov 2015 11:04:08 +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 1ZtvrL-0003Kh-Ka for pgsql-odbc@postgresql.org; Wed, 04 Nov 2015 11:04:07 +0000 Received: from mail-wm0-x229.google.com ([2a00:1450:400c:c09::229]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1ZtvrI-0006D5-D1 for pgsql-odbc@postgresql.org; Wed, 04 Nov 2015 11:04:06 +0000 Received: by wmll128 with SMTP id l128so110884906wml.0 for ; Wed, 04 Nov 2015 03:04:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:message-id:date:from:user-agent:mime-version:to:subject :references:in-reply-to:content-type; bh=wbQs+5i5uptLdTP4xqmTd5KFQzk/euYMcTTm9WKItGY=; b=rizN+ATO2lbp3PRHj8dgIM7dhuM5ATDlOst+d9pp4V6w2B3uQYKSnfzNd34oYTDAND G9TA2h4tCzllx6RZ6M2uEtUjKowEbntTrjIGkDbaxXasW+ezhZnBS9bghmHiJM1uuTjs G2ggv4WCu3KzIgmg+PS3fPc2N+Ieht5t8uV4sQlybrK0Qsa9mqBoeXSfyw2VuRKPJnE6 +M7HensaJ8qHVtZVVaTJ6J5n4bNjzk8xBxWx1JS9NNN7uL91nsD9D+N+cGw0zJsO5QOm MODJP75l4YxoRQuuDVxZWeWKSwBGuWXLzpe1vX49v1ia8gEcpoZw97zpc8OOCN6Ku5Pz X+Gg== X-Received: by 10.28.173.67 with SMTP id w64mr25619759wme.71.1446635043096; Wed, 04 Nov 2015 03:04:03 -0800 (PST) Received: from [192.168.1.111] (dsl-hkibrasgw1-58c38f-82.dhcp.inet.fi. [88.195.143.82]) by smtp.gmail.com with ESMTPSA id n17sm2430586wmg.17.2015.11.04.03.04.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Nov 2015 03:04:02 -0800 (PST) Message-ID: <5639E621.1020505@iki.fi> Date: Wed, 04 Nov 2015 13:04:01 +0200 From: Heikki Linnakangas User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.8.0 MIME-Version: 1.0 To: "Inoue, Hiroshi" , pgsql-odbc@postgresql.org Subject: Re: SQL_DATA_AT_EXEC processing broken for large objects in nightly git References: <561F954E.7020808@serena.com> <5639B85F.7030408@dream.email.ne.jp> In-Reply-To: <5639B85F.7030408@dream.email.ne.jp> Content-Type: multipart/mixed; boundary="------------050208090006020309050009" X-Pg-Spam-Score: -1.7 (-) 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. --------------050208090006020309050009 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On 11/04/2015 09:48 AM, Inoue, Hiroshi wrote: > Hi, > > I was able to reproduce it here. > Because I can't understand the current code at once, please give me some > time > to solve the problem. I also started looking at this last week, and came up with a patch that I think fixes it, but I got distracted before completing it and replying here. So here's what I came up with... - Heikki --------------050208090006020309050009 Content-Type: binary/octet-stream; name="large-object-data-at-exec-fix.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="large-object-data-at-exec-fix.patch" diff --git a/convert.c b/convert.c index 8802e6e..99ec4e5 100644 --- a/convert.c +++ b/convert.c @@ -4116,14 +4116,11 @@ inolog("ipara=%p paramType=%d %d proc_return=%d\n", ipara, ipara ? ipara->paramT } else if (!handling_large_object) { - CVT_APPEND_CHAR(qb, '?'); - return SQL_SUCCESS; + /* shouldn't happen */ + qb->errormsg = "unexpected NULL parameter value"; + qb->errornumber = STMT_EXEC_ERROR; + return SQL_ERROR; } - - /* shouldn't happen */ - qb->errormsg = "unexpected NULL parameter value"; - qb->errornumber = STMT_EXEC_ERROR; - return SQL_ERROR; } /* replace DEFAULT with something we can use */ diff --git a/test/expected/large-object-data-at-exec.out b/test/expected/large-object-data-at-exec.out new file mode 100644 index 0000000..e69de29 diff --git a/test/src/large-object-data-at-exec-test.c b/test/src/large-object-data-at-exec-test.c new file mode 100644 index 0000000..585e102 --- /dev/null +++ b/test/src/large-object-data-at-exec-test.c @@ -0,0 +1,160 @@ +/* + * Test data-at-execution, for a large object. + */ +#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);\ + } + + +/* + * Insert a large object to table, using a data-at-exec param. Then read it + * back and print. + */ +static void +do_test(HSTMT hstmt, int testno, int lobByteSize, char *lobData) +{ + char sql[200]; + int rc; + SQLLEN cbParam1; + char *buf; + SQLLEN ind; + + /**** Insert a Large Object */ + printf("inserting large object with len %d...\n", lobByteSize); + snprintf(sql, sizeof(sql), + "INSERT INTO lo_test_tab VALUES (%d, ?)", testno); + rc = SQLPrepare(hstmt, (SQLCHAR *) sql, 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 */ + lobData, /* 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 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"); + + snprintf(sql, sizeof(sql), + "SELECT id, large_data FROM lo_test_tab WHERE id = %d", testno); + SQLExecDirect(hstmt, (SQLCHAR *) sql, SQL_NTS); + rc = SQLFetch(hstmt); + CHECK_STMT_RESULT(rc, "SQLFetch failed", hstmt); + + buf = malloc(lobByteSize * 2); + rc = SQLGetData(hstmt, 2, SQL_C_BINARY, buf, lobByteSize * 2, &ind); + CHECK_STMT_RESULT(rc, "SQLGetData failed", hstmt); + + printhex(buf, ind); + printf("\n"); + + free(buf); + + rc = SQLFreeStmt(hstmt, SQL_CLOSE); + CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); +} + +int +main(int argc, char **argv) +{ + int rc; + HSTMT hstmt = SQL_NULL_HSTMT; + char param1[8] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + char param2[100]; + int i; + + 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); + } + + do_test(hstmt, 101, sizeof(param1), param1); + + for (i = 0; i < sizeof(param2); i++) + { + param2[i] = i % 200; + } + do_test(hstmt, 102, sizeof(param2), param2); + + /* Clean up */ + test_disconnect(); + + return 0; +} diff --git a/test/tests b/test/tests index e908771..eff409f 100644 --- a/test/tests +++ b/test/tests @@ -8,6 +8,7 @@ # to each name in a list, but it's easy to strip them away. TESTBINS = src/connect-test \ + src/large-object-data-at-exec-test \ src/stmthandles-test \ src/select-test \ src/update-test \ --------------050208090006020309050009 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 --------------050208090006020309050009--