Finish writing this code. Yep.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4174 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
a5f9f927e6
commit
fa87462405
25
src/ssb.js.c
25
src/ssb.js.c
@ -382,6 +382,7 @@ static void _tf_ssb_sqlAsync_work(uv_work_t* work)
|
|||||||
memcpy(&length, p, sizeof(length));
|
memcpy(&length, p, sizeof(length));
|
||||||
p += sizeof(length);
|
p += sizeof(length);
|
||||||
sqlite3_bind_text(statement, column + 1, (const char*)p, length, NULL);
|
sqlite3_bind_text(statement, column + 1, (const char*)p, length, NULL);
|
||||||
|
p += length;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SQLITE_NULL:
|
case SQLITE_NULL:
|
||||||
@ -525,9 +526,6 @@ static void _tf_ssb_sqlAsync_after_work(uv_work_t* work, int status)
|
|||||||
static JSValue _tf_ssb_sqlAsync(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
|
static JSValue _tf_ssb_sqlAsync(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
|
||||||
{
|
{
|
||||||
tf_ssb_t* ssb = JS_GetOpaque(this_val, _tf_ssb_classId);
|
tf_ssb_t* ssb = JS_GetOpaque(this_val, _tf_ssb_classId);
|
||||||
JSValue result = JS_UNDEFINED;
|
|
||||||
if (ssb)
|
|
||||||
{
|
|
||||||
const char* query = JS_ToCString(context, argv[0]);
|
const char* query = JS_ToCString(context, argv[0]);
|
||||||
sql_work_t* work = tf_malloc(sizeof(sql_work_t));
|
sql_work_t* work = tf_malloc(sizeof(sql_work_t));
|
||||||
*work = (sql_work_t)
|
*work = (sql_work_t)
|
||||||
@ -540,7 +538,10 @@ static JSValue _tf_ssb_sqlAsync(JSContext* context, JSValueConst this_val, int a
|
|||||||
.callback = JS_DupValue(context, argv[2]),
|
.callback = JS_DupValue(context, argv[2]),
|
||||||
.query = query,
|
.query = query,
|
||||||
};
|
};
|
||||||
result = JS_NewPromiseCapability(context, work->promise);
|
JSValue result = JS_NewPromiseCapability(context, work->promise);
|
||||||
|
JSValue error_value = JS_UNDEFINED;
|
||||||
|
if (ssb)
|
||||||
|
{
|
||||||
int32_t length = tf_util_get_length(context, argv[1]);
|
int32_t length = tf_util_get_length(context, argv[1]);
|
||||||
for (int i = 0; i < length; i++)
|
for (int i = 0; i < length; i++)
|
||||||
{
|
{
|
||||||
@ -560,7 +561,7 @@ static JSValue _tf_ssb_sqlAsync(JSContext* context, JSValueConst this_val, int a
|
|||||||
_tf_ssb_sql_append(&work->binds, &work->binds_count, &type, sizeof(type));
|
_tf_ssb_sql_append(&work->binds, &work->binds_count, &type, sizeof(type));
|
||||||
_tf_ssb_sql_append(&work->binds, &work->binds_count, &number, sizeof(number));
|
_tf_ssb_sql_append(&work->binds, &work->binds_count, &number, sizeof(number));
|
||||||
}
|
}
|
||||||
else if (JS_IsNumber(value))
|
else if (JS_IsNull(value))
|
||||||
{
|
{
|
||||||
uint8_t type = SQLITE_NULL;
|
uint8_t type = SQLITE_NULL;
|
||||||
_tf_ssb_sql_append(&work->binds, &work->binds_count, &type, sizeof(type));
|
_tf_ssb_sql_append(&work->binds, &work->binds_count, &type, sizeof(type));
|
||||||
@ -575,6 +576,7 @@ static JSValue _tf_ssb_sqlAsync(JSContext* context, JSValueConst this_val, int a
|
|||||||
string = "";
|
string = "";
|
||||||
}
|
}
|
||||||
_tf_ssb_sql_append(&work->binds, &work->binds_count, &type, sizeof(type));
|
_tf_ssb_sql_append(&work->binds, &work->binds_count, &type, sizeof(type));
|
||||||
|
_tf_ssb_sql_append(&work->binds, &work->binds_count, &length, sizeof(length));
|
||||||
_tf_ssb_sql_append(&work->binds, &work->binds_count, string, length);
|
_tf_ssb_sql_append(&work->binds, &work->binds_count, string, length);
|
||||||
JS_FreeCString(context, string);
|
JS_FreeCString(context, string);
|
||||||
}
|
}
|
||||||
@ -582,18 +584,21 @@ static JSValue _tf_ssb_sqlAsync(JSContext* context, JSValueConst this_val, int a
|
|||||||
int r = uv_queue_work(tf_ssb_get_loop(ssb), &work->request, _tf_ssb_sqlAsync_work, _tf_ssb_sqlAsync_after_work);
|
int r = uv_queue_work(tf_ssb_get_loop(ssb), &work->request, _tf_ssb_sqlAsync_work, _tf_ssb_sqlAsync_after_work);
|
||||||
if (r)
|
if (r)
|
||||||
{
|
{
|
||||||
JSValue error = JS_ThrowInternalError(context, "uv_queue_work failed: %s", uv_strerror(r));
|
error_value = JS_ThrowInternalError(context, "uv_queue_work failed: %s", uv_strerror(r));
|
||||||
JSValue result = JS_Call(context, work->promise[1], JS_UNDEFINED, 1, &error);
|
}
|
||||||
tf_util_report_error(context, result);
|
}
|
||||||
|
if (!JS_IsUndefined(error_value))
|
||||||
|
{
|
||||||
|
JSValue call_result = JS_Call(context, work->promise[1], JS_UNDEFINED, 1, &error_value);
|
||||||
|
tf_util_report_error(context, call_result);
|
||||||
JS_FreeValue(context, work->promise[0]);
|
JS_FreeValue(context, work->promise[0]);
|
||||||
JS_FreeValue(context, work->promise[1]);
|
JS_FreeValue(context, work->promise[1]);
|
||||||
JS_FreeValue(context, work->callback);
|
JS_FreeValue(context, work->callback);
|
||||||
JS_FreeValue(context, error);
|
JS_FreeValue(context, error_value);
|
||||||
JS_FreeCString(context, query);
|
JS_FreeCString(context, query);
|
||||||
tf_free(work->binds);
|
tf_free(work->binds);
|
||||||
tf_free(work);
|
tf_free(work);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user