xref: /netbsd-src/external/public-domain/sqlite/man/sqlite3_deserialize.3 (revision b9988867a8ad969c45a52aa7628bc932ec98d46b)
1.Dd January 24, 2024
2.Dt SQLITE3_DESERIALIZE 3
3.Os
4.Sh NAME
5.Nm sqlite3_deserialize
6.Nd deserialize a database
7.Sh SYNOPSIS
8.In sqlite3.h
9.Ft int
10.Fo sqlite3_deserialize
11.Fa "sqlite3 *db"
12.Fa "const char *zSchema"
13.Fa "unsigned char *pData"
14.Fa "sqlite3_int64 szDb"
15.Fa "sqlite3_int64 szBuf"
16.Fa "unsigned mFlags"
17.Fc
18.Sh DESCRIPTION
19The sqlite3_deserialize(D,S,P,N,M,F) interface causes the database connection
20D to disconnect from database S and then reopen S as an in-memory database
21based on the serialization contained in P.
22The serialized database P is N bytes in size.
23M is the size of the buffer P, which might be larger than N.
24If M is larger than N, and the SQLITE_DESERIALIZE_READONLY bit is not
25set in F, then SQLite is permitted to add content to the in-memory
26database as long as the total size does not exceed M bytes.
27.Pp
28If the SQLITE_DESERIALIZE_FREEONCLOSE bit is set in F, then SQLite
29will invoke sqlite3_free() on the serialization buffer when the database
30connection closes.
31If the SQLITE_DESERIALIZE_RESIZEABLE bit is set, then SQLite will try
32to increase the buffer size using sqlite3_realloc64() if writes on
33the database cause it to grow larger than M bytes.
34.Pp
35Applications must not modify the buffer P or invalidate it before the
36database connection D is closed.
37.Pp
38The sqlite3_deserialize() interface will fail with SQLITE_BUSY if the
39database is currently in a read transaction or is involved in a backup
40operation.
41.Pp
42It is not possible to deserialized into the TEMP database.
43If the S argument to sqlite3_deserialize(D,S,P,N,M,F) is "temp" then
44the function returns SQLITE_ERROR.
45.Pp
46The deserialized database should not be in WAL mode.
47If the database is in WAL mode, then any attempt to use the database
48file will result in an SQLITE_CANTOPEN error.
49The application can set the file format version numbers
50(bytes 18 and 19) of the input database P to 0x01 prior to invoking
51sqlite3_deserialize(D,S,P,N,M,F) to force the database file into rollback
52mode and work around this limitation.
53.Pp
54If sqlite3_deserialize(D,S,P,N,M,F) fails for any reason and if the
55SQLITE_DESERIALIZE_FREEONCLOSE bit is set in argument F, then
56.Fn sqlite3_free
57is invoked on argument P prior to returning.
58.Pp
59This interface is omitted if SQLite is compiled with the SQLITE_OMIT_DESERIALIZE
60option.
61.Sh IMPLEMENTATION NOTES
62These declarations were extracted from the
63interface documentation at line 10702.
64.Bd -literal
65SQLITE_API int sqlite3_deserialize(
66  sqlite3 *db,            /* The database connection */
67  const char *zSchema,    /* Which DB to reopen with the deserialization */
68  unsigned char *pData,   /* The serialized database content */
69  sqlite3_int64 szDb,     /* Number bytes in the deserialization */
70  sqlite3_int64 szBuf,    /* Total size of buffer pData[] */
71  unsigned mFlags         /* Zero or more SQLITE_DESERIALIZE_* flags */
72);
73.Ed
74.Sh SEE ALSO
75.Xr sqlite3 3 ,
76.Xr sqlite3_malloc 3 ,
77.Xr SQLITE_OK 3
78