pg.ddx.io  pgsql-odbc@postgresql.org mailing list archive  
help / 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) download

CODBCSimple.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 ÿþParam ( [parameter(Mandatory=$true, HelpMessage="The barcode value")] [string]$bc ) $ret = $false if ($bc.Length -gt 1) { $pruefZiffer = $bc[$bc.Length - 1] - 48 $sum = 0 $len = $bc.Length - 1 for ($i = 0; $i -lt $len; $i++) { $dig = $bc[$i] - 48 if ($i % 2 -eq 0) { $sum += 3 * $dig } else { $sum += $dig } } $computedZiffer = 10 - ($sum % 10) if ($computedZiffer -eq $pruefZiffer) { $ret = $true } } $ret
value931.txt (text/plain, 976B) download ÿþParam ( [parameter(Mandatory=$true, HelpMessage="The barcode value")] [string]$bc ) $ret = $false if ($bc.Length -gt 1) { $pruefZiffer = $bc[$bc.Length - 1] - 48 $sum = 0 $len = $bc.Length - 1 for ($i = 0; $i -lt $len; $i++) { $dig = $bc[$i] - 48 if ($i % 2 -eq 0) { $sum += 3 * $dig } else { $sum += $dig } } $computedZiffer = 10 - ($sum % 10) if ($computedZiffer -eq $pruefZiffer) { $ret = $true } } $ret) { $ret = $true } } $ret

view thread (15+ messages)  latest in thread

Message-ID: <004401cf2d01$17dcb070$47961150$@cartan.de>
Permalink:  ../004401cf2d01$17dcb070$47961150$@cartan.de/
Also on:    postgresql.org/message-id/004401cf2d01$17dcb070$47961150$@cartan.de

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-odbc@postgresql.org
  Cc: cartan@cartan.de, hlinnakangas@vmware.com
  Subject: Re: Null Characters in Strings, Version 9.3.1
  In-Reply-To: <004401cf2d01$17dcb070$47961150$@cartan.de>
  References: <004401cf2d01$17dcb070$47961150$@cartan.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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