Skip to content

Commit

Permalink
Added error handling to Statement::FetchAll.
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Ashley committed Jan 29, 2011
1 parent 409251a commit 937902d
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/statement.cc
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ int Statement::EIO_AfterFetchAll(eio_req *req) {

Local<Value> argv[2];

if (req->result) {
if (fetchall_req->error != NULL) {
argv[0] = Exception::Error(String::New(fetchall_req->error));
argv[1] = Local<Value>::New(Undefined());
}
Expand Down Expand Up @@ -787,7 +787,7 @@ int Statement::EIO_AfterFetchAll(eio_req *req) {
// tot_alloced_p
// );

if (fetchall_req->rows) {
if (fetchall_req->pool) {
int ret = mpool_close(fetchall_req->pool);
if (ret != MPOOL_ERROR_NONE) {
req->result = -1;
Expand Down Expand Up @@ -824,7 +824,7 @@ int Statement::EIO_FetchAll(eio_req *req) {

int rc = sqlite3_step(stmt);

if (rc == SQLITE_ROW) {
if (rc != SQLITE_DONE) {
/* open the pool */
fetchall_req->pool = mpool_open(MPOOL_FLAG_USE_MAP_ANON
, 0
Expand All @@ -850,7 +850,6 @@ int Statement::EIO_FetchAll(eio_req *req) {

for (;; rc = sqlite3_step(stmt)) {
if (rc != SQLITE_ROW) break;
// TODO: test for != SQLITE_ROW (errors)

if (!sto->column_names_) {
sto->InitializeColumns();
Expand Down Expand Up @@ -929,6 +928,23 @@ int Statement::EIO_FetchAll(eio_req *req) {
prev = cur;
}

// Test for errors
if (rc != SQLITE_DONE) {
const char *error = sqlite3_errmsg(sqlite3_db_handle(sto->stmt_));
if (error == NULL) {
error = "Unknown Error";
}
size_t errorSize = sizeof(char) * (strlen(error) + 1);
fetchall_req->error = (char *)mpool_alloc(fetchall_req->pool, errorSize, &ret);
if (fetchall_req->error != NULL) {
memcpy(fetchall_req->error, error, errorSize);
} else {
fetchall_req->error = (char *) mpool_strerror(ret);
}
req->result = -1;
return 0;
}

req->result = 0;
fetchall_req->rows = head;

Expand Down

0 comments on commit 937902d

Please sign in to comment.