Added a database exchange operation, and some context when uploading a file.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3865 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
42fcfee042
commit
d802c0023b
@ -637,7 +637,7 @@ function message(event) {
|
|||||||
return response.text();
|
return response.text();
|
||||||
}).then(function(text) {
|
}).then(function(text) {
|
||||||
var iframe = document.getElementById("document");
|
var iframe = document.getElementById("document");
|
||||||
iframe.contentWindow.postMessage({'storeBlobComplete': {name: event.data.blob.name, path: text, type: event.data.blob.type}}, '*');
|
iframe.contentWindow.postMessage({'storeBlobComplete': {name: event.data.blob.name, path: text, type: event.data.blob.type, context: event.data.context}}, '*');
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
send({event: "message", message: event.data});
|
send({event: "message", message: event.data});
|
||||||
|
@ -149,7 +149,27 @@ static JSValue _database_exchange(JSContext* context, JSValueConst this_val, int
|
|||||||
if (database)
|
if (database)
|
||||||
{
|
{
|
||||||
sqlite3_stmt* statement;
|
sqlite3_stmt* statement;
|
||||||
if (sqlite3_prepare(database->db, "UPDATE properties SET value = $1 WHERE id = $2 AND key = $3 AND value = $4", -1, &statement, NULL) == SQLITE_OK)
|
if (JS_IsNull(argv[1]) || JS_IsUndefined(argv[1]))
|
||||||
|
{
|
||||||
|
if (sqlite3_prepare(database->db, "INSERT INTO properties (id, key, value) VALUES ($1, $2, $3) ON CONFLICT DO NOTHING", -1, &statement, NULL) == SQLITE_OK)
|
||||||
|
{
|
||||||
|
size_t key_length;
|
||||||
|
size_t set_length;
|
||||||
|
const char* key = JS_ToCStringLen(context, &key_length, argv[0]);
|
||||||
|
const char* set = JS_ToCStringLen(context, &set_length, argv[2]);
|
||||||
|
if (sqlite3_bind_text(statement, 1, database->id, -1, NULL) == SQLITE_OK &&
|
||||||
|
sqlite3_bind_text(statement, 2, key, key_length, NULL) == SQLITE_OK &&
|
||||||
|
sqlite3_bind_text(statement, 3, set, set_length, NULL) == SQLITE_OK &&
|
||||||
|
sqlite3_step(statement) == SQLITE_DONE)
|
||||||
|
{
|
||||||
|
exchanged = sqlite3_changes(database->db) != 0 ? JS_TRUE : JS_FALSE;
|
||||||
|
}
|
||||||
|
JS_FreeCString(context, key);
|
||||||
|
JS_FreeCString(context, set);
|
||||||
|
sqlite3_finalize(statement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (sqlite3_prepare(database->db, "UPDATE properties SET value = $1 WHERE id = $2 AND key = $3 AND value = $4", -1, &statement, NULL) == SQLITE_OK)
|
||||||
{
|
{
|
||||||
size_t key_length;
|
size_t key_length;
|
||||||
size_t expected_length;
|
size_t expected_length;
|
||||||
@ -166,6 +186,8 @@ static JSValue _database_exchange(JSContext* context, JSValueConst this_val, int
|
|||||||
exchanged = sqlite3_changes(database->db) != 0 ? JS_TRUE : JS_FALSE;
|
exchanged = sqlite3_changes(database->db) != 0 ? JS_TRUE : JS_FALSE;
|
||||||
}
|
}
|
||||||
JS_FreeCString(context, key);
|
JS_FreeCString(context, key);
|
||||||
|
JS_FreeCString(context, expected);
|
||||||
|
JS_FreeCString(context, set);
|
||||||
sqlite3_finalize(statement);
|
sqlite3_finalize(statement);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user