Skip to content

Commit 11de52f

Browse files
author
wink
committed
initial commit
0 parents  commit 11de52f

8 files changed

+676
-0
lines changed

LICENSE

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright (c) 2010 Lee Smith <[email protected]>
2+
3+
Permission is hereby granted, free of charge, to any person
4+
obtaining a copy of this software and associated documentation
5+
files (the "Software"), to deal in the Software without
6+
restriction, including without limitation the rights to use,
7+
copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the
9+
Software is furnished to do so, subject to the following
10+
conditions:
11+
12+
The above copyright notice and this permission notice shall be
13+
included in all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.

README.md

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
NAME
2+
----
3+
4+
node-odbc - An asynchronous Node interface to unixodbc and it's supported drivers
5+
6+
SYNOPSYS
7+
--------
8+
9+
var sys = require("sys");
10+
var odbc = require("odbc");
11+
12+
var db = new odbc.Database();
13+
db.open("DRIVER={FreeTDS};SERVER=host;UID=user;PWD=password;DATABASE=dbname", function(err)
14+
{
15+
db.query("select * from table", function(err, rows)
16+
{
17+
sys.debug(sys.inspect(rows));
18+
db.close(function(){});
19+
}
20+
});
21+
22+
23+
DESCRIPTION
24+
-----------
25+
26+
unixODBC binding to node. Needs a properly configured odbc(inst).ini. Tested locally using the FreeTDS and Postgres drivers.
27+
28+
Installation
29+
------------
30+
31+
- Make sure you have unixODBC installed and the drivers configured.
32+
- node-waf configure build
33+
34+
BUGS
35+
----
36+
37+
None known, but there might be one ;).
38+
39+
40+
TODO
41+
----
42+
43+
- Not complete, supports connection management and querying.
44+
- Better (any?) error handling.
45+
- Tests
46+
- SQLGetData needs to support retrieving multiple chunks and concatenation in the case of large column values
47+
48+
ACKNOWLEDGEMENTS
49+
----------------
50+
51+
- orlandov's node-sqlite binding was the framework I used to figure out using eio's thread pool to handle blocking calls since non blocking odbc doesn't seem to appear until 3.8.
52+
53+
AUTHOR
54+
------
55+
56+
Lee Smith ([email protected])

build.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
rm -rf build
3+
node-waf configure build

odbc.js

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
Copyright (c) 2010, Lee Smith <[email protected]>
3+
4+
Permission to use, copy, modify, and/or distribute this software for any
5+
purpose with or without fee is hereby granted, provided that the above
6+
copyright notice and this permission notice appear in all copies.
7+
8+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15+
*/
16+
17+
var sys = require("sys");
18+
var sqlite = require("./odbc_bindings");
19+
20+
var Database = exports.Database = function () {
21+
var self = this;
22+
var db = new sqlite.Database();
23+
24+
db.__proto__ = Database.prototype;
25+
26+
db.addListener("ready", function () {
27+
db.maybeDispatchQuery();
28+
});
29+
30+
db.addListener("result", function () {
31+
process.assert(db.currentQuery);
32+
var callback = db.currentQuery[1];
33+
var args = Array.prototype.slice.call(db.currentQuery[2]);
34+
args.shift();
35+
args.shift();
36+
37+
if(arguments[0])
38+
{
39+
arguments[0].query = db.currentQuery[0];
40+
}
41+
42+
db.currentQuery = null;
43+
if (callback) {
44+
var newArgs = Array.prototype.slice.call(arguments);
45+
46+
for(var i = 0; i < args.length; i++) {
47+
newArgs.push(args[i]);
48+
}
49+
50+
callback.apply(db, newArgs);
51+
}
52+
db.maybeDispatchQuery();
53+
});
54+
55+
return db;
56+
};
57+
58+
Database.prototype = {
59+
__proto__: sqlite.Database.prototype,
60+
constructor: Database,
61+
};
62+
63+
Database.prototype.maybeDispatchQuery = function () {
64+
if (!this._queries) return;
65+
if (!this.currentQuery && this._queries.length > 0) {
66+
this.currentQuery = this._queries.shift();
67+
this.dispatchQuery(this.currentQuery[0]);
68+
}
69+
};
70+
71+
Database.prototype.query = function(sql, callback) {
72+
this._queries = this._queries || [];
73+
this._queries.push([sql, callback, arguments]);
74+
this.maybeDispatchQuery();
75+
};

odbc_bindings.node

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build/default/odbc_bindings.node

0 commit comments

Comments
 (0)