Commit Graph

177 Commits

Author SHA1 Message Date
Evan Miller
e655cba907 Fix handling of numeric types in ODBC driver
Fixes #255 and supersedes #256
2021-02-15 19:50:15 -05:00
Evan Miller
f1eac042b5 Fix misuse of "%*s" in sprintf strings
%*s takes the output length, not the input length. The intended
specifier was %.*s in several places. Bug(s) introduced in
2bb31f05ee
2021-01-21 18:27:20 -05:00
Evan Miller
70c1b66278 Use correct bind types for SQLBindCol / SQLFetch (#242)
SQLFetch / SQLExtendedFetch now skip the mdb_sql machinery and use
SQLGetData on their bound columns instead. We rely on mdb_fetch_row
to skip to the correct page without any bindings and then SQLGetData will
do the rest.

SQLFetch will now correctly return SQL_SUCCESS_WITH_INFO if one or more
 bound columns have their data truncated, and will return several kinds of errors
(provided by SQLGetData) that were previously ignored.

Updated the unit test with a SQL_C_LONG type for demonstration purposes.

Fixes #23
2021-01-20 09:00:48 -05:00
pedromorgan
da730d3696 apidocs with doxygen 2021-01-16 16:05:28 +00:00
Evan Miller
c31daeb2c4 Improved bounds and return value checking (oss-fuzz/29329) 2021-01-07 19:59:45 -05:00
Evan Miller
e6a09b8bd5 Report SQLAllocEnv error in ODBC unit test 2020-12-29 09:25:55 -05:00
Evan Miller
538711e450 Remove unnecessary casts 2020-12-28 22:30:20 -05:00
Evan Miller
e1e5d9738e Use thread-local storage in ODBC connector
Fix possible race condition with multiple connections in the same
process
2020-12-28 22:01:36 -05:00
Evan Miller
2bb31f05ee Improve bounds checking
No particular crashes, but replace strcpy / strncpy with snprintf
and GLib functions wherever possible.
2020-12-28 20:12:39 -05:00
Evan Miller
16d249748a Fix integer overflow
See oss-fuzz/28790
2020-12-18 11:22:52 -05:00
Evan Miller
1efe8fc709 Merge pull request #194 from evanmiller/bounds-check-mdb-sql-bind-column
[Updated] Bounds check mdb_sql_bind_column()
2020-11-14 08:16:53 -05:00
Evan Miller
bbc53dfade Bounds check mdb_sql_bind_column()
Return -1 if the bounds check fails, otherwise the result of
mdb_bind_column_by_name.

Update other places in the code to check the return value.
2020-11-08 08:50:17 -05:00
James Woodcock
06868e58ae Don't include length of '\0' in SQLGetData pcbValue
SQLGetData() should return the length of the string without the
null terminator.
2020-10-24 09:47:10 +01:00
Evan Miller
d8ed91bb05 Include missing header files in make dist 2020-10-18 07:59:45 -04:00
Evan Miller
7f7761e884 Improved support for "Short Date" fields
* Separate -D (date only) and -T (date/time) format options in mdb-export and mdb-json

* New public mdb_set_shortdate_fmt() function in libmdb

* New private(ish) mdb_col_is_shortdate() function

I'm calling it "shortdate" in order to preserve the existing API.

See https://github.com/mdbtools/mdbtools/issues/12
2020-09-02 22:14:57 -04:00
Evan Miller
4b177914ee Move test data to separate repository 2020-09-02 10:44:12 -04:00
Evan Miller
cea7553e00 Export fakeglib symbols from main library 2020-08-31 13:27:08 -04:00
Nyall Dawson
ab9d17ef98 Fix read after free error 2020-08-21 09:36:01 +10:00
Nyall Dawson
d0ea8a9a86 ODBC requires dates formatted in ISO standards 2020-08-20 14:07:17 +10:00
Evan Miller
673c7700b9 Store OLE strings on the statement object
Also cut MDB_OLE out into its own code path. This removes the last of
the global / thread-local storage in the ODBC driver, I think.
2020-08-19 19:24:40 -04:00
Evan Miller
55e0d4ff07 Store sqlState separtely on ODBC env / handle / stmts
Also fix the fact that "08001" was always returned by SQLError instead
of the actual SQL state.
2020-08-19 17:34:57 -04:00
Evan Miller
00b3ab9571 Store statement and handle errors separately 2020-08-19 17:22:54 -04:00
Evan Miller
a84c07980f Make lastError thread-safe 2020-08-19 17:03:06 -04:00
Evan Miller
e67c8e6d52 Remove obsolete comment about thread safety 2020-08-19 16:32:13 -04:00
Evan Miller
3d63f16fc0 Fix errors
It helps to enable ODBC when testing ODBC :-P
2020-08-19 16:16:25 -04:00
Evan Miller
684fa55781 Fix unused variable warning 2020-08-19 15:50:57 -04:00
Evan Miller
9020ca9a1e Attempt to make the ODBC driver thread-safe
I'm not sure if this is a complete solution - some of the global state
has been moved to thread-local storage. So passing an ODBC handle across
threads may have unexpected results. But at least it's not global state.

Each ODBC handle now has its own iconv_t object.

See #23
2020-08-19 15:35:02 -04:00
Nyall Dawson
40981d2fc6 Only handle tables in SQLColumns, not other objects 2020-08-19 10:50:12 +10:00
Nyall Dawson
b72ac6b1c0 Don't crash when a table can't be read for some reason 2020-08-19 10:44:17 +10:00
Evan Miller
858e1dff49 Merge pull request #16 from nyalldawson/reentrant
Make SQL parser/lexer reentrant
2020-08-18 07:20:35 -04:00
Nyall Dawson
4e3ed3a5fd Fix LIMIT clause is ignored when executing SQL via ODBC 2020-08-18 14:54:19 +10:00
Nyall Dawson
86741f4614 More thread safety 2020-08-18 12:28:20 +10:00
Evan Miller
6171472411 Change -Bsymbolic-functions to -Wl,-Bsymbolic-functions 2020-08-14 00:12:07 -04:00
Evan Miller
dfd41f2283 Try fixing unixODBC deadlock with -Bsymbolic-functions
This flag compels the dynamic library to prefer its own function symbols
to those in the global symbol table. This behavior should let us
directly call SQL* functions from inside other SQL* functions without
fear of interference by the host program.
2020-08-13 21:52:03 -04:00
Evan Miller
cca922562f Merge pull request #13 from nyalldawson/fix_placeholder
Fix placeholder text used instead of type name in SQLGetData SQLColumns_TYPE_NAME call
2020-08-12 22:48:41 -04:00
Evan Miller
0a72c5407b Merge pull request #14 from nyalldawson/char_len
Correctly return len of character data when SQLColAttributes is called with SQL_COLUMN_TYPE_NAME
2020-08-12 22:46:52 -04:00
Nyall Dawson
3f278f3996 Correctly return len of character data when SQLColAttributes is called with SQL_COLUMN_TYPE_NAME 2020-08-13 12:40:46 +10:00
Nyall Dawson
1fc6d60dfa Fix placeholder text used instead of type name in SQLGetData SQLColumns_TYPE_NAME call 2020-08-13 12:12:57 +10:00
Nyall Dawson
8202e38155 Don't automatically add terminators when reading data parts
via SQLGetData for OLE fields

if the column type is OLE, then we don't add terminators
see https://docs.microsoft.com/en-us/sql/odbc/reference/syntax/sqlgetdata-function?view=sql-server-ver15
and https://www.ibm.com/support/knowledgecenter/SSEPEK_11.0.0/odbc/src/tpc/db2z_fngetdata.html

"The buffer that the rgbValue argument specifies contains nul-terminated values, unless you retrieve
binary data, or the SQL data type of the column is graphic (DBCS) and the C buffer type is SQL_C_CHAR."
2020-08-13 08:03:00 +10:00
Evan Miller
362938f17c ODBC build fixes
* Require SQLGetPrivateProfileString in ODBC libraries

* Attempt to fix reported deadlock with unixODBC by rearranging
functions
2020-08-12 15:05:25 -04:00
Nyall Dawson
9a749e68fd Report more accurate field type for OLE fields 2020-08-12 15:33:54 +10:00
Nyall Dawson
68d3104134 pos should finish on data length 2020-08-12 09:51:54 +10:00
Nyall Dawson
2567e57faa Fix incorrect early free of str when reading ole fields 2020-08-12 09:06:04 +10:00
Evan Miller
71e10395fd Try another SQLGetData fix
Set the length of the return value to include the NUL termination
charaacter.
2020-08-11 07:30:33 -04:00
Evan Miller
e330feebd6 Fix for variable-length fields using SQLGetData
See:

brianb/mdbtools#130
brianb/mdbtools#131
evanmiller/mdbtools#6
2020-08-10 21:38:08 -04:00
Evan Miller
02c5544c14 Syntax fix 2020-08-10 19:19:19 -04:00
Evan Miller
a712dfef65 Get rid of indirection in ODBC driver 2020-08-10 19:15:03 -04:00
Evan Miller
05b1e2229a Fix unittest exit code 2020-08-10 17:08:55 -04:00
Evan Miller
c471570d16 Fix __attribute__ syntax 2020-08-10 17:07:54 -04:00
Evan Miller
280075a3e2 Fix unused function warnings 2020-08-10 17:04:11 -04:00