Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

tested with node 0.5.9

  • Loading branch information...
commit 45c5a67a7ab55b2fc1ceed0e09df167259372b8e 1 parent 085a43b
@xdenser authored
View
2  LICENSE
@@ -1,7 +1,7 @@
MIT License
-----------
-Copyright (C) 2010 Denys Khanzhiyev aka xdenser.
+Copyright (C) 2011 Denys Khanzhiyev aka xdenser.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
View
22 firebird.js
@@ -1,17 +1,29 @@
-var binding = require("./build/default/binding");
-var sys = require("sys");
+var binding = require("./build/Release/binding");
var stream = require("stream");
var util = require("util");
+var events = require('events');
var SchunkSize = 4*1024;
var Connection = binding.Connection;
+var FBEventEmitter = binding.FBEventEmitter;
var FBResult = binding.FBResult;
var FBStatement = binding.FBStatement;
var FBblob = binding.FBblob;
+//util.inherits(FBEventEmitter, events.EventEmitter);
+for(var i in events.EventEmitter.prototype){
+ FBEventEmitter.prototype[i] = events.EventEmitter.prototype[i];
+}
+/*
+FBEventEmitter.prototype.init = function(){
+ console.log('init called ');
+}
+*/
+//util.inherits(Connection, FBEventEmitter);
+
function MakeSafe(obj,meth){
- var super = obj.prototype[meth];
+ var superm = obj.prototype[meth];
obj.prototype[meth] = function(){
if(this.inAsyncCall){
var self = this;
@@ -20,7 +32,7 @@ function MakeSafe(obj,meth){
self[meth].apply(self,args);
});
}
- else super.apply(this,arguments);
+ else superm.apply(this,arguments);
}
}
@@ -108,7 +120,7 @@ binding.FBblob.prototype._readAll = function(initialSize, chunkSize, callback){
exports.createConnection = function () {
- var c = new Connection;
+ var c = new Connection();
return c;
};
View
8 src/fb-bindings-blob.cc
@@ -154,11 +154,11 @@ int FBblob::EIO_After_Read(eio_req *req)
return 0;
}
-int FBblob::EIO_Read(eio_req *req)
+void FBblob::EIO_Read(eio_req *req)
{
struct rw_request *r_req = (struct rw_request *)(req->data);
r_req->res = r_req->blob->read(r_req->status,r_req->buffer,(unsigned short) r_req->length);
- return 0;
+ return;
}
Handle<Value> FBblob::Read(const Arguments& args)
@@ -302,11 +302,11 @@ int FBblob::EIO_After_Write(eio_req *req)
}
-int FBblob::EIO_Write(eio_req *req)
+void FBblob::EIO_Write(eio_req *req)
{
struct rw_request *w_req = (struct rw_request *)(req->data);
isc_put_segment(w_req->status, &w_req->blob->handle, w_req->length, w_req->buffer);
- return 0;
+ return;
}
View
4 src/fb-bindings-blob.h
@@ -45,7 +45,7 @@ class FBblob : public FBEventEmitter {
static int EIO_After_Read(eio_req *req);
- static int EIO_Read(eio_req *req);
+ static void EIO_Read(eio_req *req);
static Handle<Value>
Read(const Arguments& args);
@@ -61,7 +61,7 @@ class FBblob : public FBEventEmitter {
static int EIO_After_Write(eio_req *req);
- static int EIO_Write(eio_req *req);
+ static void EIO_Write(eio_req *req);
static Handle<Value>
Write(const Arguments& args);
View
20 src/fb-bindings-connection.cc
@@ -1,4 +1,4 @@
-/*!
+/*
* Copyright by Denys Khanzhiyev aka xdenser
*
* See license text in LICENSE file
@@ -20,8 +20,9 @@ void
Local<FunctionTemplate> t = FunctionTemplate::New(New);
- t->Inherit(FBEventEmitter::constructor_template);
t->InstanceTemplate()->SetInternalFieldCount(1);
+ t->SetClassName(String::NewSymbol("Connection"));
+ t->Inherit(FBEventEmitter::constructor_template);
// Methods
NODE_SET_PROTOTYPE_METHOD(t, "connectSync", ConnectSync);
@@ -44,6 +45,7 @@ void
instance_t->SetAccessor(String::NewSymbol("connected"), ConnectedGetter);
instance_t->SetAccessor(String::NewSymbol("inTransaction"), InTransactionGetter);
instance_t->SetAccessor(String::NewSymbol("inAsyncCall"),InAsyncGetter);
+
target->Set(String::NewSymbol("Connection"), t->GetFunction());
}
@@ -365,7 +367,7 @@ Handle<Value>
Connection *connection = new Connection();
connection->Wrap(args.This());
- return args.This();
+ return scope.Close(args.This());
}
Handle<Value>
@@ -431,7 +433,7 @@ int Connection::EIO_After_Connect(eio_req *req)
}
-int Connection::EIO_Connect(eio_req *req)
+void Connection::EIO_Connect(eio_req *req)
{
struct connect_request *conn_req = (struct connect_request *)(req->data);
req->result = conn_req->conn->Connect(
@@ -445,7 +447,7 @@ int Connection::EIO_Connect(eio_req *req)
delete conn_req->Password;
delete conn_req->Role;
- return 0;
+ return ;
}
@@ -608,12 +610,12 @@ int Connection::EIO_After_TransactionRequest(eio_req *req)
}
-int Connection::EIO_TransactionRequest(eio_req *req)
+void Connection::EIO_TransactionRequest(eio_req *req)
{
struct transaction_request *tr_req = (struct transaction_request *)(req->data);
if(tr_req->commit) req->result = tr_req->conn->commit_transaction();
else req->result = tr_req->conn->rollback_transaction();
- return 0;
+ return;
}
@@ -762,13 +764,13 @@ int Connection::EIO_After_Query(eio_req *req)
}
-int Connection::EIO_Query(eio_req *req)
+void Connection::EIO_Query(eio_req *req)
{
struct query_request *q_req = (struct query_request *)(req->data);
req->result = q_req->conn->process_statement(&q_req->sqlda,**(q_req->Query), &q_req->stmt);
delete q_req->Query;
- return 0;
+ return;
}
Handle<Value>
View
6 src/fb-bindings-connection.h
@@ -62,7 +62,7 @@ class Connection : public FBEventEmitter {
static int EIO_After_Connect(eio_req *req);
- static int EIO_Connect(eio_req *req);
+ static void EIO_Connect(eio_req *req);
static Handle<Value>
Connect (const Arguments& args);
@@ -94,7 +94,7 @@ class Connection : public FBEventEmitter {
static int EIO_After_TransactionRequest(eio_req *req);
- static int EIO_TransactionRequest(eio_req *req);
+ static void EIO_TransactionRequest(eio_req *req);
static Handle<Value>
Commit (const Arguments& args);
@@ -115,7 +115,7 @@ class Connection : public FBEventEmitter {
static int EIO_After_Query(eio_req *req);
- static int EIO_Query(eio_req *req);
+ static void EIO_Query(eio_req *req);
static Handle<Value>
Query(const Arguments& args);
View
4 src/fb-bindings-eventblock.cc
@@ -6,7 +6,7 @@
#include <stdlib.h>
#include <string.h>
-#include <node_events.h>
+#include "./fb-bindings-fbeventemitter.h"
#include "./fb-bindings-eventblock.h"
/*
@@ -200,7 +200,7 @@ void event_block::event_notification(EV_P_ ev_async *w, int revents){
if(Vector[i]) {
argv[0] = EvNames[i];
argv[1] = Integer::New(Vector[i]);
- ((EventEmitter*) conn)->Emit(fbevent_symbol,2,argv);
+ ((FBEventEmitter*) conn)->Emit(fbevent_symbol,2,argv);
}
}
View
27 src/fb-bindings-fbeventemitter.cc
@@ -6,11 +6,31 @@
#include <node.h>
#include "./fb-bindings-fbeventemitter.h"
-void FBEventEmitter::Init()
+Persistent<FunctionTemplate> FBEventEmitter::constructor_template;
+
+void FBEventEmitter::Initialize(v8::Handle<v8::Object> target)
{
start_async_symbol = NODE_PSYMBOL("fbStartAsync");
stop_async_symbol = NODE_PSYMBOL("fbStopAsync");
+
+ Local<FunctionTemplate> t = FunctionTemplate::New();
+
+ constructor_template = Persistent<FunctionTemplate>::New(t);
+ constructor_template->SetClassName(String::NewSymbol("FBEventEmitter"));
+
+ target->Set(String::NewSymbol("FBEventEmitter"), constructor_template->GetFunction());
}
+
+
+void FBEventEmitter::Emit(Handle<String> event, int argc, Handle<Value> argv[])
+ {
+ HandleScope scope;
+ Handle<Value> argv1[11];
+ if(argc>10) ThrowException(Exception::Error(String::New("Cant process more than 10 arguments")));
+ argv1[0] = event;
+ for(int i=0;i<argc;i++) argv1[i+1] = argv[i];
+ node::MakeCallback(handle_,"emit",argc+1,argv1);
+ }
void FBEventEmitter::start_async()
{
@@ -24,9 +44,12 @@ void FBEventEmitter::stop_async()
Emit(stop_async_symbol, 0, NULL);
}
-FBEventEmitter::FBEventEmitter () : EventEmitter ()
+FBEventEmitter::FBEventEmitter () : ObjectWrap ()
{
in_async = false;
+ // Handle<Value> argv[1];
+ // printf("in init\n");
+ // node::MakeCallback(handle_,"init",0,argv);
}
Handle<Value>
View
15 src/fb-bindings-fbeventemitter.h
@@ -5,11 +5,10 @@
*/
#ifndef SRC_FB_BINDINGS_FBEVENTEMITTER_H_
#define SRC_FB_BINDINGS_FBEVENTEMITTER_H_
-/*
-include <node.h>
-include <v8.h>
-*/
-#include <node_events.h>
+
+#include <node.h>
+#include <v8.h>
+
using namespace node;
using namespace v8;
@@ -17,9 +16,11 @@ using namespace v8;
static Persistent<String> start_async_symbol;
static Persistent<String> stop_async_symbol;
-class FBEventEmitter : public EventEmitter {
+class FBEventEmitter: public ObjectWrap {
public:
- static void Init();
+ static void Initialize(v8::Handle<v8::Object> target);
+ static v8::Persistent<v8::FunctionTemplate> constructor_template;
+ void Emit(Handle<String> event, int argc, Handle<Value> argv[]);
protected:
void start_async();
View
4 src/fb-bindings-fbresult.cc
@@ -706,7 +706,7 @@ int FBResult::EIO_After_Fetch(eio_req *req)
return 0;
}
-int FBResult::EIO_Fetch(eio_req *req)
+void FBResult::EIO_Fetch(eio_req *req)
{
struct fetch_request *f_req = (struct fetch_request *)(req->data);
@@ -714,7 +714,7 @@ int FBResult::EIO_Fetch(eio_req *req)
req->result = (f_req->fetchStat == 0);
- return 0;
+ return ;
}
Handle<Value>
View
2  src/fb-bindings-fbresult.h
@@ -51,7 +51,7 @@ class FBResult : public FBEventEmitter {
static int EIO_After_Fetch(eio_req *req);
- static int EIO_Fetch(eio_req *req);
+ static void EIO_Fetch(eio_req *req);
static Handle<Value>
Fetch(const Arguments& args);
View
6 src/fb-bindings-statement.cc
@@ -194,14 +194,14 @@ int FBStatement::EIO_After_Exec(eio_req *req)
}
}
- ((EventEmitter*) fb_stmt)->Emit(event,argc,argv);
+ ((FBEventEmitter*) fb_stmt)->Emit(event,argc,argv);
fb_stmt->stop_async();
fb_stmt->Unref();
free(e_req);
return 0;
}
-int FBStatement::EIO_Exec(eio_req *req)
+void FBStatement::EIO_Exec(eio_req *req)
{
struct exec_request *e_req = (struct exec_request *)(req->data);
FBStatement *fb_stmt = e_req->statement;
@@ -211,7 +211,7 @@ int FBStatement::EIO_Exec(eio_req *req)
else
req->result = true;
- return 0;
+ return ;
}
Handle<Value>
View
2  src/fb-bindings-statement.h
@@ -35,7 +35,7 @@ class FBStatement : public FBResult {
static int EIO_After_Exec(eio_req *req);
- static int EIO_Exec(eio_req *req);
+ static void EIO_Exec(eio_req *req);
static Handle<Value>
Exec (const Arguments& args);
View
2  src/fb-bindings.cc
@@ -44,7 +44,7 @@ init (Handle<Object> target)
HandleScope scope;
event_block::Init();
- FBEventEmitter::Init();
+ FBEventEmitter::Initialize(target);
FBResult::Initialize(target);
Connection::Initialize(target);
FBblob::Initialize(target);
View
10 tests/def/test-async.js
@@ -8,12 +8,12 @@ var cfg = require("../config").cfg;
// Require modules
var
- fb_binding = require("../../build/default/binding");
+ fb_binding = require("../../firebird.js");
exports.AsyncConnection = function (test) {
test.expect(4);
- var conn = new fb_binding.Connection;
+ var conn = fb_binding.createConnection();
conn.connect(cfg.db, cfg.user, cfg.password, cfg.role, function(){
test.ok(conn.connected,"Connected to database");
conn.query("select * from rdb$relations", function(err,res){
@@ -29,7 +29,7 @@ exports.AsyncConnection = function (test) {
exports.AsyncQueryWithError = function (test) {
test.expect(4);
- var conn = new fb_binding.Connection;
+ var conn = fb_binding.createConnection();
conn.connect(cfg.db, cfg.user, cfg.password, cfg.role, function(){
test.ok(conn.connected,"Connected to database");
conn.query("select * from non_existent_table", function(err,res){
@@ -44,7 +44,7 @@ exports.AsyncQueryWithError = function (test) {
exports.AsyncFetch = function(test){
test.expect(6);
- var conn = new fb_binding.Connection;
+ var conn = fb_binding.createConnection();
conn.connectSync(cfg.db, cfg.user, cfg.password, cfg.role);
test.ok(conn.connected,"Connected to database");
var res = conn.querySync("select * from rdb$relations");
@@ -62,7 +62,7 @@ exports.AsyncFetch = function(test){
exports.InAsyncCallConnection = function(test){
test.expect(7);
- var conn = new fb_binding.Connection;
+ var conn = fb_binding.createConnection();
conn.on("fbStartAsync",function(){
test.ok(true,"StartAsync Called");
});
View
2  tests/def/test-binding.js
@@ -8,7 +8,7 @@ var cfg = require("../config").cfg;
// Require modules
var
- fb_binding = require("../../build/default/binding");
+ fb_binding = require("../../build/Release/binding");
safe_con = require("../../firebird.js");
exports.ConnectionBinding = function (test) {
View
31 tests/def/test-events.js
@@ -8,14 +8,15 @@ var cfg = require("../config").cfg;
// Require modules
var
- fb_binding = require("../../build/default/binding");
+ fb_binding = require("../../firebird.js");
+
var zexports = {};
function Init()
{
- var conn = new fb_binding.Connection;
+ var conn = fb_binding.createConnection();
conn.connectSync(cfg.db, cfg.user, cfg.password, cfg.role);
conn.querySync("\
create or alter procedure DoEvent(\
@@ -28,7 +29,7 @@ function Init()
}
function Connect(){
- var conn = new fb_binding.Connection;
+ var conn = fb_binding.createConnection();
conn.connectSync(cfg.db, cfg.user, cfg.password, cfg.role);
return conn;
}
@@ -47,17 +48,27 @@ function WaitForFinish(finished,clean,timeout){
timedout = true;
},timeout);
+ /*
process.nextTick(function loop(){
if(finished.call()||timedout){
clearTimeout(tid);
clean.call();
}
else process.nextTick(loop);
- });
+ });
+ */
+ setTimeout(function loop(){
+ if(finished.call()||timedout){
+ clearTimeout(tid);
+ clean.call();
+ }
+ else setTimeout(loop,0);
+ },0);
+
}
function CleanUp(){
- var con = new fb_binding.Connection;
+ var con = fb_binding.createConnection();
con.connectSync(cfg.db, cfg.user, cfg.password, cfg.role);
con.querySync("drop procedure DoEvent;");
con.disconnect();
@@ -131,10 +142,14 @@ exports.oneEventBetween = function(test) {
conn.addFBevent(eName);
- GenEvent(eName);
+ //setTimeout(function(){
+ GenEvent(eName);
+ var z = 0;
+ for(var i=0; i< 1000000; i++) z++;
+ conn.addFBevent("strange");
+ //},0);
- conn.addFBevent("strange");
-
+
// Wait 2 sec for event
WaitForFinish(function(){ return finished; },
function(){
View
4 tests/def/test-fbres.js
@@ -8,14 +8,14 @@ var cfg = require("../config").cfg;
// Require modules
var
- fb_binding = require("../../build/default/binding");
+ fb_binding = require("../../firebird.js");
var
testCase = require("../../tools/nodeunit").testCase;
module.exports = testCase({
setUp: function(callback){
- this.conn = new fb_binding.Connection;
+ this.conn = fb_binding.createConnection();
this.conn.connectSync(cfg.db, cfg.user, cfg.password, cfg.role);
this.res = this.conn.querySync("select * from rdb$relations");
callback();
View
9 tests/def/test-sync.js
@@ -8,12 +8,13 @@ var cfg = require("../config").cfg;
// Require modules
var
- fb_binding = require("../../build/default/binding");
+ fb_binding = require("../../firebird.js");
+
exports.SyncConnection = function (test) {
test.expect(3);
- var conn = new fb_binding.Connection;
+ var conn = fb_binding.createConnection();
conn.connectSync(cfg.db, cfg.user, cfg.password, cfg.role);
test.ok(conn.connected,"Connected to database");
var res = conn.querySync("select * from rdb$relations");
@@ -24,14 +25,14 @@ exports.SyncConnection = function (test) {
};
function Connect(){
- var conn = new fb_binding.Connection;
+ var conn = fb_binding.createConnection();
conn.connectSync(cfg.db, cfg.user, cfg.password, cfg.role);
conn.querySync("create table TEST_TRANS (ID INTEGER, NAME VARCHAR(20))");
return conn;
}
function Close(conn){
conn.disconnect();
- var con = new fb_binding.Connection;
+ var con = fb_binding.createConnection();
con.connectSync(cfg.db, cfg.user, cfg.password, cfg.role);
con.querySync("drop table TEST_TRANS;");
con.disconnect();
2  tools/nodeunit
@@ -1 +1 @@
-Subproject commit 8a31df2da23f57942a305ed9e2b92bf0db19d5f7
+Subproject commit 7568b4d88f439102d7c38a68519a2d13b634c3e5
Please sign in to comment.
Something went wrong with that request. Please try again.