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

With this fixes sqlite should work with new nodes. #36

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
build/
.lock-wscript
sqlite3_bindings.node
deps/mpool-2.1.0/libmpool.a
deps/mpool-2.1.0/mpool.o
81 changes: 81 additions & 0 deletions node_modules/extend/index.js

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

18 changes: 18 additions & 0 deletions node_modules/extend/package.json

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

5 changes: 4 additions & 1 deletion sqlite.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

var sys = require("sys");
var sqlite = require("./sqlite3_bindings");
var event = require('events');
var extend = require ('extend');

var Database = exports.Database = function () {
var self = this;
Expand All @@ -32,6 +33,8 @@ Database.prototype = {
constructor: Database,
};

extend (true, Database.prototype, new event.EventEmitter ());

Database.prototype.query = function(sql, bindings, rowCallback) {
var self = this;

Expand Down
29 changes: 12 additions & 17 deletions src/database.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <string.h>
#include <v8.h>
#include <node.h>
#include <node_events.h>
//#include <node_events.h>

#include "sqlite3_bindings.h"
#include "database.h"
Expand All @@ -32,7 +32,7 @@ void Database::Init(v8::Handle<Object> target) {
Local<FunctionTemplate> t = FunctionTemplate::New(New);

constructor_template = Persistent<FunctionTemplate>::New(t);
constructor_template->Inherit(EventEmitter::constructor_template);
// constructor_template->Inherit(EventEmitter::constructor_template);
constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
constructor_template->SetClassName(String::NewSymbol("Database"));

Expand All @@ -59,6 +59,7 @@ Handle<Value> Database::New(const Arguments& args) {
return args.This();
}


int Database::EIO_AfterOpen(eio_req *req) {
ev_unref(EV_DEFAULT_UC);
HandleScope scope;
Expand All @@ -80,15 +81,16 @@ int Database::EIO_AfterOpen(eio_req *req) {
FatalException(try_catch);
}

open_req->dbo->Emit(String::New("ready"), 0, NULL);
//v8::Local<v8::String> event(String::New("ready"));
open_req->dbo->Emit("ready", 0, NULL);
open_req->cb.Dispose();

free(open_req);

return 0;
}

int Database::EIO_Open(eio_req *req) {
void Database::EIO_Open(eio_req *req) {
struct open_request *open_req = (struct open_request *)(req->data);

sqlite3 **dbptr = open_req->dbo->GetDBPtr();
Expand All @@ -109,8 +111,6 @@ int Database::EIO_Open(eio_req *req) {
// sqlite3_commit_hook(db, CommitHook, open_req->dbo);
// sqlite3_rollback_hook(db, RollbackHook, open_req->dbo);
// sqlite3_update_hook(db, UpdateHook, open_req->dbo);

return 0;
}

Handle<Value> Database::Open(const Arguments& args) {
Expand Down Expand Up @@ -172,12 +172,11 @@ int Database::EIO_AfterClose(eio_req *req) {
return 0;
}

int Database::EIO_Close(eio_req *req) {
void Database::EIO_Close(eio_req *req) {
struct close_request *close_req = (struct close_request *)(req->data);
Database* dbo = close_req->dbo;
req->result = sqlite3_close(dbo->db_);
dbo->db_ = NULL;
return 0;
}

Handle<Value> Database::Close(const Arguments& args) {
Expand Down Expand Up @@ -299,11 +298,11 @@ int Database::EIO_AfterPrepareAndStep(eio_req *req) {

prep_req->cb.Dispose();
free(prep_req);

return 0;
}

int Database::EIO_PrepareAndStep(eio_req *req) {
void Database::EIO_PrepareAndStep(eio_req *req) {
struct prepare_request *prep_req = (struct prepare_request *)(req->data);

prep_req->stmt = NULL;
Expand Down Expand Up @@ -340,8 +339,6 @@ int Database::EIO_PrepareAndStep(eio_req *req) {
prep_req->lastInsertId = sqlite3_last_insert_rowid(db);
if (prep_req->mode & EXEC_AFFECTED_ROWS)
prep_req->affectedRows = sqlite3_changes(db);

return 0;
}

Handle<Value> Database::PrepareAndStep(const Arguments& args) {
Expand Down Expand Up @@ -416,10 +413,10 @@ int Database::EIO_AfterPrepare(eio_req *req) {

prep_req->cb.Dispose();
free(prep_req);

return 0;
}
int Database::EIO_Prepare(eio_req *req) {
void Database::EIO_Prepare(eio_req *req) {
struct prepare_request *prep_req = (struct prepare_request *)(req->data);

prep_req->stmt = NULL;
Expand All @@ -439,8 +436,6 @@ int Database::EIO_Prepare(eio_req *req) {
prep_req->lastInsertId = sqlite3_last_insert_rowid(db);
if (prep_req->mode & EXEC_AFFECTED_ROWS)
prep_req->affectedRows = sqlite3_changes(db);

return 0;
}

// Statement#prepare(sql, [ options ,] callback);
Expand Down
13 changes: 7 additions & 6 deletions src/database.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

#include <v8.h>
#include <node.h>
#include <node_events.h>

#include <node_object_wrap.h>
#include "events.h"
#include <sqlite3.h>

using namespace v8;
using namespace node;
using namespace node_db;

class Database : public EventEmitter {
public:
Expand All @@ -42,20 +43,20 @@ class Database : public EventEmitter {
static Handle<Value> New(const Arguments& args);

static int EIO_AfterOpen(eio_req *req);
static int EIO_Open(eio_req *req);
static void EIO_Open(eio_req *req);
static Handle<Value> Open(const Arguments& args);

static int EIO_AfterClose(eio_req *req);
static int EIO_Close(eio_req *req);
static void EIO_Close(eio_req *req);
static Handle<Value> Close(const Arguments& args);

// static Handle<Value> LastInsertRowid(const Arguments& args);
static int EIO_AfterPrepareAndStep(eio_req *req);
static int EIO_PrepareAndStep(eio_req *req);
static void EIO_PrepareAndStep(eio_req *req);
static Handle<Value> PrepareAndStep(const Arguments& args);

static int EIO_AfterPrepare(eio_req *req);
static int EIO_Prepare(eio_req *req);
static void EIO_Prepare(eio_req *req);
static Handle<Value> Prepare(const Arguments& args);

// Return a pointer to the Sqlite handle pointer so that EIO_Open can
Expand Down
29 changes: 29 additions & 0 deletions src/events.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2011 Mariano Iglesias <[email protected]>
#include "./events.h"

node_db::EventEmitter::EventEmitter() : node::ObjectWrap() {
}

void node_db::EventEmitter::Init() {
}

bool node_db::EventEmitter::Emit(const char* event, int argc, v8::Handle<v8::Value> argv[]) {
v8::HandleScope scope;

int nArgc = argc + 1;
v8::Handle<v8::Value>* nArgv = new v8::Handle<v8::Value>[nArgc];
if (nArgv == NULL) {
return false;
}

nArgv[0] = v8::String::New(event);
for (int i=0; i < argc; i++) {
nArgv[i + 1] = argv[i];
}

node::MakeCallback(this->handle_, "emit", nArgc, nArgv);

delete [] nArgv;

return true;
}
21 changes: 21 additions & 0 deletions src/events.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2011 Mariano Iglesias <[email protected]>
#ifndef EVENTS_H_
#define EVENTS_H_

#include <v8.h>
#include <node_object_wrap.h>
#include <node_version.h>
#include "./node_defs.h"

namespace node_db {
class EventEmitter : public node::ObjectWrap {
public:
static void Init();

protected:
EventEmitter();
bool Emit(const char* event, int argc, v8::Handle<v8::Value> argv[]);
};
}

#endif // BINDING_H_
Loading