SQLite

Check-in [e5099c54]
Login

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

Overview
Comment:Fix a JSON bug introduced by the optimization of [df099ad713011b67] and first appearing in 3.43.0. The problem occurs when doing a JSON_EXTRACT() on an array element that was added by JSON_SET() without first reparsing. Reported by forum post fc0e3f1e2a.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: e5099c549a1d8959d4015516f090b8e6438e517a64b20651175bf5413d94fb58
User & Date: drh 2023-10-17 13:41:41
Context
2023-10-17
17:53
Changes to sqlite3IntFloatCompare() in an attempt to better measure branch coverage in the face of aggressive compiler optimization. (check-in: 5781d043 user: drh tags: trunk)
13:47
Fix a JSON bug introduced in 3.43.0. The problem occurs when doing a JSON_EXTRACT() on an array element that was added by JSON_SET() without first reparsing. (check-in: 3161c2cd user: drh tags: branch-3.43)
13:41
Fix a JSON bug introduced by the optimization of [df099ad713011b67] and first appearing in 3.43.0. The problem occurs when doing a JSON_EXTRACT() on an array element that was added by JSON_SET() without first reparsing. Reported by forum post fc0e3f1e2a. (check-in: e5099c54 user: drh tags: trunk)
11:57
Enhance the documentation of sqlite3_deserialize() to make it clear that the input database may not be in WAL mode. Forum post a7e272cee9ac469f (check-in: e7547899 user: drh tags: trunk)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/json.c.

2152
2153
2154
2155
2156
2157
2158

2159
2160
2161
2162
2163
2164
2165
    for(;;){
      while( j<=pRoot->n
         && (i>0 || ((pRoot[j].jnFlags & JNODE_REMOVE)!=0 && pParse->useMod))
      ){
        if( (pRoot[j].jnFlags & JNODE_REMOVE)==0 || pParse->useMod==0 ) i--;
        j += jsonNodeSize(&pRoot[j]);
      }

      if( (pRoot->jnFlags & JNODE_APPEND)==0 ) break;
      if( pParse->useMod==0 ) break;
      assert( pRoot->eU==2 );
      iRoot = pRoot->u.iAppend;
      pRoot = &pParse->aNode[iRoot];
      j = 1;
    }







>







2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
    for(;;){
      while( j<=pRoot->n
         && (i>0 || ((pRoot[j].jnFlags & JNODE_REMOVE)!=0 && pParse->useMod))
      ){
        if( (pRoot[j].jnFlags & JNODE_REMOVE)==0 || pParse->useMod==0 ) i--;
        j += jsonNodeSize(&pRoot[j]);
      }
      if( i==0 && j<=pRoot->n ) break;
      if( (pRoot->jnFlags & JNODE_APPEND)==0 ) break;
      if( pParse->useMod==0 ) break;
      assert( pRoot->eU==2 );
      iRoot = pRoot->u.iAppend;
      pRoot = &pParse->aNode[iRoot];
      j = 1;
    }

Changes to test/json101.test.

1037
1038
1039
1040
1041
1042
1043













1044
1045
1046
    '$.a', json('2'),
    '$.b', json('3'),
    '$.b', json('4'),
    '$.c', json('5'),
    '$.c', json('6')
  );
} {{{"a":2,"b":4,"c":6}}}















finish_test







>
>
>
>
>
>
>
>
>
>
>
>
>



1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
    '$.a', json('2'),
    '$.b', json('3'),
    '$.b', json('4'),
    '$.c', json('5'),
    '$.c', json('6')
  );
} {{{"a":2,"b":4,"c":6}}}

# 2023-10-17 https://sqlite.org/forum/forumpost/fc0e3f1e2a
# Incorrect accesss to '$[0]' in parsed + edited JSON.
#
do_execsql_test json101-23.1 {
  SELECT j, j->>0, j->>1
    FROM (SELECT json_set(json_set('[]','$[#]',0), '$[#]',1) AS j);
} {{[0,1]} 0 1}
do_execsql_test json101-23.2 {
  SELECT j, j->>0, j->>1
    FROM (SELECT json_set('[]','$[#]',0,'$[#]',1) AS j);
} {{[0,1]} 0 1}



finish_test