Commit aefb3cc4 by Orlando Vazquez

Use a linked list for `statement.step`

parent d8e7c186
...@@ -30,6 +30,24 @@ extern "C" { ...@@ -30,6 +30,24 @@ extern "C" {
using namespace v8; using namespace v8;
using namespace node; using namespace node;
struct cell_node {
void *value;
int type;
struct cell_node *next;
};
struct row_node {
struct cell_node *cells;
struct row_node *next;
};
// represent strings with this struct
struct string_t {
size_t bytes;
char data[];
};
class Statement : public EventEmitter { class Statement : public EventEmitter {
public: public:
...@@ -43,16 +61,12 @@ class Statement : public EventEmitter { ...@@ -43,16 +61,12 @@ class Statement : public EventEmitter {
Statement(sqlite3_stmt* stmt, int first_rc = -1, int mode = 0) Statement(sqlite3_stmt* stmt, int first_rc = -1, int mode = 0)
: EventEmitter(), first_rc_(first_rc), mode_(mode), stmt_(stmt) { : EventEmitter(), first_rc_(first_rc), mode_(mode), stmt_(stmt) {
column_count_ = -1; column_count_ = -1;
column_types_ = NULL;
column_names_ = NULL; column_names_ = NULL;
column_data_ = NULL;
} }
~Statement() { ~Statement() {
if (stmt_) sqlite3_finalize(stmt_); if (stmt_) sqlite3_finalize(stmt_);
if (column_types_) free(column_types_); if (column_names_) FreeColumnData();
if (column_names_) free(column_names_);
if (column_data_) FreeColumnData();
} }
static Handle<Value> Bind(const Arguments &args); static Handle<Value> Bind(const Arguments &args);
...@@ -87,14 +101,15 @@ class Statement : public EventEmitter { ...@@ -87,14 +101,15 @@ class Statement : public EventEmitter {
private: private:
int column_count_; int column_count_;
int *column_types_;
char **column_names_; char **column_names_;
void **column_data_;
bool error_; bool error_;
int first_rc_; int first_rc_;
int mode_; int mode_;
sqlite3_stmt* stmt_; sqlite3_stmt* stmt_;
// for statment.step
cell_node *cells;
}; };
// indicates the key type (integer index or name string) // indicates the key type (integer index or name string)
...@@ -128,20 +143,6 @@ struct bind_pair { ...@@ -128,20 +143,6 @@ struct bind_pair {
size_t value_size; size_t value_size;
}; };
// Results will stored in a multi-dimensional linked list.
// That is, a linked list (rows) of linked lists (row values)
// Results are composed of rows. Rows are composed of cells.
struct cell_node {
void *value;
int type;
struct cell_node *next;
};
struct row_node {
struct cell_node *cells;
struct row_node *next;
};
struct fetchall_request { struct fetchall_request {
Persistent<Function> cb; Persistent<Function> cb;
Statement *sto; Statement *sto;
...@@ -150,10 +151,4 @@ struct fetchall_request { ...@@ -150,10 +151,4 @@ struct fetchall_request {
struct row_node *rows; struct row_node *rows;
}; };
// represent strings with this struct
struct string_t {
size_t bytes;
char data[];
};
#endif #endif
var fs = require("fs"), var fs = require("fs"),
sys = require("sys"), sys = require("sys"),
sqlite = require("../sqlite"); sqlite = require("sqlite");
var puts = sys.puts; var puts = sys.puts;
var inspect = sys.inspect; var inspect = sys.inspect;
......
...@@ -25,14 +25,14 @@ function createTestTable(db, callback) { ...@@ -25,14 +25,14 @@ function createTestTable(db, callback) {
var testRows = [ [ 1, "foo", 9 ] var testRows = [ [ 1, "foo", 9 ]
, [ 2, "bar", 8 ] , [ 2, "bar", 8 ]
, [ 3, "baz", 7 ] , [ 3, null, 7 ]
, [ 4, "quux", 6 ] , [ 4, "quux", 6 ]
, [ 5, "juju", 5 ] , [ 5, "juju", null ]
]; ];
var testRowsExpected = [ { id: 5, name: 'juju', age: 5 } var testRowsExpected = [ { id: 5, name: 'juju', age: null }
, { id: 4, name: 'quux', age: 6 } , { id: 4, name: 'quux', age: 6 }
, { id: 3, name: 'baz', age: 7 } , { id: 3, name: null, age: 7 }
, { id: 2, name: 'bar', age: 8 } , { id: 2, name: 'bar', age: 8 }
, { id: 1, name: 'foo', age: 9 } , { id: 1, name: 'foo', age: 9 }
]; ];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment