Fixed apps not working most of the time. Ultimately, storing a pointer to the database using JS_NewInt64 was lossy and a bad idea. Also, remove use of JNI since we're only starting tildefriends as its own process now.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4215 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
@ -2,6 +2,8 @@
|
||||
|
||||
#include "log.h"
|
||||
#include "mem.h"
|
||||
#include "ssb.h"
|
||||
#include "task.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
@ -31,7 +33,7 @@ static JSValue _database_get_all(JSContext* context, JSValueConst this_val, int
|
||||
static JSValue _database_get_like(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv);
|
||||
static JSValue _databases_list(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv, int magic, JSValue* data);
|
||||
|
||||
void tf_database_register(JSContext* context, sqlite3* sqlite)
|
||||
void tf_database_register(JSContext* context)
|
||||
{
|
||||
JS_NewClassID(&_database_class_id);
|
||||
JSClassDef def =
|
||||
@ -45,13 +47,12 @@ void tf_database_register(JSContext* context, sqlite3* sqlite)
|
||||
}
|
||||
|
||||
JSValue global = JS_GetGlobalObject(context);
|
||||
JSValue data[] = { JS_NewInt64(context, (int64_t)(intptr_t)sqlite) };
|
||||
JSValue constructor = JS_NewCFunctionData(context, _database_create, 0, 0, 1, data);
|
||||
JSValue constructor = JS_NewCFunctionData(context, _database_create, 0, 0, 0, NULL);
|
||||
JS_SetConstructorBit(context, constructor, true);
|
||||
JS_SetPropertyStr(context, global, "Database", constructor);
|
||||
JSValue databases = JS_NewObject(context);
|
||||
JS_SetPropertyStr(context, global, "databases", databases);
|
||||
JS_SetPropertyStr(context, databases, "list", JS_NewCFunctionData(context, _databases_list, 0, 0, 1, data));
|
||||
JS_SetPropertyStr(context, databases, "list", JS_NewCFunctionData(context, _databases_list, 0, 0, 0, NULL));
|
||||
JS_FreeValue(context, global);
|
||||
}
|
||||
|
||||
@ -60,9 +61,8 @@ static JSValue _database_create(JSContext* context, JSValueConst this_val, int a
|
||||
++_database_count;
|
||||
JSValue object = JS_NewObjectClass(context, _database_class_id);
|
||||
|
||||
int64_t value = 0;
|
||||
JS_ToInt64(context, &value, data[0]);
|
||||
sqlite3* db = (sqlite3*)(intptr_t)value;
|
||||
tf_task_t* task = tf_task_get(context);
|
||||
sqlite3* db = tf_ssb_get_db(tf_task_get_ssb(task));
|
||||
|
||||
database_t* database = tf_malloc(sizeof(database_t));
|
||||
*database = (database_t)
|
||||
@ -105,7 +105,7 @@ static JSValue _database_get(JSContext* context, JSValueConst this_val, int argc
|
||||
if (database)
|
||||
{
|
||||
sqlite3_stmt* statement;
|
||||
if (sqlite3_prepare(database->db, "SELECT value FROM properties WHERE id = $1 AND key = $2", -1, &statement, NULL) == SQLITE_OK)
|
||||
if (sqlite3_prepare(database->db, "SELECT value FROM properties WHERE id = ? AND key = ?", -1, &statement, NULL) == SQLITE_OK)
|
||||
{
|
||||
size_t length;
|
||||
const char* keyString = JS_ToCStringLen(context, &length, argv[0]);
|
||||
@ -278,9 +278,8 @@ JSValue _database_get_like(JSContext* context, JSValueConst this_val, int argc,
|
||||
|
||||
static JSValue _databases_list(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv, int magic, JSValue* data)
|
||||
{
|
||||
int64_t value = 0;
|
||||
JS_ToInt64(context, &value, data[0]);
|
||||
sqlite3* db = (sqlite3*)(intptr_t)value;
|
||||
tf_task_t* task = tf_task_get(context);
|
||||
sqlite3* db = tf_ssb_get_db(tf_task_get_ssb(task));
|
||||
|
||||
JSValue array = JS_UNDEFINED;
|
||||
sqlite3_stmt* statement;
|
||||
|
Reference in New Issue
Block a user