Skip to content

Commit

Permalink
Merge pull request #1 from immuta/remove_unicode
Browse files Browse the repository at this point in the history
Disable UNICODE support by default
  • Loading branch information
KyleLilly authored Oct 24, 2016
2 parents bc80233 + c729b28 commit d8f21d1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 47 deletions.
72 changes: 34 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ var db = require('odbc')()

db.open(cn, function (err) {
if (err) return console.log(err);

db.query('select * from user where user_id = ?', [42], function (err, data) {
if (err) console.log(err);

console.log(data);

db.close(function () {
Expand All @@ -60,7 +60,7 @@ api

### Database

The simple api is based on instances of the `Database` class. You may get an
The simple api is based on instances of the `Database` class. You may get an
instance in one of the following ways:

```javascript
Expand All @@ -73,7 +73,7 @@ or by using the helper function:

```javascript
var db = require("odbc")();
```
```

or by creating an instance with the constructor function:

Expand Down Expand Up @@ -148,7 +148,7 @@ db.open(cn, function (err) {
if (err) {
return console.log(err);
}

console.log(rows);

//if moreResultSets is truthy, then this callback function will be called
Expand Down Expand Up @@ -194,9 +194,9 @@ db.open(cn, function (err) {
if (err) {
return console.log(err);
}

//we now have an open connection to the database

db.close(function (err) {
console.log("the database connection is now closed");
});
Expand Down Expand Up @@ -472,7 +472,7 @@ pool.open(cn, function (err, db) {

//db is now an open database connection and can be used like normal
//but all we will do now is close the whole pool

pool.close(function () {
console.log("all connections in the pool are closed");
});
Expand All @@ -493,7 +493,7 @@ var connectionString = "DRIVER={FreeTDS};SERVER=host;UID=user;PWD=password;DATAB
db.open(connectionString, function(err) {
db.query("select * from table", function(err, rows, moreResultSets) {
console.log(util.inspect(rows, null, 10));

db.close(function() {
console.log("Database connection closed");
});
Expand All @@ -517,8 +517,8 @@ build options

### Debug

If you would like to enable debugging messages to be displayed you can add the
flag `DEBUG` to the defines section of the `binding.gyp` file and then execute
If you would like to enable debugging messages to be displayed you can add the
flag `DEBUG` to the defines section of the `binding.gyp` file and then execute
`node-gyp rebuild`.

```javascript
Expand All @@ -531,10 +531,10 @@ flag `DEBUG` to the defines section of the `binding.gyp` file and then execute

### Dynodbc

You may also enable the ability to load a specific ODBC driver and bypass the
You may also enable the ability to load a specific ODBC driver and bypass the
ODBC driver management layer. A performance increase of ~5Kqps was seen using
this method with the libsqlite3odbc driver. To do this, specify the `dynodbc`
flag in the defines section of the `binding.gyp` file. You will also need to
flag in the defines section of the `binding.gyp` file. You will also need to
remove any library references in `binding.gyp`. Then execute `node-gyp
rebuild`.

Expand All @@ -545,20 +545,16 @@ rebuild`.
],
'conditions' : [
[ 'OS == "linux"', {
'libraries' : [
//remove this: '-lodbc'
'libraries' : [
//remove this: '-lodbc'
],
<snip>
```
### Unicode
By default, UNICODE suppport is enabled. This should provide the most accurate
way to get Unicode strings submitted to your database. For best results, you
may want to put your Unicode string into bound parameters.
However, if you experience issues or you think that submitting UTF8 strings will
work better or faster, you can remove the `UNICODE` define in `binding.gyp`
By default, UNICODE suppport is disabled. If you wish to enable UNICODE support
you can add the `UNICODE` define in `binding.gyp`
```javascript
<snip>
Expand Down Expand Up @@ -587,7 +583,7 @@ define in `binding.gyp`
When column names are retrieved from ODBC, you can request by SQL_DESC_NAME or
SQL_DESC_LABEL. SQL_DESC_NAME is the exact column name or none if there is none
defined. SQL_DESC_LABEL is the heading or column name or calculation.
defined. SQL_DESC_LABEL is the heading or column name or calculation.
SQL_DESC_LABEL is used by default and seems to work well in most cases.
If you want to use the exact column name via SQL_DESC_NAME, enable the `STRICT_COLUMN_NAMES`
Expand All @@ -605,39 +601,39 @@ tips
----
### Using node < v0.10 on Linux
Be aware that through node v0.9 the uv_queue_work function, which is used to
execute the ODBC functions on a separate thread, uses libeio for its thread
Be aware that through node v0.9 the uv_queue_work function, which is used to
execute the ODBC functions on a separate thread, uses libeio for its thread
pool. This thread pool by default is limited to 4 threads.
This means that if you have long running queries spread across multiple
instances of odbc.Database() or using odbc.Pool(), you will only be able to
This means that if you have long running queries spread across multiple
instances of odbc.Database() or using odbc.Pool(), you will only be able to
have 4 concurrent queries.
You can increase the thread pool size by using @developmentseed's [node-eio]
(https://github.com/developmentseed/node-eio).
#### install:
#### install:
```bash
npm install eio
```
#### usage:
```javascript
var eio = require('eio');
var eio = require('eio');
eio.setMinParallel(threadCount);
```
### Using the FreeTDS ODBC driver
* If you have column names longer than 30 characters, you should add
* If you have column names longer than 30 characters, you should add
"TDS_Version=7.0" to your connection string to retrive the full column name.
* Example : "DRIVER={FreeTDS};SERVER=host;UID=user;PWD=password;DATABASE=dbname;TDS_Version=7.0"
* If you got error "[unixODBC][FreeTDS][SQL Server]Unable to connect to data source"
* If you got error "[unixODBC][FreeTDS][SQL Server]Unable to connect to data source"
Try use SERVERNAME instead of SERVER
* Example : "DRIVER={FreeTDS};SERVERNAME=host;UID=user;PWD=password;DATABASE=dbname"
* Be sure that your odbcinst.ini has the proper threading configuration for your
FreeTDS driver. If you choose the incorrect threading model it may cause
the thread pool to be blocked by long running queries. This is what
the thread pool to be blocked by long running queries. This is what
@wankdanker currently uses on Ubuntu 12.04:
```
Expand All @@ -646,7 +642,7 @@ Description = TDS driver (Sybase/MS SQL)
Driver = libtdsodbc.so
Setup = libtdsS.so
CPTimeout = 120
CPReuse =
CPReuse =
Threading = 0
```
Expand All @@ -668,19 +664,19 @@ Copyright (c) 2013 Dan VerWeire <[email protected]>
Copyright (c) 2010 Lee Smith <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16 changes: 7 additions & 9 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
'targets' : [
{
'target_name' : 'odbc_bindings',
'sources' : [
'sources' : [
'src/odbc.cpp',
'src/odbc_connection.cpp',
'src/odbc_statement.cpp',
Expand All @@ -13,13 +13,11 @@
'include_dirs': [
"<!(node -e \"require('nan')\")"
],
'defines' : [
'UNICODE'
],
'defines' : [],
'conditions' : [
[ 'OS == "linux"', {
'libraries' : [
'-lodbc'
'libraries' : [
'-lodbc'
],
'cflags' : [
'-g'
Expand All @@ -28,16 +26,16 @@
[ 'OS == "mac"', {
'libraries' : [
'-L/usr/local/lib',
'-lodbc'
'-lodbc'
]
}],
[ 'OS=="win"', {
'sources' : [
'src/strptime.c',
'src/odbc.cpp'
],
'libraries' : [
'-lodbccp32.lib'
'libraries' : [
'-lodbccp32.lib'
]
}]
]
Expand Down

0 comments on commit d8f21d1

Please sign in to comment.