forked from cory/tildefriends
Made sure that SQL errors make it to the client.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3867 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
15
src/ssb.db.c
15
src/ssb.db.c
@ -526,17 +526,19 @@ static int _tf_ssb_sqlite_authorizer(void* user_data, int action_code, const cha
|
||||
return SQLITE_DENY;
|
||||
}
|
||||
|
||||
void tf_ssb_db_visit_query(tf_ssb_t* ssb, const char* query, const JSValue binds, void (*callback)(JSValue row, void* user_data), void* user_data)
|
||||
JSValue tf_ssb_db_visit_query(tf_ssb_t* ssb, const char* query, const JSValue binds, void (*callback)(JSValue row, void* user_data), void* user_data)
|
||||
{
|
||||
JSValue result = JS_UNDEFINED;
|
||||
sqlite3* db = tf_ssb_get_db(ssb);
|
||||
JSContext* context = tf_ssb_get_context(ssb);
|
||||
sqlite3_stmt* statement;
|
||||
sqlite3_set_authorizer(db, _tf_ssb_sqlite_authorizer, ssb);
|
||||
if (sqlite3_prepare(db, query, -1, &statement, NULL) == SQLITE_OK)
|
||||
{
|
||||
JSContext* context = tf_ssb_get_context(ssb);
|
||||
if (_tf_ssb_sqlite_bind_json(context, db, statement, binds))
|
||||
{
|
||||
while (sqlite3_step(statement) == SQLITE_ROW)
|
||||
int r = SQLITE_OK;
|
||||
while ((r = sqlite3_step(statement)) == SQLITE_ROW)
|
||||
{
|
||||
JSValue row = _tf_ssb_sqlite_row_to_json(context, statement);
|
||||
tf_trace_t* trace = tf_ssb_get_trace(ssb);
|
||||
@ -545,14 +547,19 @@ void tf_ssb_db_visit_query(tf_ssb_t* ssb, const char* query, const JSValue binds
|
||||
tf_trace_end(trace);
|
||||
JS_FreeValue(context, row);
|
||||
}
|
||||
if (r != SQLITE_DONE)
|
||||
{
|
||||
result = JS_ThrowInternalError(context, "SQL Error %s: running \"%s\".", sqlite3_errmsg(db), query);
|
||||
}
|
||||
}
|
||||
sqlite3_finalize(statement);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("prepare failed: %s: %s\n", sqlite3_errmsg(db), query);
|
||||
result = JS_ThrowInternalError(context, "SQL Error %s: preparing \"%s\".", sqlite3_errmsg(db), query);
|
||||
}
|
||||
sqlite3_set_authorizer(db, NULL, NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
static JSValue _tf_ssb_format_message(JSContext* context, const char* previous, const char* author, int64_t sequence, double timestamp, const char* hash, const char* content, const char* signature, bool sequence_before_author)
|
||||
|
Reference in New Issue
Block a user