SQLite

Check-in [e638d5e4]
Login

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

Overview
Comment:Rig sqlite3_serialize() so that it will initialize a previously uninitialized database prior to serializing it, so that it does not have a zero-byte size and does not return NULL (except for OOM). Forum thread 498777780e16880a.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: e638d5e408ea2e189b6771d16bbc2e42c606e88e05fbea78079b6e39e41f344c
User & Date: drh 2024-01-20 16:29:19
References
2024-03-06
21:53
Fix a memory leak in new memdb1.test test cases that were added by [e638d5e408ea2e18]. No changes to SQLite itself. (check-in: f0a49dc8 user: drh tags: branch-3.45)
2024-01-20
18:21
Fix a memory leak in new memdb1.test test cases that were added by [e638d5e408ea2e18]. No changes to SQLite itself. (check-in: bb2b7a65 user: drh tags: trunk)
Context
2024-03-06
20:55
Rig sqlite3_serialize() so that it will initialize a previously uninitialized database prior to serializing it, so that it does not have a zero-byte size and does not return NULL (except for OOM). Forum thread 498777780e16880a. (check-in: 22a33f13 user: mistachkin tags: branch-3.45)
2024-01-20
16:38
Make sure that %V and %G are testing for every since day in between 1970-01-01 and 2023-01-19. (check-in: 39c475f5 user: drh tags: trunk)
16:29
Rig sqlite3_serialize() so that it will initialize a previously uninitialized database prior to serializing it, so that it does not have a zero-byte size and does not return NULL (except for OOM). Forum thread 498777780e16880a. (check-in: e638d5e4 user: drh tags: trunk)
15:13
When doing a text-affinity comparison between two values where one or both have both a text and a numeric type, make sure the numeric type does not confuse the answer. This is a deeper fix to the problem observed by forum pose 3776b48e71. The problem bisects to [25f2246be404f38b] on 2014-08-24, prior to version 3.8.7. (check-in: 709841f8 user: drh tags: trunk)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/memdb.c.

795
796
797
798
799
800
801








802
803
804
805
806
807
808
  sqlite3_free(zSql);
  if( rc ) return 0;
  rc = sqlite3_step(pStmt);
  if( rc!=SQLITE_ROW ){
    pOut = 0;
  }else{
    sz = sqlite3_column_int64(pStmt, 0)*szPage;








    if( piSize ) *piSize = sz;
    if( mFlags & SQLITE_SERIALIZE_NOCOPY ){
      pOut = 0;
    }else{
      pOut = sqlite3_malloc64( sz );
      if( pOut ){
        int nPage = sqlite3_column_int(pStmt, 0);







>
>
>
>
>
>
>
>







795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
  sqlite3_free(zSql);
  if( rc ) return 0;
  rc = sqlite3_step(pStmt);
  if( rc!=SQLITE_ROW ){
    pOut = 0;
  }else{
    sz = sqlite3_column_int64(pStmt, 0)*szPage;
    if( sz==0 ){
      sqlite3_reset(pStmt);
      sqlite3_exec(db, "BEGIN IMMEDIATE; COMMIT;", 0, 0, 0);
      rc = sqlite3_step(pStmt);
      if( rc==SQLITE_ROW ){
        sz = sqlite3_column_int64(pStmt, 0)*szPage;
      }
    }
    if( piSize ) *piSize = sz;
    if( mFlags & SQLITE_SERIALIZE_NOCOPY ){
      pOut = 0;
    }else{
      pOut = sqlite3_malloc64( sz );
      if( pOut ){
        int nPage = sqlite3_column_int(pStmt, 0);

Changes to test/memdb1.test.

262
263
264
265
266
267
268












269
270
    SELECT * FROM t1;
  } {1 2 3 4}
  
  do_catchsql_test 830 {
    PRAGMA wal_checkpoint;
  } {1 {database disk image is malformed}}
}













finish_test







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


262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
    SELECT * FROM t1;
  } {1 2 3 4}
  
  do_catchsql_test 830 {
    PRAGMA wal_checkpoint;
  } {1 {database disk image is malformed}}
}

# 2024-01-20
# https://sqlite.org/forum/forumpost/498777780e16880a
#
# Make sure a database is initialized before serializing it.
#
reset_db
sqlite3 dbempty :memory:
do_test 900 {
  set len [string length [dbempty serialize]]
  expr {$len>0}
} 1

finish_test