On 11/27/06, LuYanJun <[EMAIL PROTECTED]> wrote:

Can anybody give a simple example for domestrating ?
I am puzzled by this topic, how does a music file be sotred in DB as BLOB
type?


You can insert /any/ kind of data into a SQLite database (or most any other
sort of DB for that matter). Here's a short Pascal program that would do
about what you want -- but of course getting the binary data out and into an
object that can play it is another matter. Also I imagine this would be very
slow, coming in at around 3 - 5 MB per song that has to be completely loaded
into memory from the DB before playback and begin. I have not tested this
but it gives you the idea: 1) load data into a stream / data string 2) write
as DB BLOB.

var
 MP3Source: string;
 Data: TFileStream

 DBFileName: string;
 DB: TSQLiteDatabase;
 MustCreate: boolean;
begin
 MP3Source := 'SomeSong.mp3';
 DBFileName := 'mp3.db3';

 MustCreate := not FileExists(DBFileName);
 DB := TSQLiteDatabase.Create(DBFileName);
 try
   if MustCreate then begin
     DB.ExecSQL('CREATE TABLE mp3(filename STRING PRIMARY KEY, data
BLOB);');
   end;

   Data := TFileStream.Create(MP3Source, fmOpenRead);
   try
     Data.Seek(0);

     DB.UpdateBlob('INSERT OR UPDATE INTO mp3(filename, data) ' +
                   'VALUES(' + QuotedStr(MP3Source) + ', ?);', Data);
   finally
     FreeAndNil(Data);
   end;
 finally
   DB.Close;
   FreeAndNil(DB);
 end;
end;

Reply via email to