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

Chore/merge v1.4.6 #6

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
727db01
Update README to install unixODBC using brew
kwent Feb 13, 2018
9db6a69
Update nan to latest (v2.9.2)
wankdanker Mar 14, 2018
3ba64cf
1.3.1
wankdanker Mar 14, 2018
d22e09b
Add ODBCResult::GetRowCountSync for issue #116
wankdanker Mar 20, 2018
a4d63ed
Fix broken ODBCResult::GetColumnNamesSync
wankdanker Mar 20, 2018
0f4b9c4
1.3.2
wankdanker Mar 22, 2018
a927a26
Added ODBCConnection::GetInfoSync using SQLGetInfo
ondr3j Apr 2, 2018
a9d6627
Add test for getInfoSync()
wankdanker Apr 2, 2018
3ba2e73
1.4.0
wankdanker Apr 2, 2018
2ec659b
fix: add (const char *) to non-unicode GetInfoSync() case; fixes #118
wankdanker Apr 7, 2018
a884bf6
1.4.1
wankdanker Apr 7, 2018
6f7206a
Just adjusted edited a few line to Allow for AIX compiling
abmusse May 10, 2018
ff25020
Add `.connected` to README.
joshuapinter May 27, 2018
8e5244b
fixes for node v10
wankdanker Jun 22, 2018
7ea7333
1.4.2
wankdanker Jun 22, 2018
bc44bd2
Merge branch 'master' of https://github.com/ab-m/node-odbc into ab-m-…
wankdanker Jul 24, 2018
24750cc
1.4.3
wankdanker Jul 24, 2018
7f88df4
Just adjusted edited a few line to Allow for AIX compiling
abmusse May 10, 2018
0525014
fixes for node v10
wankdanker Jun 22, 2018
ca69d38
1.4.2
wankdanker Jun 22, 2018
2f90824
1.4.3
wankdanker Jul 24, 2018
f5a3e01
Merge branch 'patch-1' of https://github.com/joshuapinter/node-odbc
wankdanker Jul 24, 2018
d1d015f
Merge branch 'joshuapinter-patch-1'
wankdanker Jul 24, 2018
64b5aab
Merge branch 'patch-1' of https://github.com/kwent/node-odbc into kwe…
wankdanker Jul 24, 2018
71cfe77
Merge branch 'kwent-patch-1'
wankdanker Jul 24, 2018
a773846
1.4.4
wankdanker Jul 24, 2018
f08680c
Added conditional to npm install correctly when on IBM i
abmusse Jul 25, 2018
ef1c65f
Document IBM i install instructions
ThePrez Jul 25, 2018
dfa40e3
1.4.5
wankdanker Jul 26, 2018
b21a45f
Adding files to .gitignore and advertising the v2.0.0-beta.0 release
markdirish Apr 5, 2019
6f30c05
Updating version number so that it can be npm published
markdirish Apr 5, 2019
75e0648
Merge pull request #55 from markdirish/master
markdirish Apr 5, 2019
a41c204
Merge tag 'v1.4.6' into chore/merge-v1.4.6
imccoy Jun 27, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ a.out
build
node_modules
deps
.idea
.idea
core
.env
.vscode
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# node-odbc 2.0.0 is now in beta!
A new version of `odbc` has been released in beta! The initial release of this beta can be found at [https://www.npmjs.com/package/odbc/v/2.0.0-beta.0](https://www.npmjs.com/package/odbc/v/2.0.0-beta.0), while later releases can be found under the Versions tab on npm. This URL contains information including the README file outlining the new API.

To install the beta version, include the `beta` tag with your command:
```
npm install odbc@beta
```

Test it out and give feedback on the issues of the official git repository!

---

node-odbc
---------

Expand All @@ -10,7 +22,10 @@ requirements
* unixODBC binaries and development libraries for module compilation
* on Ubuntu/Debian `sudo apt-get install unixodbc unixodbc-dev`
* on RedHat/CentOS `sudo yum install unixODBC unixODBC-devel`
* on OSX using macports.org `sudo port unixODBC`
* on OSX
* using macports.org `sudo port unixODBC`
* using brew `brew install unixODBC`
* on IBM i `yum install unixODBC unixODBC-devel` (requires [yum](http://ibm.biz/ibmi-rpms))
* odbc drivers for target database
* properly configured odbc.ini and odbcinst.ini.

Expand Down Expand Up @@ -83,6 +98,16 @@ var Database = require("odbc").Database
, db = new Database();
```

#### .connected

Returns a Boolean of whether the database is currently connected.

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

console.log( "Connected: " + db.connected );
```

#### .open(connectionString, callback)

Open a connection to a database.
Expand Down
12 changes: 12 additions & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@
],
'libraries' : [
]
}],
[ 'OS=="aix"', {
'variables': {
'os_name': '<!(uname -s)',
},
'conditions': [
[ '"<(os_name)"=="OS400"', {
'ldflags': [
'-Wl,-brtl,-bnoquiet,-blibpath:/QOpenSys/pkgs/lib,-lodbc'
]
}]
]
}]
]
}
Expand Down
18 changes: 18 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "odbc",
"description": "unixodbc bindings for node",
"version": "1.3.0",
"version": "1.4.6",
"main": "lib/odbc.js",
"types": "./lib/odbc.d.ts",
"homepage": "http://github.com/wankdanker/node-odbc/",
Expand Down Expand Up @@ -33,8 +33,8 @@
"test": "cd test && node run-tests.js"
},
"dependencies": {
"bindings": "^1.2.1",
"nan": "^2.0.9",
"bindings": "^1.3.0",
"nan": "^2.10.0",
"node-gyp": "^3.0.3"
},
"gypfile": true
Expand Down
16 changes: 11 additions & 5 deletions src/odbc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ void ODBC::Init(v8::Handle<Object> exports) {
constructor_template->Set(Nan::New<String>("SQL_RESET_PARAMS").ToLocalChecked(), Nan::New<Number>(SQL_RESET_PARAMS), constant_attributes);
constructor_template->Set(Nan::New<String>("SQL_DESTROY").ToLocalChecked(), Nan::New<Number>(SQL_DESTROY), constant_attributes);
constructor_template->Set(Nan::New<String>("FETCH_ARRAY").ToLocalChecked(), Nan::New<Number>(FETCH_ARRAY), constant_attributes);
constructor_template->Set(Nan::New<String>("SQL_USER_NAME").ToLocalChecked(), Nan::New<Number>(SQL_USER_NAME), constant_attributes);
NODE_ODBC_DEFINE_CONSTANT(constructor_template, FETCH_OBJECT);

// Prototype Methods
Expand Down Expand Up @@ -204,7 +205,7 @@ void ODBC::UV_AfterCreateConnection(uv_work_t* req, int status) {
info[0] = Nan::New<External>(data->dbo->m_hEnv);
info[1] = Nan::New<External>(data->hDBC);

Local<Value> js_result = Nan::New<Function>(ODBCConnection::constructor)->NewInstance(2, info);
Local<Object> js_result = Nan::NewInstance(Nan::New(ODBCConnection::constructor), 2, info).ToLocalChecked();

info[0] = Nan::Null();
info[1] = js_result;
Expand Down Expand Up @@ -251,7 +252,7 @@ NAN_METHOD(ODBC::CreateConnectionSync) {
params[0] = Nan::New<External>(dbo->m_hEnv);
params[1] = Nan::New<External>(hDBC);

Local<Object> js_result = Nan::New<Function>(ODBCConnection::constructor)->NewInstance(2, params);
Local<Object> js_result = Nan::NewInstance(Nan::New(ODBCConnection::constructor), 2, params).ToLocalChecked();

info.GetReturnValue().Set(js_result);
}
Expand Down Expand Up @@ -445,8 +446,10 @@ Handle<Value> ODBC::GetColumnValue( SQLHSTMT hStmt, Column column,
, tm_wday : 0
, tm_yday : 0
, tm_isdst : 0
#ifndef _AIX //AIX does not have these
, tm_gmtoff : 0
, tm_zone : 0
#endif
};

SQL_TIMESTAMP_STRUCT odbcTime;
Expand Down Expand Up @@ -482,6 +485,9 @@ Handle<Value> ODBC::GetColumnValue( SQLHSTMT hStmt, Column column,
return scope.Escape(Nan::New<Date>((double(timegm(&timeInfo)) * 1000)
+ (odbcTime.fraction / 1000000)).ToLocalChecked());
#else
#ifdef _AIX
#define timelocal mktime
#endif
return scope.Escape(Nan::New<Date>((double(timelocal(&timeInfo)) * 1000)
+ (odbcTime.fraction / 1000000)).ToLocalChecked());
#endif
Expand Down Expand Up @@ -847,11 +853,11 @@ Local<Object> ODBC::GetSQLError (SQLSMALLINT handleType, SQLHANDLE handle, char*
// First error is assumed the primary error
objError->Set(Nan::New("error").ToLocalChecked(), Nan::New(message).ToLocalChecked());
#ifdef UNICODE
objError->SetPrototype(Exception::Error(Nan::New((uint16_t *)errorMessage).ToLocalChecked()));
Nan::SetPrototype(objError, Exception::Error(Nan::New((uint16_t *) errorMessage).ToLocalChecked()));
objError->Set(Nan::New("message").ToLocalChecked(), Nan::New((uint16_t *)errorMessage).ToLocalChecked());
objError->Set(Nan::New("state").ToLocalChecked(), Nan::New((uint16_t *)errorSQLState).ToLocalChecked());
#else
objError->SetPrototype(Exception::Error(Nan::New(errorMessage).ToLocalChecked()));
Nan::SetPrototype(objError, Exception::Error(Nan::New(errorMessage).ToLocalChecked()));
objError->Set(Nan::New("message").ToLocalChecked(), Nan::New(errorMessage).ToLocalChecked());
objError->Set(Nan::New("state").ToLocalChecked(), Nan::New(errorSQLState).ToLocalChecked());
#endif
Expand All @@ -876,7 +882,7 @@ Local<Object> ODBC::GetSQLError (SQLSMALLINT handleType, SQLHANDLE handle, char*
if (statusRecCount == 0) {
//Create a default error object if there were no diag records
objError->Set(Nan::New("error").ToLocalChecked(), Nan::New(message).ToLocalChecked());
objError->SetPrototype(Exception::Error(Nan::New(message).ToLocalChecked()));
Nan::SetPrototype(objError, Exception::Error(Nan::New(message).ToLocalChecked()));
objError->Set(Nan::New("message").ToLocalChecked(), Nan::New(
(const char *) "[node-odbc] An error occurred but no diagnostic information was available.").ToLocalChecked());
}
Expand Down
58 changes: 52 additions & 6 deletions src/odbc_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ void ODBCConnection::Init(v8::Handle<Object> exports) {
Nan::SetPrototypeMethod(constructor_template, "beginTransactionSync", BeginTransactionSync);
Nan::SetPrototypeMethod(constructor_template, "endTransaction", EndTransaction);
Nan::SetPrototypeMethod(constructor_template, "endTransactionSync", EndTransactionSync);


Nan::SetPrototypeMethod(constructor_template, "getInfoSync", GetInfoSync);

Nan::SetPrototypeMethod(constructor_template, "columns", Columns);
Nan::SetPrototypeMethod(constructor_template, "tables", Tables);

Expand Down Expand Up @@ -554,7 +556,7 @@ NAN_METHOD(ODBCConnection::CreateStatementSync) {
params[1] = Nan::New<External>(conn->m_hDBC);
params[2] = Nan::New<External>(hSTMT);

Local<Object> js_result(Nan::New<Function>(ODBCStatement::constructor)->NewInstance(3, params));
Local<Object> js_result(Nan::NewInstance(Nan::New(ODBCStatement::constructor), 3, params).ToLocalChecked());

info.GetReturnValue().Set(js_result);
}
Expand Down Expand Up @@ -643,12 +645,11 @@ void ODBCConnection::UV_AfterCreateStatement(uv_work_t* req, int status) {
info[1] = Nan::New<External>(data->conn->m_hDBC);
info[2] = Nan::New<External>(data->hSTMT);

Local<Value> js_result = Nan::New<Function>(ODBCStatement::constructor)->NewInstance(3, info);
Local<Object> js_result = Nan::NewInstance(Nan::New(ODBCStatement::constructor), 3, info).ToLocalChecked();

info[0] = Nan::Null();
info[1] = js_result;


Nan::TryCatch try_catch;

data->cb->Call( 2, info);
Expand Down Expand Up @@ -888,7 +889,7 @@ void ODBCConnection::UV_AfterQuery(uv_work_t* req, int status) {
info[2] = Nan::New<External>(data->hSTMT);
info[3] = Nan::New<External>(canFreeHandle);

Local<Object> js_result = Nan::New<Function>(ODBCResult::constructor)->NewInstance(4, info);
Local<Object> js_result = Nan::NewInstance(Nan::New(ODBCResult::constructor), 4, info).ToLocalChecked();

// Check now to see if there was an error (as there may be further result sets)
if (data->result == SQL_ERROR) {
Expand Down Expand Up @@ -1137,12 +1138,57 @@ NAN_METHOD(ODBCConnection::QuerySync) {
result[2] = Nan::New<External>(hSTMT);
result[3] = Nan::New<External>(canFreeHandle);

Local<Object> js_result = Nan::New<Function>(ODBCResult::constructor)->NewInstance(4, result);
Local<Object> js_result = Nan::NewInstance(Nan::New(ODBCResult::constructor), 4, result).ToLocalChecked();

info.GetReturnValue().Set(js_result);
}
}


/*
* GetInfoSync
*/

NAN_METHOD(ODBCConnection::GetInfoSync) {
DEBUG_PRINTF("ODBCConnection::GetInfoSync\n");
Nan::HandleScope scope;

ODBCConnection* conn = Nan::ObjectWrap::Unwrap<ODBCConnection>(info.Holder());

if (info.Length() == 1) {
if ( !info[0]->IsNumber() ) {
return Nan::ThrowTypeError("ODBCConnection::GetInfoSync(): Argument 0 must be a Number.");
}
}
else {
return Nan::ThrowTypeError("ODBCConnection::GetInfoSync(): Requires 1 Argument.");
}

SQLUSMALLINT InfoType = info[0]->NumberValue();

switch (InfoType) {
case SQL_USER_NAME:
SQLRETURN ret;
SQLTCHAR userName[255];
SQLSMALLINT userNameLength;

ret = SQLGetInfo(conn->m_hDBC, SQL_USER_NAME, userName, sizeof(userName), &userNameLength);

if (SQL_SUCCEEDED(ret)) {
#ifdef UNICODE
info.GetReturnValue().Set(Nan::New((uint16_t *)userName).ToLocalChecked());
#else
info.GetReturnValue().Set(Nan::New((const char *) userName).ToLocalChecked());
#endif
}
break;

default:
return Nan::ThrowTypeError("ODBCConnection::GetInfoSync(): The only supported Argument is SQL_USER_NAME.");
}
}


/*
* Tables
*/
Expand Down
1 change: 1 addition & 0 deletions src/odbc_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class ODBCConnection : public Nan::ObjectWrap {
static NAN_METHOD(QuerySync);
static NAN_METHOD(BeginTransactionSync);
static NAN_METHOD(EndTransactionSync);
static NAN_METHOD(GetInfoSync);
protected:

struct Fetch_Request {
Expand Down
38 changes: 33 additions & 5 deletions src/odbc_result.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ void ODBCResult::Init(v8::Handle<Object> exports) {
Nan::SetPrototypeMethod(constructor_template, "fetchSync", FetchSync);
Nan::SetPrototypeMethod(constructor_template, "fetchAllSync", FetchAllSync);
Nan::SetPrototypeMethod(constructor_template, "getColumnNamesSync", GetColumnNamesSync);
Nan::SetPrototypeMethod(constructor_template, "getRowCountSync", GetRowCountSync);

// Properties
OPTION_FETCH_MODE.Reset(Nan::New("fetchMode").ToLocalChecked());
Expand Down Expand Up @@ -184,7 +185,7 @@ NAN_METHOD(ODBCResult::Fetch) {

Local<String> fetchModeKey = Nan::New<String>(OPTION_FETCH_MODE);
if (obj->Has(fetchModeKey) && obj->Get(fetchModeKey)->IsInt32()) {
data->fetchMode = obj->Get(fetchModeKey)->ToInt32()->Value();
data->fetchMode = Nan::To<Uint32>(obj->Get(fetchModeKey)).ToLocalChecked()->Value();
}
}
else {
Expand Down Expand Up @@ -337,7 +338,7 @@ NAN_METHOD(ODBCResult::FetchSync) {

Local<String> fetchModeKey = Nan::New<String>(OPTION_FETCH_MODE);
if (obj->Has(fetchModeKey) && obj->Get(fetchModeKey)->IsInt32()) {
fetchMode = obj->Get(fetchModeKey)->ToInt32()->Value();
fetchMode = Nan::To<Uint32>(obj->Get(fetchModeKey)).ToLocalChecked()->Value();
}
}

Expand Down Expand Up @@ -433,7 +434,7 @@ NAN_METHOD(ODBCResult::FetchAll) {

Local<String> fetchModeKey = Nan::New<String>(OPTION_FETCH_MODE);
if (obj->Has(fetchModeKey) && obj->Get(fetchModeKey)->IsInt32()) {
data->fetchMode = obj->Get(fetchModeKey)->ToInt32()->Value();
data->fetchMode = Nan::To<Uint32>(obj->Get(fetchModeKey)).ToLocalChecked()->Value();
}
}
else {
Expand Down Expand Up @@ -594,7 +595,7 @@ NAN_METHOD(ODBCResult::FetchAllSync) {

Local<String> fetchModeKey = Nan::New<String>(OPTION_FETCH_MODE);
if (obj->Has(fetchModeKey) && obj->Get(fetchModeKey)->IsInt32()) {
fetchMode = obj->Get(fetchModeKey)->ToInt32()->Value();
fetchMode = Nan::To<Uint32>(obj->Get(fetchModeKey)).ToLocalChecked()->Value();
}
}

Expand Down Expand Up @@ -744,9 +745,36 @@ NAN_METHOD(ODBCResult::GetColumnNamesSync) {
}

for (int i = 0; i < self->colCount; i++) {
#ifdef UNICODE
cols->Set(Nan::New(i),
Nan::New((const char *) self->columns[i].name).ToLocalChecked());
Nan::New((uint16_t*) self->columns[i].name).ToLocalChecked());
#else
cols->Set(Nan::New(i),
Nan::New((char *) self->columns[i].name).ToLocalChecked());
#endif

}

info.GetReturnValue().Set(cols);
}

/*
* GetRowCountSync
*/

NAN_METHOD(ODBCResult::GetRowCountSync) {
DEBUG_PRINTF("ODBCResult::GetRowCountSync\n");
Nan::HandleScope scope;

ODBCResult* self = Nan::ObjectWrap::Unwrap<ODBCResult>(info.Holder());

SQLLEN rowCount = 0;

SQLRETURN ret = SQLRowCount(self->m_hSTMT, &rowCount);

if (!SQL_SUCCEEDED(ret)) {
rowCount = 0;
}

info.GetReturnValue().Set(Nan::New<Number>(rowCount));
}
1 change: 1 addition & 0 deletions src/odbc_result.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class ODBCResult : public Nan::ObjectWrap {
static NAN_METHOD(FetchSync);
static NAN_METHOD(FetchAllSync);
static NAN_METHOD(GetColumnNamesSync);
static NAN_METHOD(GetRowCountSync);

//property getter/setters
static NAN_GETTER(FetchModeGetter);
Expand Down
Loading