Saving a dababase

Jun 20, 2011 at 10:58pm

Saving a dababase


I’m currently working with databases following dbviewer & dbcuelist examples from the sdk.

I’m trying to save datas from the database to a file.
And before implementing my own read/write methods using “SELECT *” queries, I’m wondering if there isn’t an easier option.

I can see that db_open from ext_database.c has an option to read from a file on disk but can’t manage to make it work.
An empty file only rejects any table creation/modification.

I also tried to discover methods from the sqlite object (using its o_messlist) but couldn’t find something usefull.
It seems there’s a “create_backup” method but I’m not sure what it is doing and how to use it.

Any idea ?



Jun 21, 2011 at 6:06pm

Hi Léo,

Unless you’ve set the attribute to make the database a memory-resident database, then the database is automatically saved to disk and updated after each transaction. No manual saving is required.


Jun 21, 2011 at 6:40pm

Hi Tim,

I’ve followed the dbcuelist example, so I’m using “db_open”.

Right now I’m passing NULL as second argument in “db_open”, which, if I understand it correctly in “ext_database.c”, forces the database to be “rambased”.

I’ve tried entering a filename instead, I’ve tried with an existing file and a non-existing file. But then all queries return errors, so I don’t understand what I’m doing wrong.



Jun 23, 2011 at 5:51pm

In audiounit~ there is a cache of plug-in information stored in a SQLite database in the preferences folder. Here is the code used to create/open that database:

short			au_db_path = 0;
	char			au_db_pathstr[MAX_PATH_CHARS];
	t_max_err		err = MAX_ERR_NONE;
	t_db_result		*result = NULL;

	// Open the cache of AU info (if it exists) from the last time or create it anew
	err = preferences_path("", true, &au_db_path);
	if (!err)
		path_topotentialname(au_db_path, "aucache.db3", au_db_pathstr, 0);
		strncpy_zero(au_db_pathstr, "aucache.db3", MAX_PATH_CHARS);

	err = db_open(ps___max_audiounit_db__, au_db_pathstr, &s_db);
	if (err)
		error("audiounit~ could not open cache from %s", au_db_pathstr);

Hope this helps,

Jun 23, 2011 at 6:44pm

Thanks Tim,

I’ll take a look.

Anyway, I need to be able to read and write different files for my system (something like a complicated preset system).
I only use the database for the powerful data manipulation SQL it provides.
So I implemented my own read/write methods.




You must be logged in to reply to this topic.