Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Linux_x64.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
rm -rf build;
mkdir build && cd build && cmake .. -G"Unix Makefiles" -DCMAKE_BUILD_TYPE=Release && make
49 changes: 49 additions & 0 deletions Projects/mod_sqlite/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,55 @@ void ModuleRegister()
SDK_ENDTRY;
});

g_DatabaseClass.RegisterFunction("backup", [](Galactic3D::Interfaces::INativeState* pState, int32_t argc, void* pUser) {
SDK_TRY;

SDK::State State(pState);

auto pThis = State.CheckThis<CDatabase, g_DatabaseClass>();

const char* pszFilename = State.CheckString(0);

sqlite3* pDstDB;
if (sqlite3_open(pszFilename, &pDstDB) != SQLITE_OK) {
pState->SetError("%s", sqlite3_errmsg(pDstDB));

sqlite3_close(pDstDB);

return false;
}

sqlite3_backup* backupDB = sqlite3_backup_init(pDstDB, "main", pThis->m_pDatabase, "main");
if (backupDB == nullptr) {
pState->SetError("%s", sqlite3_errmsg(pDstDB));

sqlite3_close(pDstDB);

return false;
}

int rc = 0;
do
{
rc = sqlite3_backup_step(backupDB, -1);
if (rc == SQLITE_BUSY || rc == SQLITE_LOCKED)
sqlite3_sleep(250);
} while (rc == SQLITE_OK || rc == SQLITE_BUSY || rc == SQLITE_LOCKED);

sqlite3_backup_finish(backupDB);

rc = sqlite3_backup_step(backupDB, -1);

sqlite3_close(pDstDB);

if (rc != SQLITE_DONE)
pState->SetError("%s", sqlite3_errmsg(pDstDB));

return true;

SDK_ENDTRY;
});

g_DatabaseClass.RegisterFunction("query", [](Galactic3D::Interfaces::INativeState* pState, int32_t argc, void* pUser) {
SDK_TRY;

Expand Down