Commit a3db51bf by Orlando Vazquez

Don't bother to create a memory pool if there are no results

parent ac7dbadf
...@@ -785,12 +785,15 @@ int Statement::EIO_AfterFetchAll(eio_req *req) { ...@@ -785,12 +785,15 @@ int Statement::EIO_AfterFetchAll(eio_req *req) {
// max_alloced_p, // max_alloced_p,
// tot_alloced_p // tot_alloced_p
// ); // );
if (fetchall_req->rows) {
int ret = mpool_close(fetchall_req->pool); int ret = mpool_close(fetchall_req->pool);
if (ret != MPOOL_ERROR_NONE) { if (ret != MPOOL_ERROR_NONE) {
req->result = -1; req->result = -1;
argv[0] = Exception::Error(String::New(mpool_strerror(ret))); argv[0] = Exception::Error(String::New(mpool_strerror(ret)));
argv[1] = Local<Value>::New(Undefined()); argv[1] = Local<Value>::New(Undefined());
} }
}
TryCatch try_catch; TryCatch try_catch;
...@@ -834,25 +837,24 @@ int Statement::EIO_FetchAll(eio_req *req) { ...@@ -834,25 +837,24 @@ int Statement::EIO_FetchAll(eio_req *req) {
, *prev = NULL , *prev = NULL
, *head = NULL; , *head = NULL;
while (1) { for (;; rc = sqlite3_step(stmt)) {
int rc = sqlite3_step(stmt); if (rc != SQLITE_ROW) break;
// TODO: test for != SQLITE_ROW (errors)
if (rc == SQLITE_DONE) {
break;
}
if (!sto->column_names_) { if (!sto->column_names_) {
sto->InitializeColumns(); sto->InitializeColumns();
} }
cur = (struct row_node *) mpool_alloc(fetchall_req->pool cur = (struct row_node *) mpool_alloc
( fetchall_req->pool
, sizeof(struct row_node) , sizeof(struct row_node)
, &ret); , &ret
);
cur->next = NULL; cur->next = NULL;
// If this is the first row, set head to cur and hold it there since it // If this is the first row, assign `cur` to `head` and `hold` head there
// was the first result. Otherwise set the `next` field on the `prev` // since it was the first result. Otherwise set the `next` field on
// pointer to attach the newly allocated element. // the`prev` pointer to attach the newly allocated element.
(!head ? head : prev->next) = cur; (!head ? head : prev->next) = cur;
struct cell_node *cell_head = NULL struct cell_node *cell_head = NULL
...@@ -863,14 +865,13 @@ int Statement::EIO_FetchAll(eio_req *req) { ...@@ -863,14 +865,13 @@ int Statement::EIO_FetchAll(eio_req *req) {
cell = (struct cell_node *) cell = (struct cell_node *)
mpool_alloc(fetchall_req->pool, sizeof(struct cell_node), &ret); mpool_alloc(fetchall_req->pool, sizeof(struct cell_node), &ret);
// If this is the first cell, set cell_head to cell and hold it there // Same as above with the row linked list.
// since it was the first result. Otherwise set the `next` field on the
// `prev` pointer to attach the newly allocated element.
(!cell_head ? cell_head : cell_prev->next) = cell; (!cell_head ? cell_head : cell_prev->next) = cell;
cell->type = sqlite3_column_type(sto->stmt_, i); cell->type = sqlite3_column_type(sto->stmt_, i);
cell->next = NULL; cell->next = NULL;
// TODO: Cache column data in the fetchall req struct.
switch (cell->type) { switch (cell->type) {
case SQLITE_INTEGER: case SQLITE_INTEGER:
cell->value = (int *) cell->value = (int *)
......
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