Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-interest Archive, November 2006
[Qt 4.2] Using SQLite in memory with Qt Resource System


Message 1 in thread

Hi all,

I have some pretty static data that I want to ship with my app (relates to 
postcode formats / country names).  I can currently extract the data into my 
programme from a separate sqlite3 database on the users PC.  Now I want to 
hide the data to prevent inadvertent loss.

I am interested in the in memory option  (setDatabaseName(":memory:").  So far 
I have seen examples where a table is created this way with values inserted 
using programme code (e.g. Cached Table Example in 4.2 docs).

Is there a direct way of getting an existing sqlite3 database into memory 
using e.g.  resource system

 myapp.qrc ...headerstuff....<file>/config/database.db</file>....footer stuff

and some other code to associate the particular database into memory?

If there is no direct way to do this, is it possible to create the relevant 
tables in memory using SQL and then importing the data from an embedded csv? 
[I am happy with table creation idea but looking for guidance on importing 
data from csv once table is ready].

Any help much appreciated.

Regards,


Amit

--
 [ signature omitted ] 

Message 2 in thread

> Is there a direct way of getting an existing sqlite3 database into memory 

http://www.mail-archive.com/sqlite-users@xxxxxxxxxx/msg15904.html

Entirely sqlite specific, of course.

Micha


--
 [ signature omitted ] 

Message 3 in thread

Micha,

many thanks for the excellent answer to the specific item.

I'd recommend the presentation referenced below to anyone looking at sqlite 
for the first time.

If anyone knows of a way of reading from (e.g. csv) into sqlite from within Qt 
I'm still curious.  I can do it using meta commands issued at the sqlite 
prompt.  Micha's answer deals well with getting from sqlite into sqlite in 
memory, but does not seem to allow for hiding the data in the executable. 

Thanks,

Amit


On Thursday 02 November 2006 11:25, Michael Bieber wrote:
> > Is there a direct way of getting an existing sqlite3 database into memory
>
> http://www.mail-archive.com/sqlite-users@xxxxxxxxxx/msg15904.html
>
> Entirely sqlite specific, of course.
>
> Micha
>
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body. List archive and information:
> http://lists.trolltech.com/qt-interest/

--
 [ signature omitted ] 

Message 4 in thread

amit wrote:
> Micha,
> 
> many thanks for the excellent answer to the specific item.
> 
> I'd recommend the presentation referenced below to anyone looking at sqlite 
> for the first time.
> 
> If anyone knows of a way of reading from (e.g. csv) into sqlite from within Qt 
> I'm still curious.  I can do it using meta commands issued at the sqlite 
> prompt.  Micha's answer deals well with getting from sqlite into sqlite in 
> memory, but does not seem to allow for hiding the data in the executable. 
> 
> Thanks,
> 
> Amit

If you have your data prepared once in a sqlite database, you could dump 
that database into a textfile (using the .dump meta command), and pack 
that textfile into the Qt resource file.

Your application could then get a number of SQL commands from the 
resource and issue them to a ':memory:' sqlite database.

/eno

--
 [ signature omitted ] 

Message 5 in thread

On Thursday 02 November 2006 16:35, troll@xxxxxxxxxxxx wrote:

Great - sounds promising.  Understand first para...not at all sure how to do 
second bit. 

Are you suggesting something like  "INSERT ....FROM ...'myfile.csv' (which I 
didn't think sqlite supports)? Or have I missed your meaning?

A
>
> If you have your data prepared once in a sqlite database, you could dump
> that database into a textfile (using the .dump meta command), and pack
> that textfile into the Qt resource file.
>
> Your application could then get a number of SQL commands from the
> resource and issue them to a ':memory:' sqlite database.
>
> /eno
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body. List archive and information:
> http://lists.trolltech.com/qt-interest/

--
 [ signature omitted ] 

Message 6 in thread

amit wrote:
> On Thursday 02 November 2006 16:35, troll@xxxxxxxxxxxx wrote:
> 
> Great - sounds promising.  Understand first para...not at all sure how to do 
> second bit. 
> 
> Are you suggesting something like  "INSERT ....FROM ...'myfile.csv' (which I 
> didn't think sqlite supports)? Or have I missed your meaning?

I don't know how to get the CSV file into a database, but I remember you 
said you would know how to do that. So what you would do is

a) create a database, using the sqlite commandline tool
b) fill it with the vaues from your CSV-file
c) dump that into a file.

That file would then contain a series of SQL statements.

You add that file to your resource. After that you can access the SQL 
statements from within the Qt app, where you can rebuild the database in 
memory from exactly these SQL statements, and use it.

However, whenever you change the underlying data you need to do a), b) 
and c) and then rebuild your application.

/eno

--
 [ signature omitted ] 

Message 7 in thread

On Thursday 02 November 2006 23:14, troll@xxxxxxxxxxxx wrote:

Ah. I think this is the crucial bit.  I hadn't appreciated that the dump 
process would put the SQL as well as the values into the output.  Will try 
Monday and post outcome.

Thanks again.

A

>
> That file would then contain a series of SQL statements.
>

--
 [ signature omitted ]