SQLite Forum

sqlite3_backup_init returns null, but no error is set
Login

sqlite3_backup_init returns null, but no error is set

(1) By anonymous on 2022-01-31 09:58:10 [source]

Reproducer:

  1. open a connection to memory database (":memory:") => source database
  2. open a connection to memory database (":memory:") => destination database
  3. call sqlite3_backup_init(destination, "main", source, "temp")

This causes sqlite3_backup_init to return NULL, but no error is set on the destination database handle.

Quoting the docs:

If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is returned and an error code and error message are stored in the destination database connection D.

I ran fossil bisect, and it points to 6a45d8fe8bfbc11a as the first bad commit.

fossil bisect good
bisect complete
  2 BAD     2022-01-30 21:09:03 c10ed4a7fe33fd93
  6 BAD     2022-01-24 20:16:37 11df9187dad0eb33
  8 BAD     2022-01-24 16:47:12 1f7fa46126ea33ed
  9 BAD     2022-01-24 15:34:55 6a45d8fe8bfbc11a
 10 GOOD    2022-01-24 14:01:31 53d4404458fb6f0b CURRENT
  7 GOOD    2022-01-24 12:48:54 ad7aace761c6b21b
  5 GOOD    2022-01-21 18:57:30 2f5dc7a9eed89baf
  4 GOOD    2022-01-11 23:28:12 4cbb3e3efeb40cc4
  1 GOOD    2022-01-06 13:25:41 872ba256cbf61d92
  3 GOOD    2021-12-20 23:46:44 d9f814a6402ca7fd

Here's my debug output:

destination db = 0x7fd486707110
source db = 0x7fd486708f00

sqlite3_backup_init(0x7fd486707110, "main", 0x7fd486708f00, "temp") => 0x0
sqlite3_errcode(0x7fd486707110) => 0
sqlite3_errmsg(0x7fd486707110) => 'not an error'
sqlite3_errcode(0x7fd486708f00) => 0
sqlite3_errmsg(0x7fd486708f00) => 'not an error'

For the record, calling sqlite3_backup_init(target, "main", source, "main") works just fine.

(2) By Richard Hipp (drh) on 2022-01-31 12:31:59 in reply to 1 [link] [source]

Thanks for beta-testing trunk! We'd have fewer bugs in releases if more people would do the same.

The problem should be fixed as of check-in 639fc7633bd74042.

(3) By anonymous on 2022-01-31 14:22:33 in reply to 2 [link] [source]

Fantastic! I can verify that trunk as of 639fc7633bd74042 works as expected. Thank you for your quick response and bugfix, and thank you for SQLite!