diff options
author | drh <drh@noemail.net> | 2016-06-17 13:01:51 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2016-06-17 13:01:51 +0000 |
commit | 2ad96f5880fd77919571477dc0302cf763e527ff (patch) | |
tree | 78c3435f9f829d423521be840386cd8f3e13e3f4 /ext/misc/json1.c | |
parent | 3480bfdae9523d3b2e67c4b594e79bab6ca7776b (diff) | |
download | sqlite-2ad96f5880fd77919571477dc0302cf763e527ff.tar.gz sqlite-2ad96f5880fd77919571477dc0302cf763e527ff.zip |
Add the json_quote() function to the JSON1 extension.
FossilOrigin-Name: 2c3714aebf5e40e3728877a235b3c1f93defa33e
Diffstat (limited to 'ext/misc/json1.c')
-rw-r--r-- | ext/misc/json1.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/ext/misc/json1.c b/ext/misc/json1.c index 99d299c29..a9452b019 100644 --- a/ext/misc/json1.c +++ b/ext/misc/json1.c @@ -1212,6 +1212,25 @@ static void jsonTest1Func( ****************************************************************************/ /* +** Implementation of the json_QUOTE(VALUE) function. Return a JSON value +** corresponding to the SQL value input. Mostly this means putting +** double-quotes around strings and returning the unquoted string "null" +** when given a NULL input. +*/ +static void jsonQuoteFunc( + sqlite3_context *ctx, + int argc, + sqlite3_value **argv +){ + JsonString jx; + + jsonInit(&jx, ctx); + jsonAppendValue(&jx, argv[0]); + jsonResult(&jx); + sqlite3_result_subtype(ctx, JSON_SUBTYPE); +} + +/* ** Implementation of the json_array(VALUE,...) function. Return a JSON ** array that contains all values given in arguments. Or if any argument ** is a BLOB, throw an error. @@ -2124,6 +2143,7 @@ int sqlite3Json1Init(sqlite3 *db){ { "json_extract", -1, 0, jsonExtractFunc }, { "json_insert", -1, 0, jsonSetFunc }, { "json_object", -1, 0, jsonObjectFunc }, + { "json_quote", 1, 0, jsonQuoteFunc }, { "json_remove", -1, 0, jsonRemoveFunc }, { "json_replace", -1, 0, jsonReplaceFunc }, { "json_set", -1, 1, jsonSetFunc }, |