Import SQLite database using Qt/QSqlDatabase -


i have 2 separate applications, 1 placed @ production @ office, , need copy of sqlite database generated , updated @ production side.

until i've tried 2 approches:

  1. copy entire sqlite file production-application , "redirect" qsqldatabase-handles file (was not able work, many connections opened , not closable)
  2. access sqlite-db on network, query data , insert missing data using sql (works, since there lot of data takes time)

are there possibilities import or maybe override existing database (or single tables, placed in different files), there still open connections?

using: qt 4.8, sqlite, windows 7, vs2010

so able reach goal using sqlite backup api (which distributed .h , .c qt versions). on documentation page sqlite backup there few examples, database copied either file in-memory db, or in-memory file. in case used following function (1:1 doc page, several comments removed):

int loadorsavedb(sqlite3 *pinmemory, const char *zfilename, int issave){   int rc;                   /* function return code */   sqlite3 *pfile;           /* database connection opened on zfilename */   sqlite3_backup *pbackup;  /* backup object used copy data */   sqlite3 *pto;             /* database copy (pfile or pinmemory) */   sqlite3 *pfrom;           /* database copy (pfile or pinmemory) */    /* open database file identified zfilename. exit if fails   ** reason. */   rc = sqlite3_open(zfilename, &pfile);   if( rc==sqlite_ok ){      pfrom = (issave ? pinmemory : pfile);     pto   = (issave ? pfile     : pinmemory);      pbackup = sqlite3_backup_init(pto, "main", pfrom, "main");     if( pbackup ){       (void)sqlite3_backup_step(pbackup, -1);       (void)sqlite3_backup_finish(pbackup);     }     rc = sqlite3_errcode(pto);   }    (void)sqlite3_close(pfile);   return rc; } 

the additional steps handle needed in function above were:

1.get sqlite-handle qsqldatabase

qvariant destvar = database.driver()->handle(); 

2.check handle validity , cast sqlite3*

if(destvar.isvalid() && qstrcmp(destvar.typename(), "sqlite3*") == 0) {     sqlite3* destination = *static_cast<sqlite3 **>(destvar.data());     ... } 

thanks cl. (who pointing right direction).


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -