How to create a database in memory?

Forum related to SQLite

Moderators: gto, cipto_kh, EgonHugeist

Post Reply
pol
Senior Boarder
Senior Boarder
Posts: 91
Joined: 13.10.2005, 08:19

How to create a database in memory?

Post by pol »

Hi!

It should be possible to create a SQLite database in memory, on the fly, create and populate tables and do sql operations on them. Other components (DISqlite) can do that.
Any ideas how this could be done using Zeos?

Regards,
Rüdiger
TheBlackSheep
Fresh Boarder
Fresh Boarder
Posts: 4
Joined: 27.02.2008, 22:43

Post by TheBlackSheep »

Hi Rüdiger

that's easy, drop a zeos TZConnection component on a form or datamodule and set the database to ":memory:" (without the quotes " " of course but both colons ( : ) at each end are important. Set the "Connected" property to true and just point the TZQuery/TZReadOnlyQuery/TZTable components you add to this connection. that's it really.

If you Disconnect (or set the Active state to false) on the TZConnection, you'll effectively drop any database/tables you've created etc.

It definitely does work with Zeos :-)

Chrs
User avatar
cipto_kh
Senior Boarder
Senior Boarder
Posts: 83
Joined: 28.09.2005, 11:22
Location: Indonesia
Contact:

Post by cipto_kh »

That's feature is only happen in SQLite?
pol
Senior Boarder
Senior Boarder
Posts: 91
Joined: 13.10.2005, 08:19

Post by pol »

Hi Chris,

Thanky you. What I did wrong was writing :MEMORY instead of :memory:. Who would expect that?
Now it is working fine :-)

Rüdiger
DucatiDesmo
Fresh Boarder
Fresh Boarder
Posts: 1
Joined: 05.05.2008, 08:59

Post by DucatiDesmo »

I find this really interesting!
Sorry for this newbie question, (newbie of sqlite and zeos components!)

...is it possible to store the memory database to a file?

thanks,
Filippo Forlani
aducom
Zeos Dev Team
Zeos Dev Team
Posts: 67
Joined: 30.08.2005, 13:21

Post by aducom »

Yes, attach a real db with table and use simple sql to copy the data. You cannot just 'save'. Then you should consider using a real table in the first place
Post Reply