Hi,
I found several examples on how to use sqlite in memory, using ":memory:" as database. But can I save the database to a file (and reload it into memory)? I mean other than creating an identical database structure and copy the data. I want to prevent to write every single update to disk and want to flush it, when the operations are done.
How to save SQLite Database in memory to file?
How to save SQLite Database in memory to file?
Good morning, that's a nice tnetennba!
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Re: How to save SQLite Database in memory to file?
Ah thanks! I obviously used the wrong keywords for searching and didn't think copying it to *memory.
Good morning, that's a nice tnetennba!
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Re: How to save SQLite Database in memory to file?
I had problems- in pre 6.11 I got a memory error with 6.11, the code just crashed. (with or without using p-utf8)
here's the version I ended up with.
I originally used utf8() but why do two function calls(utf8() & freememory()) to achieve the same thing with a datasection?
(portion of my sqlite3 library)
here's the version I ended up with.
I originally used utf8() but why do two function calls(utf8() & freememory()) to achieve the same thing with a datasection?
(portion of my sqlite3 library)
Code: Select all
DeclareModule sqlite3
Declare backup( srcNum, dstNum )
EndDeclareModule
Module sqlite3
EnableExplicit
UseSQLiteDatabase()
ImportC ""
sqlite3_backup_init(destID, *zDestName, sourceID, *zSourceName)
sqlite3_backup_step(backupHandle, nPage)
sqlite3_backup_finish(backupHandle)
EndImport
#backupALL = -1
#sqlite3_ok = 0
DataSection
asciiMain:
Data.a 'm', 'a', 'i', 'n', 0 ; "p-utf8" didn't work for me. Caused memory error, on 6.11 just a crash.
EndDataSection
Procedure backup(srcNum, dstNum)
Protected success, backupHandle
If IsDatabase(srcNum) And IsDatabase(dstNum)
backupHandle = sqlite3_backup_init( DatabaseID(dstNum), ?asciiMain, DatabaseID(srcNum), ?asciiMain )
If backupHandle
sqlite3_backup_step( backupHandle, #backupALL )
success = Bool( sqlite3_backup_finish(backupHandle) = #sqlite3_ok )
EndIf
EndIf
ProcedureReturn success
EndProcedure
EndModule
-
- User
- Posts: 94
- Joined: Sun Oct 24, 2004 9:25 am
Re: How to save SQLite Database in memory to file?
Anything wrong with simply using :
DatabaseUpdate( #DB_YTCS, "Vacuum DB_MEM into '.\gaga.s3db' " )
??
DatabaseUpdate( #DB_YTCS, "Vacuum DB_MEM into '.\gaga.s3db' " )
??
Is this an artifact or should it be disposed of ?