Dimitris Servis wrote:
Hello John,

You do not have to load the entire file into memory.  The best way is to

memory map it and use the returned pointer to copy it into the RDBMS.
You can retrieve it to a file in a similar way.  It helps if you store
the file size in the DB so that you can create a file the correct size
to act as a destination for your memcopy.

It is only a few lines of code to wrap such logic along with the current
Sqlite API.



That's just a great idea. Is there an API in SQLite or should I wrap the
native OS APIs?

THANKS!!!

dimitris

Build your own function to go into your application or into your own Sqlite interface wrapper set. If you are using Linux just -
   open the file,
     ...optional
     read some details of the file to put in your Sqlite table as a key
   get the file size
   mmap it and get a pointer to the data
   close the file
   bind file ptr to the prepared SQL statement
     ...optional
     bind file size to the prepared SQL statement
     ...optional
     bind file description to prepared SQL statement
   sqlite step
   sqlite reset
   unmap the file

The file will now be a blob in the DB and you have no memory to free. If you add the optional events you will be able to use SQL to retrieve the file based on a description or key and will have the size stored for when you want to retrieve the file and do something with it.

You have totally avoided the dreaded malloc and free and their pathological side effects and can be unconcerned about the file size since the VM system takes care of it.

In some circumstances it might be appropriate to register the logic as an Sqlite function so that you could pop a file in and out of the DB using SQL alone. You can do that by having an application level custom function or compiling it into the Sqlite library by taking advantage of the open source nature of Sqlite. Adding functions to the Sqlite library is very simple.

-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to