save :memory: SQLite database to database file on HDD

Just starting out? Need help? Post your questions and find answers here.
User avatar
menschmarkus
User
User
Posts: 18
Joined: Fri Dec 28, 2012 11:23 pm
Location: Center Germany

save :memory: SQLite database to database file on HDD

Post 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?
As soon you do it right, it works !
User avatar
Kiffi
Addict
Addict
Posts: 1353
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: save :memory: SQLite database to database file on HDD

Post by Kiffi »

menschmarkus wrote:Any ideas or ready made solutions?
viewtopic.php?p=363718#p363718

Greetings ... Peter
Hygge
User avatar
menschmarkus
User
User
Posts: 18
Joined: Fri Dec 28, 2012 11:23 pm
Location: Center Germany

Re: save :memory: SQLite database to database file on HDD

Post by menschmarkus »

:D
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

Code: Select all

If BackUp
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.
As soon you do it right, it works !
Fred
Administrator
Administrator
Posts: 16623
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: save :memory: SQLite database to database file on HDD

Post 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)
User avatar
menschmarkus
User
User
Posts: 18
Joined: Fri Dec 28, 2012 11:23 pm
Location: Center Germany

Re: save :memory: SQLite database to database file on HDD

Post by menschmarkus »

I am sorry for bothering you :oops: 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

Code: Select all

Debug IsDatabase(DbFile)
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?
As soon you do it right, it works !
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: save :memory: SQLite database to database file on HDD

Post 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")
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
menschmarkus
User
User
Posts: 18
Joined: Fri Dec 28, 2012 11:23 pm
Location: Center Germany

Re: save :memory: SQLite database to database file on HDD

Post 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 :oops:

Thanks TI-994A
As soon you do it right, it works !
Post Reply