I my experience, the best approach is to create a description of your data
in a form that is good for being parsed and feeding into a code generator.
C structures are not good for this, they are good for being compiled into
executable code.

I would create a data description, and use it to generate the SQL and the C
structures.  The data description could be whatever you find convenient: I
use XML, but anything will do so long as it is expressive enough for you and
you can parse it.

I use a code generation tool called Cog (http://nedbatchelder.com/code/cog)
to generate the code itself.

--Ned.
http://nedbatchelder.com
 

-----Original Message-----
From: John Stanton [mailto:[EMAIL PROTECTED] 
Sent: Monday, 17 October, 2005 10:40 AM
To: sqlite-users@sqlite.org
Subject: Re: [sqlite] Question about automatic schema creation from custom
data-strucutre for persistence storage

I addressed this some time back in a C program which dynamically 
generates XML.  Generating SQL would be an option.

By building a table with a keyname for each data element and a pointer 
to a data item the output structure can be assembled.  As a wise person 
once told me "There is no problem in CS which cannot be solved by yet 
another level of indirection".

In my case I also added a function pointer so that callbacks could be 
used.  With XML the table is actually a transformation of the DTD so 
that the result is guaranteed to be "well formed".  If the table were 
compiled from the data structure then a similar integrity could be assured.

This method would require a few lines of code, but you would only need 
to do it once as opposed to writing code for each data structure.
JS

Dan Kennedy wrote:
> As far as I know C++ has no introspection capability so the answer 
> is probably no. Unless you want to parse your header file yourself,
> or something like that.
>  
> With Java or another high-level programming language that supports 
> introspection it would be possible I think.
> 
> 
> "Rajan, Vivek K" <[EMAIL PROTECTED]> wrote:
> Hello- 
> 
> 
> 
> Has anyone had experience with automatically creating schema from a
> custom data-structure for persistence storage using SQLite? So, in my
> C/C++ program I have the following type of data-structure:
> 
> 
> 
> struct _trace {
> 
> std::string name; 
> 
> std::string prop;
> 
> std:string object; 
> 
> int a; 
> 
> double b; 
> 
> }; 
> 
> 
> 
> std::vector _myPath; 
> 
> 
> Now, let's say I want to write and read _myPath data-structure
> (persistence) in SQLite database. 
> 
> 
> 
> My questions:
> 
> - Is there a mechanism to dynamically create a schema on-the-fly from
> the data-structure? 
> 
> - Essentially a capability to store any custom data-structure into
> SQLite data-base by automatic creation of schema for the data-structure
> 
> 
> 
> Rajan
> 
> 
> 
> 
> 
> 
>               
> ---------------------------------
>  Yahoo! Music Unlimited - Access over 1 million songs. Try it free.


Reply via email to