Hiroshi Inoue [Mon, 23 Nov 2015 23:09:04 +0000 (08:09 +0900)]
It's not good to pass path name of files in system folder to candle.exe because the file redirection may occur. Instead we specify system folder's name at .wxs.
Hiroshi Inoue [Sat, 21 Nov 2015 00:43:53 +0000 (09:43 +0900)]
Remove useless statements.
Hiroshi Inoue [Sat, 14 Nov 2015 04:19:05 +0000 (13:19 +0900)]
If libpq needs different version of MSVC runtime from that psqlodbc
needs, install it also.
Hiroshi Inoue [Fri, 13 Nov 2015 12:49:15 +0000 (21:49 +0900)]
Improve the way to intall libpq related modules.
Instead of describing fixed items in a .wxs file, automatically detect
what modules to be installed.
Heikki Linnakangas [Mon, 9 Nov 2015 14:03:47 +0000 (16:03 +0200)]
Improve parsing of INSERT INTO statements to support @@identity
Patch by Christian Ullrich, some extra comments and regression test by me.
Heikki Linnakangas [Mon, 9 Nov 2015 13:27:08 +0000 (15:27 +0200)]
Set an error message when password is required to connect.
In previous versions, if a connection fails because the server requires a
password and no password was supplied, you got a "fe_sendauth: no password
supplied" message from SQLGetDiagField(). That got lost at some point, so
put it back, as "Password required".
Per report from "PSequel Support".
Heikki Linnakangas [Wed, 23 Sep 2015 07:14:10 +0000 (10:14 +0300)]
Remove obsolete references to pg_regress from README.txt.
The regression tests no longer use pg_regress, since commit
2002b71d.
Heikki Linnakangas [Tue, 22 Sep 2015 12:36:02 +0000 (15:36 +0300)]
Fix buffer overrun in constructing error message.
If the server returned an error longer than 4096 bytes, we would overrun
the buffer by two bytes. If you're unlucky, that could lead to a crash,
and it consistently did on Windows.
Per report from Andrus Moor.
Heikki Linnakangas [Fri, 26 Jun 2015 15:49:56 +0000 (18:49 +0300)]
Fix autoconf test for whether SQLColAttribute's argument is SQLLEN *.
There was a spurious < character, which made it fail with some compilers.
While we're at it, reformat, add a "checking for" message for that test,
make it a bit more robust by defining the function's body and using the
pointer too.
Per report from Mark Hellegers
Heikki Linnakangas [Tue, 23 Jun 2015 13:48:31 +0000 (16:48 +0300)]
Release critical section if SQLAllocHandle() fails.
Heikki Linnakangas [Wed, 6 May 2015 23:19:45 +0000 (02:19 +0300)]
Don't define strlcat prototype if the system has strlcat()
The #ifdef was wrong.
Hopefully this fixes the build failure on OS X Maverick that Alex Dunn
reported.
Heikki Linnakangas [Wed, 6 May 2015 22:47:23 +0000 (01:47 +0300)]
Silence compiler warning about unused variable
Heikki Linnakangas [Thu, 9 Apr 2015 18:52:19 +0000 (21:52 +0300)]
Fix description of error in comments.
I misunderstood the search_path and current_schema() issue.
current_schema() works fine if search_path contains more than one element.
It just returns the first one in that case. However, I set the search_path
to an invalid value, which just happened to look valid.
Heikki Linnakangas [Thu, 9 Apr 2015 18:46:45 +0000 (21:46 +0300)]
Fix segfault when "SELECT current_schema()" returns NULL.
current_schema() can be NULL, for example if search_path contains more
than one schema. CC_get_current_schema() segfaulted on that. Also fix all
the callers to expect that CC_get_current_schema() can return NULL.
Per report from Frank van der Aa.
Heikki Linnakangas [Wed, 25 Feb 2015 09:17:44 +0000 (11:17 +0200)]
Initialize parameter type of NULL parameters correctly.
When building the arrays of parameter types, formats, etc. for sending to
the server with PQexecParams(), the parameter types for NULL parameters
were not set. This caused "cache lookup failed for type XXX" errors.
Add test case for SQLBindParameter with NULL params.
Heikki Linnakangas [Fri, 6 Feb 2015 15:39:53 +0000 (17:39 +0200)]
Fix regression test to use correct CHECK macro
Heikki Linnakangas [Mon, 2 Feb 2015 22:41:48 +0000 (00:41 +0200)]
Fix typo in connection string used in regression test.
Heikki Linnakangas [Mon, 2 Feb 2015 22:15:10 +0000 (00:15 +0200)]
Fix minor memory leaks.
Per Coverity warnings.
Heikki Linnakangas [Mon, 2 Feb 2015 20:46:30 +0000 (22:46 +0200)]
Remove dead code in ColAttSet.
This is dead code because the caller of ColAttSet never passes 'rti' as
NULL.
Spotted by Coverity. Patch by Michael Paquier.
Heikki Linnakangas [Mon, 2 Feb 2015 20:44:37 +0000 (22:44 +0200)]
Remove dead code
Spotted by Coverity. Patch by Michael Paquier.
Heikki Linnakangas [Mon, 2 Feb 2015 20:31:11 +0000 (22:31 +0200)]
Remove dead code.
Pointed out by Coverity as 13523.
Michael Paquier
Heikki Linnakangas [Mon, 2 Feb 2015 20:25:48 +0000 (22:25 +0200)]
Remove some dead code.
gpps.h was removed back in 2004.
Heikki Linnakangas [Mon, 26 Jan 2015 07:01:29 +0000 (09:01 +0200)]
Refactor regression tests to use a custom program instead of pg_regress.
Using pg_regress was awkward, because it used a dummy .sql file for each
test that just launched the test program. Also, it added a dependency;
the driver doesn't require PostgreSQL sources to build, just libpq
headers, but the pgxs program is not usually shipped with libpq headers.
The new "runsuite" program runs all the test programs given on the command
line, compares the results with the expected output, and produces
TAP-compatible output. It can be run stand-alone, as the TAP output is
human-readable, or with the perl 'prove' program which gives more pretty
output.
Heikki Linnakangas [Mon, 2 Feb 2015 18:30:50 +0000 (20:30 +0200)]
Use _MSC_VER to check for existence of isinf/isnan.
Let's use this variant of the check that's also used in the main PostgreSQL
sources. It has been shown to work, so should be more robust.
Per suggestions from Michael Paquier and Tom Lane.
Heikki Linnakangas [Thu, 29 Jan 2015 12:48:46 +0000 (14:48 +0200)]
A better fix for isnan() and isinf() on Windows.
Newer versions of Visual Studio actually have isnan() and isinf() macros.
Silence compiler warnings about redefining them.
Heikki Linnakangas [Thu, 29 Jan 2015 12:35:28 +0000 (14:35 +0200)]
Fix typo in README.
Michael Paquier
Heikki Linnakangas [Thu, 29 Jan 2015 12:29:40 +0000 (14:29 +0200)]
Fix crash when a query is described, without binding params.
Add test case for the same.
Heikki Linnakangas [Thu, 29 Jan 2015 12:14:38 +0000 (14:14 +0200)]
Don't do premature execution.
Use protocol v3 Parse instead, even in UseServerSidePrepare=0 mode.
Remove the DisallowPremature config option.
Heikki Linnakangas [Thu, 29 Jan 2015 11:32:54 +0000 (13:32 +0200)]
Fix building on Windows systems without isinf()/isnan().
Michael Paquier
Heikki Linnakangas [Wed, 28 Jan 2015 17:46:10 +0000 (19:46 +0200)]
Remove unused variable.
Left over from the switch to PQconnectdbParams.
Heikki Linnakangas [Wed, 28 Jan 2015 14:36:45 +0000 (16:36 +0200)]
Cleanup after test, to silence Valgrind warnings about leaked memory.
Heikki Linnakangas [Wed, 28 Jan 2015 14:16:50 +0000 (16:16 +0200)]
Use PQconnectdbParams for connecting.
This makes it unnecessary to build a connection string, which was broken
anyway. (Try connecting with a username that contains a single quote and
a space).
Heikki Linnakangas [Wed, 28 Jan 2015 14:04:12 +0000 (16:04 +0200)]
Simplify the way the connection string is built.
Heikki Linnakangas [Wed, 28 Jan 2015 12:56:57 +0000 (14:56 +0200)]
Silence Coverity warning about unsafe use of strcpy
We know that pg_attribute.attnum value is an integer that fits in 16 bytes,
but Coverity doesn't. And of course it's nicer to not crash if the backend
is crazy and returns garbage..
Heikki Linnakangas [Wed, 28 Jan 2015 12:47:03 +0000 (14:47 +0200)]
Use fixed-width fields for SQLState values.
I'm hoping that this silences a Coverity warning, making it realize that
none of the strings in the array are longer than 5 bytes.
Heikki Linnakangas [Wed, 28 Jan 2015 12:34:54 +0000 (14:34 +0200)]
Silence Coverity warnings about derefencing NULL pointer.
Heikki Linnakangas [Wed, 28 Jan 2015 12:15:32 +0000 (14:15 +0200)]
Fix parsing of escaped quotes.
The driver-side SQL parsing code didn't recognize quotes and double-quotes
escaped by doubling them correctly. Also add a test case that fails without
this fix.
Heikki Linnakangas [Wed, 28 Jan 2015 11:21:54 +0000 (13:21 +0200)]
Disable LF <-> LF+CR conversion in the param-conversions test.
This silences a silly regression failure on Windows. There is a separate
test for LFConversion, so let's just rely on that.
Heikki Linnakangas [Tue, 27 Jan 2015 18:26:05 +0000 (20:26 +0200)]
Make boolsaschar test case insensitive to whether text maps to CHAR or WCHAR.
There's no need to print the type of the text column, it's not what
boolsaschar test case is testing.
This fixes regression failure on Windows with Unicode driver.
Heikki Linnakangas [Tue, 27 Jan 2015 17:57:11 +0000 (19:57 +0200)]
Use a larger buffer for error message.
This allows us to get a large NOTICE message. The driver limitation that the
comment in notice-test.c talks about has been lifted, remove comment.
Heikki Linnakangas [Tue, 27 Jan 2015 16:59:31 +0000 (18:59 +0200)]
Remove unneeded tests from configure script.
Heikki Linnakangas [Tue, 27 Jan 2015 16:40:55 +0000 (18:40 +0200)]
Teach deprecated-test regression test about keyset-type cursors.
Also use SQL_CURSOR_TYPE instead of SQL_ATTR_CURSOR_TYPE in the
SQLSetStmtOption calls. Although they both have the same value,
SQL_CURSOR_TYPE is what it used to be called back when SQLSetStmtOption
was not deprecated yet, so that's what a genuinely old application would
use.
Heikki Linnakangas [Tue, 27 Jan 2015 15:38:57 +0000 (17:38 +0200)]
The printf() output format of infinite/nan doubles varies across platforms.
Notably, it's different on Windows. Check for infinite/nan values explicitly
in the regression test, to avoid platform-dependent output.
Heikki Linnakangas [Tue, 27 Jan 2015 14:18:10 +0000 (16:18 +0200)]
Windows _snprintf is not a drop-in replacement for POSIX snprintf()
It handles truncation differently. Witnessed by failures in the
result-conversions regression test on Windows. Create a shim function that
uses _snprintf() to implement the POSIX truncation behavior (as long as you
don't run out of memory...)
Heikki Linnakangas [Tue, 27 Jan 2015 12:21:14 +0000 (14:21 +0200)]
Use correct handle when getting error message in regression test.
I hadn't noticed that the error message on procedure call didn't complain
about the invalid function. Also, on Windows, apparently the error message
isn't automatically copied from statement to connection handle, because
I got a diff.
Heikki Linnakangas [Tue, 27 Jan 2015 12:17:27 +0000 (14:17 +0200)]
Teach SQLDriverConnect that Port is no longer required.
This caused SQLDriverConnect to unnecessarily fail or open a connection
options dialog if no Port was specified.
Heikki Linnakangas [Mon, 26 Jan 2015 16:36:49 +0000 (18:36 +0200)]
Remove dead code.
Also move some stuff that's not used elsewhere into multibyte.c
Heikki Linnakangas [Mon, 26 Jan 2015 16:30:59 +0000 (18:30 +0200)]
Remove dead NULL-check.
Per Coverity warning, res-keyset is accessed earlier, so can't be NULL.
Heikki Linnakangas [Mon, 26 Jan 2015 16:25:39 +0000 (18:25 +0200)]
Don't crash on NULL result from CC_send_query
Per Coverity warning. There are probably dozens more cases like this that
it doesn't happen to warn aboute, but let's reduce the noise anyway.
Heikki Linnakangas [Mon, 26 Jan 2015 16:20:43 +0000 (18:20 +0200)]
Fix memory overrun bug with large keyset-driven result sets.
The address passed to memset() was bogus, resulting in clobbering random
piece of memory.
Found by Coverity. Add a somewhat contrived test case for this too.
Heikki Linnakangas [Mon, 26 Jan 2015 15:53:12 +0000 (17:53 +0200)]
Remove a few more unnecessary NULL-checks.
The only caller to QR_next_tuple always passed non-NULL.
Heikki Linnakangas [Mon, 26 Jan 2015 15:49:09 +0000 (17:49 +0200)]
Remove unnecessary null-check.
Per Coverity warning.
Heikki Linnakangas [Mon, 26 Jan 2015 07:49:00 +0000 (09:49 +0200)]
loadlib.c is only needed on Windows.
Heikki Linnakangas [Mon, 26 Jan 2015 07:30:01 +0000 (09:30 +0200)]
Remove dead function.
Heikki Linnakangas [Mon, 26 Jan 2015 06:57:09 +0000 (08:57 +0200)]
Use test -x rather than test -f to check the [i]odbc_config program.
I copied the odbc_config_dummy version from the Debian system, but forgot
to make the script executable. Configure failed, but it didn't complain
about odbc_config, but it claimed that "libpq-fe.h" could not be found.
Turns out that it tried to execute odbc_config --include-prefix, which
failed, leaving the variable empty. In subsequent tests, it ran gcc like
"gcc -I -I/usr/include/postgresql". With this fix, you'll get an error
about odbc_config.
Heikki Linnakangas [Fri, 23 Jan 2015 19:27:57 +0000 (21:27 +0200)]
Fix miscellaneous little issues spotted by Coverity.
A few were real bugs, although highly unlikely ones. Others were false
positives like dead code, but let's be tidy.
Heikki Linnakangas [Fri, 23 Jan 2015 18:01:01 +0000 (20:01 +0200)]
Remove unnecessary argument from schema_strcat1 and my_strcat1.
The length was always passed as SQL_NTS.
Heikki Linnakangas [Fri, 23 Jan 2015 17:04:21 +0000 (19:04 +0200)]
Fix test case to work with standards_conforming_strings=off.
Heikki Linnakangas [Fri, 23 Jan 2015 16:54:31 +0000 (18:54 +0200)]
With standards_conforming_strings=off, one \ in LIKE pattern becomes four.
You could get a segfault if the pattern contained a lot of \ characters.
Add test case for the bug.
Heikki Linnakangas [Fri, 23 Jan 2015 15:40:34 +0000 (17:40 +0200)]
Check return values of a few function calls.
While we're at it, fix spelling of the error messages.
Clang static analyzer complained.
Heikki Linnakangas [Fri, 23 Jan 2015 14:41:15 +0000 (16:41 +0200)]
Silence a few harmless warnings that clang static analyzer gave.
Heikki Linnakangas [Fri, 23 Jan 2015 14:27:18 +0000 (16:27 +0200)]
Fix bug in detection of E'' literals.
The code assigned to escape_in_literal local variable when it saw a quote
characeter after E. And checked the local variable on subsequent iterations.
But the function is called separately for each processed characters, so the
local variable was reset between each call. Move the flag to the QueryParse
struct so that it survives across calls.
Expand the 'quotes' test case to cover this.
Clang Static Analyzer warned that the escape_in_literal variable was set
but not used, which lead me into looking at this more closely.
Heikki Linnakangas [Fri, 23 Jan 2015 13:15:20 +0000 (15:15 +0200)]
Correctly set returned value to an empty string in "cvt_null_date" mode.
Spotted by clang compiler warning. Also add test case for this.
Heikki Linnakangas [Fri, 23 Jan 2015 12:47:25 +0000 (14:47 +0200)]
Refactor and add comments for the modes ResolveOneParam can operate in.
ResolveOneParam can work in four different modes that are mutually
exclusive. Put the mode in an enum field in the QueryBuild struct,
separately from the additional flags that can be set. Add comments to
explain what each mode does.
Refactor the way CVT_SPECIAL_CHARS works with the query buffer along the
way. It was always a bit awkward, but with this refactoring it would've
become more so, as the mode would've needed to be another argument to it.
Heikki Linnakangas [Thu, 22 Jan 2015 20:04:58 +0000 (22:04 +0200)]
More miscellaneous cleanup.
* Simplify the way the ignore-round-trip-time config option works. (No need
for the caller of CC_send_query_append to pass it as argument,
CC_send_query_append can look at the options in the connection object
itself)
* remove unnecessary local variable used for "fetch" constant.
* remove unused FLGP_BUILDING_PREPARE_STATEMENT flag.
* remove unused parameter, and check for stmt==NULL, from QB_Initialize.
* inline process_statements function into its only caller.
Heikki Linnakangas [Thu, 22 Jan 2015 17:44:59 +0000 (19:44 +0200)]
Miscellaneous cleanup.
* Mark functions used only in same file as static.
* Remove unused 'encoding' argument from msgtowstr and wstrtoms (all
callers passed NULL).
* Silence remaining compiler warnings on 64-bit Windows about assigning
size_t to int without cast.
* Remove superfluous FORMAT_INT4/FORMAT_UINT4 defines.
* Remove useless dollar_quote argument from findTag (it was always '$'), and
add comment.
* Turn OID_NAME into a #define, to avoid a useless sprintf.
* Turn the mapFuncs array into structs, for clarity, and add comment.
Heikki Linnakangas [Thu, 22 Jan 2015 17:37:20 +0000 (19:37 +0200)]
Remove "Cancel as FreeStmt" from docs, too.
Heikki Linnakangas [Thu, 22 Jan 2015 17:26:27 +0000 (19:26 +0200)]
Check for PQsetSingleRowMode function in configure test.
We require libpq 9.2 (or newer), where PQsetSingleRowMode was added. Check
for that in configure, so that you get a nice error message if you try
build with anything older.
Heikki Linnakangas [Thu, 22 Jan 2015 13:42:38 +0000 (15:42 +0200)]
Add expected output for running on a database initialized with C locale.
Heikki Linnakangas [Thu, 22 Jan 2015 13:27:17 +0000 (15:27 +0200)]
Remove default for Port attribute.
The default is to use whatever the libpq's default is. Makes no difference
under normal circumstances, as 5432 is the libpq default too, but it can
be changed if you make a custom build of libpq.
While at it, fix a typo in error message.
Heikki Linnakangas [Thu, 22 Jan 2015 11:51:11 +0000 (13:51 +0200)]
Don't put default Servername and Port in the odbc.ini file.
This way, the driver will pick up the defaults from the libpq environment
variables, which makes more sense as we rely on those for the 'sampletables'
test case anyway.
Heikki Linnakangas [Thu, 22 Jan 2015 07:17:04 +0000 (09:17 +0200)]
Expand colattributes test case a bit.
Test SQL_DESC_TYPE_NAME. There was an old report in the pgfoundry bug
tracker that it didn't work correctly with interval types, (#
1010745, from
Farid Zidan on 2009-12-30), but it seems to work now.
Heikki Linnakangas [Wed, 21 Jan 2015 20:04:33 +0000 (22:04 +0200)]
Improve print_diag() regression test helper to print all diagnostic records.
Previously, it only printed the first record. This is academic at the
moment, as the driver never reports more than one record AFAICS, but let's
be prepared.
Heikki Linnakangas [Wed, 21 Jan 2015 20:01:16 +0000 (22:01 +0200)]
Silence regression failure of diagnostic test.
Now that I fixed the bug in the error handler, we're not losing the libpq's
message about lost connect anymore. It overwrites the previous FATAL error,
which is unfortunate, but it's been long-standing behaviour that if multiple
errors are returned as result for a query, only the last one is kept.
Heikki Linnakangas [Wed, 21 Jan 2015 17:59:54 +0000 (19:59 +0200)]
Fix references to uninitialized memory.
Some variables that were supposed to be set by sscanf() were accessed before
checking the return value of sscanf().
Spotted by valgrind on the result-conversions regression test.
Heikki Linnakangas [Wed, 21 Jan 2015 17:49:19 +0000 (19:49 +0200)]
Fix uninitialized memory access.
Introduced by the big libpq patch. Before that, the keyset array was
allocated - and zeroed - in another function.
Spotted by Valgrind.
Heikki Linnakangas [Wed, 21 Jan 2015 17:00:10 +0000 (19:00 +0200)]
Fix reference to free'd plan name.
libpq_bind_and_exec fetched a pointer to the statement's plan name to a
local variable, but then called prepareParameters which free'd it, and
allocated a new plan name. The already-free'd name was then passed to
PQexecParams().
Spotted by valgrind
Heikki Linnakangas [Wed, 21 Jan 2015 16:44:52 +0000 (18:44 +0200)]
Fix read-after-free bug in error handler.
If a connection dies, CC_on_abort() calls PQfinish() which frees the error
message. handle_pgres_error better deal with the error message before
calling CC_on_abort().
Spotted by valgrind, on the "diagnostic" regression test.
Heikki Linnakangas [Wed, 21 Jan 2015 16:43:09 +0000 (18:43 +0200)]
Fix bug in determining the datatypes when binding.
In the big libpq patch, I accidentally removed the line where
current_exec_param was reset to 0. It's still required (which is a very
fiddly way to pass that value to ParseAndDescribeWithLibpq, but let's live
with it for now..)
Heikki Linnakangas [Wed, 21 Jan 2015 15:36:30 +0000 (17:36 +0200)]
Minor cleanup.
Remove local variable that was never used for anything real (just passed as
NULL to mylog/qlog). Replace with real query in the logs, and add some extra
logging.
Heikki Linnakangas [Tue, 20 Jan 2015 22:00:49 +0000 (00:00 +0200)]
Remove unused arguments.
Heikki Linnakangas [Tue, 20 Jan 2015 21:05:25 +0000 (23:05 +0200)]
Mark functions that are not used outside convert.c as static. Remove dead code.
Heikki Linnakangas [Tue, 20 Jan 2015 20:57:39 +0000 (22:57 +0200)]
Add test cases for conversions from string to date/time/timestamps.
Also improve a comment.
Heikki Linnakangas [Tue, 20 Jan 2015 11:18:20 +0000 (13:18 +0200)]
Add a few tests for conversions between binary and text.
Just noticed that it was not tested.
Heikki Linnakangas [Mon, 19 Jan 2015 21:29:59 +0000 (23:29 +0200)]
Remove long-since obsolete FAR/NEAR decorations from pointers.
We haven't supported a segmented memory model for ages, probably never.
Heikki Linnakangas [Mon, 19 Jan 2015 20:54:00 +0000 (22:54 +0200)]
Misc cleanup, mostly dead code removal.
Heikki Linnakangas [Mon, 19 Jan 2015 20:42:01 +0000 (22:42 +0200)]
Don't insist that Server, Username and Database options are set.
Libpq will use sensible defaults if they are not set. In particular, it's
very useful that if you don't specify a Server, on Unix systems we will now
try to connect to a local installation via Unix domain sockets. That was
difficult to configure otherwise.
Heikki Linnakangas [Sun, 18 Jan 2015 20:13:02 +0000 (22:13 +0200)]
Remove obsolete CancelAsFreeStmt option.
It became obsolete when support for ODBC versions < 3.51 was removed, as
it never did anything in 3.51 version.
Heikki Linnakangas [Sun, 18 Jan 2015 17:41:02 +0000 (19:41 +0200)]
Change URL to FAQ to point to new domain, odbc.postgresql.org.
Heikki Linnakangas [Fri, 16 Jan 2015 21:25:48 +0000 (23:25 +0200)]
The project's website was moved to odbc.postgresql.org.
Change links in the readmes accordingly.
Heikki Linnakangas [Fri, 16 Jan 2015 21:18:47 +0000 (23:18 +0200)]
Send proper datatypes to the server when binding parameters.
We used to always send 0 as the parameter type, which means that the server
should deduce the datatype from the context. That usually works well, but
we can do better. Sometimes there is ambiguity, like in "SELECT '555' > ?".
If the parameter is bound as a string, '6' would return true, but if it's
bound as an integer, it returns false.
When the application calls SQLBindParameter, it specifies the datatype, so
we should make use of that.
Add a test case for the "SELECT '555' > ?" case.
Heikki Linnakangas [Fri, 16 Jan 2015 21:12:53 +0000 (23:12 +0200)]
More fixes to building query with SQL_INTEGER and SQL_SMALLINT params.
Jeremy Faith pointed out that the code still incorrectly accepted '-' as
a valid integer. But a bigger issue with negative numbers is that even a
valid negative integer can lead to bogus queries. Consider "SELECT 0-?",
where the parameter is -123. It was expanded to "SELECT 0--123".
To fix, don't accept '-' as a valid integer, forcing it to be quoted. And
if the value is negative, put parens around it, so that the previous
example becomes "SELECT 0-(-123)".
Add test cases for these issues. While we're at it, improve the output of
the param-conversions-test to be more readable.
Heikki Linnakangas [Thu, 15 Jan 2015 16:41:01 +0000 (18:41 +0200)]
Fix passing username to the server.
In commit
e85fbb2, as part of removing non-libpq code, I removed the code
that determined the username of the currently logged-in user, and send it
to the server during authentication. However, I accidentally also removed
the code that passed any explicitly-given username to the server. Oops.
Heikki Linnakangas [Thu, 15 Jan 2015 09:04:33 +0000 (11:04 +0200)]
Silence compiler warnings on 64-bit Windows build.
Be more careful about using size_t with variables that count offsets or
lengths of strings. In theory, a string longer than 2^31 could overflow an
int. I'm not sure if such a string can occur in practice, but let's be
tidy.
Heikki Linnakangas [Thu, 15 Jan 2015 08:59:39 +0000 (10:59 +0200)]
Fix Windows build.
In the previous commit, I missed a reference to the autocommit_public
field that was inside an #ifdef _HANDLE_ENLIST_IN_DTC_ section.
Heikki Linnakangas [Thu, 15 Jan 2015 08:30:52 +0000 (10:30 +0200)]
Don't reset autocommit attribute at SQLDriverConnect.
It should be possible to call SQLSetConnectAttr to disable autocommit
before establishing a connection. It was incorrectly reset when the
per-datasource options were read. To fix, move autocommit_public flag from
ConnInfo struct to Connection, like we've always done with login_timeout.
Also add a test case.
Reported by Ivan Zhang
Heikki Linnakangas [Wed, 14 Jan 2015 16:19:11 +0000 (18:19 +0200)]
Silence compiler warnings about variables being used uninitialized.
Heikki Linnakangas [Tue, 13 Jan 2015 21:29:48 +0000 (23:29 +0200)]
Fix various quoting issues in sending query parameters to server.
The code used to just assume that if the parameter's SQL type is SQL_INTEGER
or SQL_SMALLINT, it doesn't need quoting. While that's true for valid
integers values, there were no safeguards that the bound string is actually
valid input. The server will just throw an error on invalid input, but we
need to quote it correctly to send it to the server in the first place.
For example, if the string "123, 'inject'" is bound to an SQL_INTEGER param,
we need to quote it or the server will interpret it as part of the query.
Also add a test case for this.
Reported by Jeremy Faith.
Heikki Linnakangas [Tue, 13 Jan 2015 19:48:29 +0000 (21:48 +0200)]
Minor cleanup of the way binary parameter format is chosen.
Rather than have the caller guess whether ResolveOneParam chooses to use
the binary format, add an explicit return value for it.
Heikki Linnakangas [Tue, 6 Jan 2015 09:36:57 +0000 (11:36 +0200)]
Fix building with MSDTC=no.