Page 1 of 1
save :memory: SQLite database to database file on HDD
Posted: Tue Jan 21, 2020 7:14 pm
by menschmarkus
Hi there,
I tried to find something in the forum but without success. So here my question:
How can I save a database which I created in memory?
Any ideas or ready made solutions?
Re: save :memory: SQLite database to database file on HDD
Posted: Tue Jan 21, 2020 7:23 pm
by Kiffi
menschmarkus wrote:Any ideas or ready made solutions?
viewtopic.php?p=363718#p363718
Greetings ... Peter
Re: save :memory: SQLite database to database file on HDD
Posted: Tue Jan 21, 2020 7:33 pm
by menschmarkus
Perfect, thank you kiffi
Edit:
Hm, I tried out your code.
At the command line:
Code: Select all
BackUp = sqlite3_backup_init(DatabaseID(DbFile), "main", DatabaseID(DbMem), "main")
something is going wrong. The following
is #False so no backup init is done.The error code
Code: Select all
Debug sqlite3_errcode(DatabaseID(DbFile))
results a 1 which means "SQL Error or missing database".
I add another debug line
Code: Select all
Debug sqlite3_errcode(DatabaseID(DbMem))
which results in a 0 what is OK.
The "temp.db" file exists. Size is 0
I don't want to say your code is wrong but something else seems to be wrong.
For your information I use PB 5.71 LTS in 32 bit with Win10 64 bit OS.
Any idea what may happened?
Edit2:
I tried PB 5.46 LTS. Here it works fine. It seems something in PB 5,71 LTS has changed.
Re: save :memory: SQLite database to database file on HDD
Posted: Tue Jan 21, 2020 11:03 pm
by Fred
May be it's an unicode issue, you can try to change the import to:
sqlite3_backup_init(pDest, zDestName.p-utf8, pSource, zSourceName.p-utf8)
Re: save :memory: SQLite database to database file on HDD
Posted: Sat Feb 15, 2020 4:51 pm
by menschmarkus
I am sorry for bothering you

but
Fred wrote:May be it's an unicode issue, you can try to change the import to:
sqlite3_backup_init(pDest, zDestName.p-utf8, pSource, zSourceName.p-utf8)
I changed Kiffis original code to:
Code: Select all
... BackUp = sqlite3_backup_init(DatabaseID(DbFile), "main.p-utf8", DatabaseID(DbMem), "main.p-utf8") ...
I still get Error Code 1 for FileDB
Furthermore I proviously checked valid opened FileDB with
right after opening the empty file as Database. This gives a valid value.
Used Hardware/Software:
Win 10 (1909)
PB 5.71 LTS (x86)
Is it really a bug?
Re: save :memory: SQLite database to database file on HDD
Posted: Sat Feb 15, 2020 5:12 pm
by TI-994A
menschmarkus wrote:...I changed Kiffis original code to:
Code: Select all
... BackUp = sqlite3_backup_init(DatabaseID(DbFile), "main.p-utf8", DatabaseID(DbMem), "main.p-utf8") ...
Add the
.p-utf8 extension to the declaration, and not the call:
Code: Select all
ImportC "sqlite3.lib"
sqlite3_backup_init(pDest, zDestName.p-utf8, pSource, zSourceName.p-utf8) ;<-- add the extensions here
sqlite3_backup_step(sqlite3_backup, nPage)
sqlite3_backup_finish(sqlite3_backup)
sqlite3_errcode(db)
EndImport
Leave the function call syntax as it is:
Code: Select all
BackUp = sqlite3_backup_init(DatabaseID(DbFile), "main", DatabaseID(DbMem), "main")
Re: save :memory: SQLite database to database file on HDD
Posted: Sat Feb 15, 2020 6:09 pm
by menschmarkus
TI-994A wrote:
Add the .p-utf8 extension to the declaration, and not the call:
OMG, did not see the wood for the trees
Thanks TI-994A