我本楚狂人 wrote:
This (or something like it) should do what you want, but I'm not sure if putting large objects like MP3 files into the database is really a good idea. Others have said they had better performance using the file system to store large files and simply saving the file names in the database.I have search with Google , and find these information as belowsqlite3_prepare(..., "insert into foo values(?);", -1, &stmt, ...); sqlite3_bind_blob(stmt, 1, "bar", 3, SQLITE_TRANSIENT); sqlite3_step(stmt); But if there is a file in this path "C:\a.mp3",I use "ifstream mp3("C:\\a.mp3")open this file . Then I don't know how can I insert it to the database with the pointer "sqlite3 *db; " (the database has two column, the first's type is text(to write the name of file) ; the second's type is blob(to write the binary file ) ) Would you please give me some code about this problem?Thank you. And another question, What's the lastest parameter's mean of sqlite3_prepare? I have read the help of this problem , but I can't understand.
ifstream mp3("C:\\a.mp3");
mp3.seekg(0, ios::end);
long sz = mp3.tellg();
mp3.seekg(0, ios::beg);
stringstream sbuf;
sbuf << mp3.rdbuf();
char* buf = sbuf.str();
sqlite3_prepare(..., "insert into foo values(?);", -1, &stmt, ...);
sqlite3_bind_blob(stmt, 1, buf, sz, SQLITE_TRANSIENT);
sqlite3_step(stmt);
HTH
Dennis Cote

