[sqlite] backup memory database not working
Thank you Clemens, this way all is fine! Am 11.03.2016 um 16:27 schrieb Clemens Ladisch: > asdf asdf wrote: >> My intention: >> - loading a file db into a memory db. > This is not done with ATTACH, but by making a backup of the > file DB with the memory DB as destination. > > > Regards, > Clemens > ___ > sqlite-users mailing list > sqlite-users at mailinglists.sqlite.org > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
[sqlite] backup memory database not working
I am not sure if i understand you correctly. My intention: - loading a file db into a memory db. - work with memory db during runtime. so it could be changed - save mem db back to file db. Is this possible ? Thank you Am 11.03.2016 um 16:19 schrieb Clemens Ladisch: > asdf asdf wrote: >> - create a memory db >> - attach a file db >> - backup memory db >> this fails. > An attached database stays separate, i.e., its data is not merged into > the backup. > > To backup the file DB, give its name (and not "main") to > sqlite3_backup_init(). > > > Regards, > Clemens > ___ > sqlite-users mailing list > sqlite-users at mailinglists.sqlite.org > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
[sqlite] backup memory database not working
Hello, meanwhile i could reproduce my situation more precisely. Short: - create a memory db - attach a file db - backup memory db this fails. Please watch my compile ready example (VS 2013) attached. Thank you for help Am 10.03.2016 um 21:56 schrieb R Smith: > > > On 2016/03/10 10:41 PM, asdf asdf wrote: >> Hello, >> what do you mean, please ? What code is not shown:my own code (and what >> could be the cause then) using the example or what i posted in >> stackoverflow. >> >> I would be happy to solve it. Any information appreciated- > > He means that there is something else that is wrong in your code that > you've used to test this Backup feature. We cannot see your full code, > so we do not know what is wrong with it, but we know something is > wrong because the backup from memory works when we do it, and works > when done like the example. You can easily use the command line > SQLite3.exe tool to test it. > > So, if it works correctly for us, meaning it is not an SQLite bug, but > there might be something in your code that is missing or weird and we > would like to help you find it, however, only if you show us the exact > code you've used to test with. Also the DB schema - some SQL perhaps > to populate the in-memory database. Perhaps something about the schema > is strange and causes the problem, then it might even be a bug - but > we can't know that until we have exactly what you have. > > Thanks, > Ryan > > ___ > sqlite-users mailing list > sqlite-users at mailinglists.sqlite.org > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users -- next part -- #include "stdafx.h" #include "sqlite3.h" #include #include #include int backupDb( sqlite3 *pDb, /* Database to back up */ const char *zFilename, /* Name of file to back up to */ void(*xProgress)(int, int) /* Progress function to invoke */ ){ int rc; /* Function return code */ sqlite3 *pFile; /* Database connection opened on zFilename */ sqlite3_backup *pBackup;/* Backup handle used to copy data */ /* Open the database file identified by zFilename. */ rc = sqlite3_open(zFilename, ); if( rc==SQLITE_OK ){ /* Open the sqlite3_backup object used to accomplish the transfer */ pBackup = sqlite3_backup_init(pFile, "main", pDb, "main"); if( pBackup ){ /* Each iteration of this loop copies 5 database pages from database ** pDb to the backup database. If the return value of backup_step() ** indicates that there are still further pages to copy, sleep for ** 250 ms before repeating. */ do { rc = sqlite3_backup_step(pBackup, 5); if(xProgress != nullptr) { xProgress( sqlite3_backup_remaining(pBackup), sqlite3_backup_pagecount(pBackup) ); } if( rc==SQLITE_OK || rc==SQLITE_BUSY || rc==SQLITE_LOCKED ){ sqlite3_sleep(5); } } while( rc==SQLITE_OK || rc==SQLITE_BUSY || rc==SQLITE_LOCKED ); /* Release resources allocated by backup_init(). */ (void)sqlite3_backup_finish(pBackup); } rc = sqlite3_errcode(pFile); } /* Close the database connection opened on database file zFilename ** and return the result of this function. */ (void)sqlite3_close(pFile); return rc; } booldo_select(sqlite3*db, const std::string& sql, const std::string& comment = "") { if (db == nullptr) std::cout << "\ndo_select: no database";; sqlite3_stmt* stmt = nullptr; std::cout << "\ndo_select("<<comment<<") <"<<sql<<">"; int res = sqlite3_prepare_v2(db, sql.c_str(), -1, , 0); if (res == SQLITE_OK) { /// cycle result rows do{ res = sqlite3_step(stmt); int row = 0; int cols = sqlite3_column_count(stmt); switch (res) { case SQLITE_DONE: break; case SQLITE_ROW: { /// cycle result columns for (int col = 0; col < cols; col++) { std::string sres = (const char*)sqlite3_column_text(stmt, 0); std::cout << "\n\t" <<"(" << row << "," << col << ") : " << sres.c_str(); } } break; default: { sqlite3_finalize(stmt); std::cout << "\n\t"<< "sql error: " << sql.c_str(); return false; } break;
[sqlite] backup memory database not working
Thank you Ryan, i wrote a small test routine using the same backup routine i use in my code and in fact, here it works. Attached. Need to investigate for differences. Thanks to community for support Am 10.03.2016 um 21:56 schrieb R Smith: > > > On 2016/03/10 10:41 PM, asdf asdf wrote: >> Hello, >> what do you mean, please ? What code is not shown:my own code (and what >> could be the cause then) using the example or what i posted in >> stackoverflow. >> >> I would be happy to solve it. Any information appreciated- > > He means that there is something else that is wrong in your code that > you've used to test this Backup feature. We cannot see your full code, > so we do not know what is wrong with it, but we know something is > wrong because the backup from memory works when we do it, and works > when done like the example. You can easily use the command line > SQLite3.exe tool to test it. > > So, if it works correctly for us, meaning it is not an SQLite bug, but > there might be something in your code that is missing or weird and we > would like to help you find it, however, only if you show us the exact > code you've used to test with. Also the DB schema - some SQL perhaps > to populate the in-memory database. Perhaps something about the schema > is strange and causes the problem, then it might even be a bug - but > we can't know that until we have exactly what you have. > > Thanks, > Ryan > > ___ > sqlite-users mailing list > sqlite-users at mailinglists.sqlite.org > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users -- next part -- #include "stdafx.h" #include "sqlite3.h" #include #include #include //#include "sqlite3ext.h" int backupDb( sqlite3 *pDb, /* Database to back up */ const char *zFilename, /* Name of file to back up to */ void(*xProgress)(int, int) /* Progress function to invoke */ ){ int rc; /* Function return code */ sqlite3 *pFile; /* Database connection opened on zFilename */ sqlite3_backup *pBackup;/* Backup handle used to copy data */ /* Open the database file identified by zFilename. */ rc = sqlite3_open(zFilename, ); if( rc==SQLITE_OK ){ /* Open the sqlite3_backup object used to accomplish the transfer */ pBackup = sqlite3_backup_init(pFile, "main", pDb, "main"); if( pBackup ){ /* Each iteration of this loop copies 5 database pages from database ** pDb to the backup database. If the return value of backup_step() ** indicates that there are still further pages to copy, sleep for ** 250 ms before repeating. */ do { rc = sqlite3_backup_step(pBackup, 5); if(xProgress != nullptr) { xProgress( sqlite3_backup_remaining(pBackup), sqlite3_backup_pagecount(pBackup) ); } if( rc==SQLITE_OK || rc==SQLITE_BUSY || rc==SQLITE_LOCKED ){ sqlite3_sleep(250); } } while( rc==SQLITE_OK || rc==SQLITE_BUSY || rc==SQLITE_LOCKED ); /* Release resources allocated by backup_init(). */ (void)sqlite3_backup_finish(pBackup); } rc = sqlite3_errcode(pFile); } /* Close the database connection opened on database file zFilename ** and return the result of this function. */ (void)sqlite3_close(pFile); return rc; } boolbackup_test_sqlite_mem(void) { sqlite3*db=nullptr; /// create memory db if(sqlite3_open(":memory:", ) == SQLITE_OK) { /// create table std::string sql = "CREATE TABLE IF NOT EXISTS [stock] (" "[sid] VARCHAR(40) UNIQUE NOT NULL PRIMARY KEY," "[price] FLOAT " " ) "; char* db_err = nullptr; if(sqlite3_exec(db, sql.c_str(), nullptr, nullptr, _err) == SQLITE_OK) { /// fill table with 1 records for(int i=0;i < 1;i++) { std::ostringstream sstr; sstr<<"INSERT INTO stock (sid,price) VALUES("; sstr<<"'"<<i<<"',"; sstr<<(double) i / 7; sstr<<")"; sql=sstr.str(); if(sqlite3_exec(db, sql.c_str(), nullptr, nullptr, _err) != SQLITE_OK) { std::cout<<"\nsql error: "<<sql.c_str(); return false; } } /// check we have content sqlite3_stmt* stmt=nullptr; sql="SELECT count(*) FROM stock"; int r
[sqlite] backup memory database not working
Hello, what do you mean, please ? What code is not shown:my own code (and what could be the cause then) using the example or what i posted in stackoverflow. I would be happy to solve it. Any information appreciated- Am 10.03.2016 um 20:39 schrieb Clemens Ladisch: > asdf asdf wrote: >> Backing up a file database works well;not so memory. >> >> I described the issue here: >> http://stackoverflow.com/questions/35834529/sqlite-backup-memory-database-c > There is an error in your code. Which you have not shown. > > > Regards, > Clemens > ___ > sqlite-users mailing list > sqlite-users at mailinglists.sqlite.org > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
[sqlite] backup memory database not working
Hello, the examples for the back API as exposed here: https://www.sqlite.org/backup.html work not for memory database. Tested with latest amalgamation VC++ VS 2013. Backing up a file database works well;not so memory. I described the issue here: http://stackoverflow.com/questions/35834529/sqlite-backup-memory-database-c Thank you for help