MCPcopy Create free account
hub / github.com/WiseLibs/better-sqlite3 / Deserialize

Method Deserialize

src/objects/database.cpp:92–120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90}
91
92bool Database::Deserialize(
93 v8::Local<v8::Object> buffer,
94 Addon* addon,
95 sqlite3* db_handle,
96 bool readonly
97) {
98 size_t length = node::Buffer::Length(buffer);
99 unsigned char* data = (unsigned char*)sqlite3_malloc64(length);
100 unsigned int flags = SQLITE_DESERIALIZE_FREEONCLOSE | SQLITE_DESERIALIZE_RESIZEABLE;
101
102 if (readonly) {
103 flags |= SQLITE_DESERIALIZE_READONLY;
104 }
105 if (length) {
106 if (!data) {
107 ThrowError("Out of memory");
108 return false;
109 }
110 memcpy(data, node::Buffer::Data(buffer), length);
111 }
112
113 int status = sqlite3_deserialize(db_handle, "main", data, length, length, flags);
114 if (status != SQLITE_OK) {
115 ThrowSqliteError(addon, status == SQLITE_ERROR ? "unable to deserialize database" : sqlite3_errstr(status), status);
116 return false;
117 }
118
119 return true;
120}
121
122void Database::FreeSerialization(char* data, void* _) {
123 sqlite3_free(data);

Callers

nothing calls this directly

Calls 1

ThrowErrorFunction · 0.85

Tested by

no test coverage detected