I hackish method might be something like this:
struct s
{
...
};
struct s myS;
char buf[sizeof(s)*2]; // *2 as base64 encoding will be approx 33% bigger.
base64_encode( &myS, buf, sizeof(s) );
INSERT INTO table ( myTextField ) VALUES ( 'buf' );
then retrieval is the opposite.
Noel Frankinet wrote:
Narendran a écrit :
Noel Frankinet wrote:
Narendran a écrit :
Dear Friends,
I am in the process of forming a Generic API,(sql oriented and
BerkelyDB
and sister databases). In the process of integration ,i like to
store a
Structure in Sqlite.
as far as my knowledge SQLITE allows me to declare the column types
suppoted by the programming languare or say i am using blob . My
requirement
is i wish to store a structure in the SQLite column.
I am unable to form a sql statement to store the structure ,i am
also
not
clear with whether i can have a strucure as column type.
suggestions will be really helpful.
Thanking you,
B.Narendran
You will need to turn your c struct into a blob and store that blob.
When retrieving the blob, you need a way to turn it back into your
struct.
Its releatively easy if your struct does not contains pointers.
Best wishes
--
Noël Frankinet
Gistek Software SA
http://www.gistek.net
-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------
Dear Frankinet,
Thanks for ur reply,
I am unable to understand what u have said. I am having a structure
and I
am converting in to a blob. This means i am supposed to remove the
'\0' in
between the strucure and put a final '\0' (NULL) character . Blob
need only
on e null character to terminate it.
I tried to memcopy the structure elements and store them ,I can
store but
i am unable to find a way to retrieve it back.
typedef struct ethernetcard1
{
char port[10];
char ipaddress[20];
char mask[20];
int bandwidth;
}
what i tried is
char *buffer;
int bufferlen;buffersize;
bufferlen = strlen(port)+strlen(ipaddress)+strlen(mask)+sizeof(int)+1;
memcpy(buffer,user.port,strlen(user.port);
buffersize = strlen(user.port);
memcpy(buffer,user.ipaddress,strlen(user.ipaddress));
buffersize += strlen(user.ipaddress);
and finally i included a NULL character to the buffer to make it as
string
and i can insert in to a text field in sqlite column . I am unable to
figure
out a way to retrieve it back if i am storing in this way or a blob
type I
think blob will be similar to this .
expecting ur valuable suggestion.
Thanking you,
Narendran
hello Narendran,
Unfortunately, I'm still using 2.xx, so I encode the blob in character
using sqlite_encode and I decode it back when I get it from sqlite.
You are on the right track, but for string you should have a way to
store the length.
I have written some encoding function (like write_string and
read_string) to help encoding and decoding from the buffer (and avoi
all those mesy memcpy).
I hope this help
Best wishes
-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------