Ok, Let me do it with C language
const unsigned char* Format(const char* szFormat, ...);
int AudioFillDatabase(const char* audiofile);
int main(void)
{
Open();
execDML(" CREATE TABLE IF NOT EXISTS AudioTable (id INTEGER , \n"
" name VARCHAR , \n"
" data BLOB , \n"
" type VARCHAR);");
AudoFillDatabase(SomeSongname.xxx);
Close();
exit(0);
}
int AudioFillDatabase(const char* audiofile)
{
FILE* fp = fopen(audiofile, "rb");
if ( fp == NULL )
return -1;
else {
fseek(fp, 0, SEEK_END);
long filesize = ftell(fp);
unsigned char* MemFileSize = new unsigned char[filesize + 1];
size_t ret = fread(MemFileSize, filesize, 1, fp);
if ( ret != 0 )
return -1;
else {
unsigned char* buf = new unsigned char[filesize+1024];
buf = Format("insert into AudioTable values (0, 'music', %Q, 'mp3');",
MemFileSize);
execDML(buf);
}
}
const char* format(const char* szFromat, ...)
{
va_list va;
va_start(va, szFormat);
static char* mpBuf = sqlite3_vmprintf(szFormat, va);
va_end(va);
return mpBuf;
}
----- Original Message -----
From: "Isaac Raway" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Tuesday, November 28, 2006 11:04 PM
Subject: Re: [sqlite] Music Files
> 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;
>