1

I'm trying to dump a file from sqlite3 database using C++ function. I have tried this on terminal command and it works perfectly but here it's not executed.

errmsg=: no such function: writefile

bool Database::download(string username, string filename){

    string query = "SELECT USERNAME FROM FILES WHERE USERNAME='"+username+"';";
    int rc = sqlite3_exec(dbFile,query.c_str(),private_callback,(void *)data,&errmsg);
    if(rc==SQLITE_OK){
        cout<<"this username dont have any uploaded files!"<<endl;
        return false;

    }
    else{
        query = "SELECT writefile('"+filename+"',FILE) FROM FILES WHERE USERNAME='"+username+"' AND FILENAME='"+filename+"';";
        rc = sqlite3_exec(dbFile,query.c_str(),private_callback,(void *)data,&errmsg);

        if(rc!=SQLITE_OK){
            cout<<errmsg<<endl;
            return false;
        }
        elsereturn true;
    }
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
  • Yes, can't seem to do it via the app... but was able to do it via command line. https://stackoverflow.com/questions/15448373/how-to-dump-a-file-stored-in-a-sqlite-database-as-a-blob – Jc Nolan Jul 07 '19 at 01:52

1 Answers1

2

The documentation says:

Note that the readfile(X) and writefile(X,Y) functions are extension functions and are not built into the core SQLite library. These routines are available as a loadable extension in the ext/misc/fileio.c source file in the SQLite source code repositories.

CL.
  • 173,858
  • 17
  • 217
  • 259