Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to GetColumnValue #9

Open
wants to merge 29 commits into
base: master
Choose a base branch
from

Conversation

lee-houghton
Copy link

I've had a chance to merge the changes from 0.6.2 to 0.6.11 into my fork. I'm currently testing it myself.

There are some compatibility changes:

  • SQL_TYPE_DATE columns are handled (I don't think they were before)
  • Removed strptime.cpp on Windows - it now uses mktime and _mkgmtime32
  • SQL_BINARY columns are returned as a node Buffer object, rather than a hex-encoded string
  • SQL_BIT columns are handled using the SQL_C_BIT data type rather than converting to SQL_C_CHAR
  • The ODBCResult fetch mode can now be FETCH_NONE, which specifies that the columns will be fetched manually
  • SQL_VARCHAR and SQL_BINARY columns can be partially requested using the maxBytes parameter.

I'd like to implement sending node Buffer objects for SQL_BINARY parameters, but I haven't yet had the time.

It's not been thoroughly tested, especially on platforms other than Windows/MSSQL, so there may certainly be issues there. I don't have any other platforms set up, so I can't currently test it on those without a lot of work.

lee-houghton and others added 23 commits October 5, 2013 19:18
Still need to (a). return the value as a Buffer rather than a string (b)
support other types (c). refactor so that it is not duplicating
ODBC::GetColumnValue needlessly.
* Return Buffer for varbinary columns
* Fix SQL_T macro for compile-time string concatenation
* Fix DEBUG_PRINTF usage in ODBCConnection::Query not respecting UNICODE
flag
* Pass 3rd argument to Query callback ("more")
* Start work on GetColumnValue returning data types probably (probably
should just use ODBC::GetColumnValue somehow - needs refactoring)
* Add ODBCResult::GetColumnValueSync
Remove strptime, use SQL_TIMESTAMP_STRUCT and mktime/_mkgmtime similar
to *nix.
The Windows ODBC Driver Manager returns SQLSTATE 01S00 whereas unixODBC
returns SQLSTATE IM002.
MSSQL's datetime type has only 3 millisecond precision (datetime2
supports better precision, but is unlikely to exist elsewhere)
MSSQL requires N'☯ąčęėįšųūž☎áäàéêèóöòüßÄÖÜ€ шчябы Ⅲ ❤' but sqlite
doesn't support national character literals. Relying on default
collation being unicode-capable is also non-standard, however...
See commit #c0cbf24d5dc1ccf62314e949532acc530cbe45b0
Was printing a not-necessarily-null terminated buffer with %s.
Split into GetCColumnType, GetColumnData, and ConvertColumnValue to
allow ODBC::GetColumnValue (async) to do the data-getting on the worker
thread and the conversion in the callback on the V8 thread.
Returns a Buffer if the data type of the column is SQL_BINARY or
SQL_VARBINARY.
Converts the 'bit' data type into true/false using the SQL_C_BIT data
type rather than SQL_C_TCHAR.
Handle null terminators got from SQLGetData with SQL_C_TCHAR
Also fix exception handling in some functions
Allow fetching entire value in async mode (loops via uv_queue_work) -
refactored ODBC::GetColumnValue again to make this possible without
unduly duplicating code. Allow not passing maxBytes to
result.getColumnValue.
TODO: Fix behaviour of maxBytes for strings (should really be maxChars),
maxBytes is pretty useless for strings when you don't know if the
underlying representation is unicode or utf-8.
Caused by FetchMoreData not passing on SQL_NULL_DATA
Conflicts:
	src/odbc.cpp - preferred my changes over upstream (since I have refactored GetColumnValue)
	src/odbc.h - reverted my changes to DEBUG_PRINTF
	src/odbc_result.cpp
…string

 * Handle SQL_DATE and SQL_TIMESTAMP separately
@wankdanker
Copy link
Owner

Awesome! Thank you for re-working this onto v0.6.11. When I get a chance to understand this in more detail and test on Linux with FreeTDS, Sqlite, MySQL and Postgres I'll probably publish it as v0.7.0 because of the compatibility changes you mentioned.

@wankdanker
Copy link
Owner

Is your Windows environment 32 or 64 bit?

@lee-houghton
Copy link
Author

I'm building on a 64-bit machine, but my Node.js version is 32-bit at the moment. It's possible I've introduced some changes which break 64-bit compatibility - I apologise if that's the case :(

@wankdanker
Copy link
Owner

No worries. I just could not build because the call to SQLGetData according to spec uses SQLLEN for the BufferLength argument and in several instances in your code the variable being passed is of SQLINTEGER type. On my system there is no conversion available from SQLINTEGER to SQLLEN. So, I had to change a bunch of things over to SQLLEN. No problem, was just wondering how that might have worked for you.

At any rate, I got it to build but with lots of failing tests. :( Possibly because I didn't really pay close attention to what I was doing as explained above. ;)

…timestamp because they cmoe through as SQL_DATE (just go back to treating everything as a date and time, since JavaScript doesn't care anyway whether there was originally a time component or not)

(cherry picked from commit fb76807)
@lee-houghton
Copy link
Author

Hopefully I should have time tomorrow to fix the break I introduced for 64-bit Linux builds and do some more thorough testing with the msodbcsql11 driver.

@wankdanker
Copy link
Owner

OK. Sounds good. I've been slammed with non-related work, so I haven't had much time to address any of the pull requests. :(

@lee-houghton
Copy link
Author

OK, I'll need to test this further, but I that seems to work. I had to also change the buffer-reading code for integers to expect sizeof(SQLINTEGER) bytes in the buffer instead of sizeof(long).

@lee-houghton
Copy link
Author

Just added another fix - I noticed that date values before 1970 weren't being handled correctly in Windows (it was always returning 1969-12-31T23:59:59 for those dates) because MSVC's _mkgmtime32 doesn't handle them.

…efine by not using TzSpecificLocalTimeToSystemTime in that case.
@wankdanker wankdanker self-assigned this Feb 27, 2015
clach04 pushed a commit to clach04/node-odbc__DO_NOT_USE that referenced this pull request Dec 17, 2020
Fixing both an SQL_FLOAT issue and boundRow garbage Data

Fixes wankdanker#67
Fixes wankdanker#8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants