pg.ddx.io pgsql-odbc@postgresql.org mailing list archivehelp / color / mirror / Atom feed
From: Nils Gösche <cartan@cartan.de> To: 'Heikki Linnakangas' <hlinnakangas@vmware.com> Cc: pgsql-odbc@postgresql.org Subject: Re: Null Characters in Strings, Version 9.3.1 Date: Wed, 19 Feb 2014 00:28:12 +0100 Message-ID: <004401cf2d01$17dcb070$47961150$@cartan.de> (raw) List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-odbc> Heikki wrote: > I'm afraid I can't easily compile and execute that either, with all the Windows-ism's in it. Could you pick one of the regression test cases (e.g http://git.postgresql.org/gitweb/?p=psqlodbc.git;a=blob_plain;f=test/src/sel ect-test.c;hb=HEAD), > and modify it to reproduce the problem? And please also include the SQL statements to create the test table and data. Ok, I included a little create script, and modified one of the regression test files to fetch a single text value as WCHAR from a single row of data. The resulting program is reasonably simple. The end of the output with version 9.2.1 of the driver looks like this: $computedZiffer = 10 - ($sum % 10) if ($computedZiffer -eq $pruefZiffer) { $ret = $true } } $ret strlen = 487 sqlLen = 974 disconnecting Press ENTER to exit... And here it is with 9.3.1: $computedZiffer = 10 - ($sum % 10) if ($computedZiffer -eq $pruefZiffer) { $ret = $true } } $ret strlen = 459 sqlLen = 974 disconnecting Press ENTER to exit... strlen is different in both cases, but sqlLen is the same. I modified the program to output the received SQL_C_WCHAR value in binary (preceded by a UTF16 BOM). The two result files are attached (value921.txt and value931.txt). If you look at them in a hex editor, you will notice that the 9.2.1 version contains some Ctrl-M characters! Apparently, these have been stripped in the 9.3.1 version, but the sqlLen value is still the same. I suppose that .NET uses the latter value to determine how many characters to include in its query result string (null characters are perfectly normal characters in C# strings). Regards, -- Nils Gösche Don’t ask for whom the <Ctrl-G> tolls. -- Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-odbc Attachments: Create.sql (application/octet-stream, 596B) downloadCODBCSimple.c (text/plain, 1.5K) download
#include <stdio.h> #include <stdlib.h> #include "common.h" void write_output(const unsigned char *buf, int count) { FILE *fs = fopen("value.txt", "wb"); if (fs == NULL) { fprintf(stderr, "fopen failed: %s\n", strerror(errno)); } else { unsigned char bom[2] = { 0xFF, 0xFE }; fwrite(bom, 1, 2, fs); fwrite(buf, 1, count, fs); fclose(fs); } } int main(int argc, char **argv) { SQLRETURN rc; SQLLEN sqlLen; HSTMT hstmt = SQL_NULL_HSTMT; char *sql; char buf[8192]; wchar_t wbuf[8192]; test_connect(); rc = SQLAllocStmt(conn, &hstmt); if (!SQL_SUCCEEDED(rc)) { print_diag("failed to allocate stmt handle", SQL_HANDLE_DBC, conn); exit(1); } /* Run a query with a result set with all kinds of values */ sql = "SELECT body FROM macros WHERE name = 'check_pruefziffer'"; rc = SQLExecDirect(hstmt, (SQLCHAR *)sql, SQL_NTS); CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt); /* Fetch result */ rc = SQLFetch(hstmt); CHECK_STMT_RESULT(rc, "SQLFetch failed", hstmt); rc = SQLGetData(hstmt, 1, SQL_C_WCHAR, wbuf, sizeof(wbuf), &sqlLen); CHECK_STMT_RESULT(rc, "SQLGetData failed", hstmt); wprintf(L"varcharcol: %s\n", wbuf); printf("strlen = %u\n", wcslen(wbuf)); printf("sqlLen = %d\n", sqlLen); write_output((unsigned char *) wbuf, sqlLen); rc = SQLFreeStmt(hstmt, SQL_CLOSE); CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); /* Clean up */ test_disconnect(); puts("Press ENTER to exit..."); fgets(buf, sizeof buf, stdin); return 0; }value921.txt (text/plain, 976B) download
ÿþP a r a m ( [ p a r a m e t e r ( M a n d a t o r y = $ t r u e , H e l p M e s s a g e = "