SQLite

Check-in [04d4100445]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Change the name of the json_merge_patch() function to just json_patch().
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | json_mergepatch
Files: files | file ages | folders
SHA3-256: 04d4100445a3373986ee962618bc03ec304f6ba2f867c8e9eee415daffb593fc
User & Date: drh 2017-03-23 20:33:49.228
Context
2017-03-23
23:44
Add the json_patch() SQL function to the JSON1 extension. (check-in: 4760884820 user: drh tags: trunk)
20:33
Change the name of the json_merge_patch() function to just json_patch(). (Closed-Leaf check-in: 04d4100445 user: drh tags: json_mergepatch)
12:56
Avoid redundant edits in the json_merge_patch() function. (check-in: 4a8e6437dd user: drh tags: json_mergepatch)
Changes
Unified Diff Ignore Whitespace Patch
Changes to ext/misc/json1.c.
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
}

/*
** Implementation of the json_mergepatch(JSON1,JSON2) function.  Return a JSON
** object that is the result of running the RFC 7396 MergePatch() algorithm
** on the two arguments.
*/
static void jsonMergePatchFunc(
  sqlite3_context *ctx,
  int argc,
  sqlite3_value **argv
){
  JsonParse x;     /* The JSON that is being patched */
  JsonParse y;     /* The patch */
  JsonNode *pResult;   /* The result of the merge */







|







1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
}

/*
** Implementation of the json_mergepatch(JSON1,JSON2) function.  Return a JSON
** object that is the result of running the RFC 7396 MergePatch() algorithm
** on the two arguments.
*/
static void jsonPatchFunc(
  sqlite3_context *ctx,
  int argc,
  sqlite3_value **argv
){
  JsonParse x;     /* The JSON that is being patched */
  JsonParse y;     /* The patch */
  JsonNode *pResult;   /* The result of the merge */
2256
2257
2258
2259
2260
2261
2262
2263
2264

2265
2266
2267
2268
2269
2270
2271
  } aFunc[] = {
    { "json",                 1, 0,   jsonRemoveFunc        },
    { "json_array",          -1, 0,   jsonArrayFunc         },
    { "json_array_length",    1, 0,   jsonArrayLengthFunc   },
    { "json_array_length",    2, 0,   jsonArrayLengthFunc   },
    { "json_extract",        -1, 0,   jsonExtractFunc       },
    { "json_insert",         -1, 0,   jsonSetFunc           },
    { "json_merge_patch",     2, 0,   jsonMergePatchFunc    },
    { "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           },
    { "json_type",            1, 0,   jsonTypeFunc          },
    { "json_type",            2, 0,   jsonTypeFunc          },
    { "json_valid",           1, 0,   jsonValidFunc         },







<

>







2256
2257
2258
2259
2260
2261
2262

2263
2264
2265
2266
2267
2268
2269
2270
2271
  } aFunc[] = {
    { "json",                 1, 0,   jsonRemoveFunc        },
    { "json_array",          -1, 0,   jsonArrayFunc         },
    { "json_array_length",    1, 0,   jsonArrayLengthFunc   },
    { "json_array_length",    2, 0,   jsonArrayLengthFunc   },
    { "json_extract",        -1, 0,   jsonExtractFunc       },
    { "json_insert",         -1, 0,   jsonSetFunc           },

    { "json_object",         -1, 0,   jsonObjectFunc        },
    { "json_patch",           2, 0,   jsonPatchFunc         },
    { "json_quote",           1, 0,   jsonQuoteFunc         },
    { "json_remove",         -1, 0,   jsonRemoveFunc        },
    { "json_replace",        -1, 0,   jsonReplaceFunc       },
    { "json_set",            -1, 1,   jsonSetFunc           },
    { "json_type",            1, 0,   jsonTypeFunc          },
    { "json_type",            2, 0,   jsonTypeFunc          },
    { "json_valid",           1, 0,   jsonValidFunc         },
Changes to test/json104.test.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# 2017-03-22
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements tests for json_mergepatch(A,B) SQL function.
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl

ifcapable !json1 {
  finish_test
  return
}

# This is the example from pages 2 and 3 of RFC-7396
do_execsql_test json104-100 {
  SELECT json_merge_patch('{
       "a": "b",
       "c": {
         "d": "e",
         "f": "g"
       }
     }','{
       "a":"z",
       "c": {
         "f": null
       }
     }');
} {{{"a":"z","c":{"d":"e"}}}}


# This is the example from pages 4 and 5 of RFC-7396 
do_execsql_test json104-110 {
  SELECT json_merge_patch('{
       "title": "Goodbye!",
       "author" : {
         "givenName" : "John",
         "familyName" : "Doe"
       },
       "tags":[ "example", "sample" ],
       "content": "This will be unchanged"
     }','{
       "title": "Hello!",
       "phoneNumber": "+01-123-456-7890",
       "author": {
         "familyName": null
       },
       "tags": [ "example" ]
     }');
} {{{"title":"Hello!","author":{"givenName":"John"},"tags":["example"],"content":"This will be unchanged","phoneNumber":"+01-123-456-7890"}}}

do_execsql_test json104-200 {
  SELECT json_merge_patch('[1,2,3]','{"x":null}');
} {{{}}}
do_execsql_test json104-210 {
  SELECT json_merge_patch('[1,2,3]','{"x":null,"y":1,"z":null}');
} {{{"y":1}}}

finish_test










|












|
















|


















|


|



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# 2017-03-22
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements tests for json_patch(A,B) SQL function.
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl

ifcapable !json1 {
  finish_test
  return
}

# This is the example from pages 2 and 3 of RFC-7396
do_execsql_test json104-100 {
  SELECT json_patch('{
       "a": "b",
       "c": {
         "d": "e",
         "f": "g"
       }
     }','{
       "a":"z",
       "c": {
         "f": null
       }
     }');
} {{{"a":"z","c":{"d":"e"}}}}


# This is the example from pages 4 and 5 of RFC-7396 
do_execsql_test json104-110 {
  SELECT json_patch('{
       "title": "Goodbye!",
       "author" : {
         "givenName" : "John",
         "familyName" : "Doe"
       },
       "tags":[ "example", "sample" ],
       "content": "This will be unchanged"
     }','{
       "title": "Hello!",
       "phoneNumber": "+01-123-456-7890",
       "author": {
         "familyName": null
       },
       "tags": [ "example" ]
     }');
} {{{"title":"Hello!","author":{"givenName":"John"},"tags":["example"],"content":"This will be unchanged","phoneNumber":"+01-123-456-7890"}}}

do_execsql_test json104-200 {
  SELECT json_patch('[1,2,3]','{"x":null}');
} {{{}}}
do_execsql_test json104-210 {
  SELECT json_patch('[1,2,3]','{"x":null,"y":1,"z":null}');
} {{{"y":1}}}

finish_test