QSqlRecord qt4 sqlite3 dump to file int erkennen.
Verfasst: 25. April 2006 13:51
Ich habe ein sqlite3 dump export fertig bekommen .. dank auch an dieses forum... er funktioniert doch nun im TablesDump... gibt es sowas is_numeric? bool um zahlen nicht zu quoten?..
Code: Alles auswählen
void Gui_Main::PrepareDump()
{
QString dumpfile = "sqlinsert.sql"; /* put to file */
QSqlQuery query;
QString table_name;
QString table_typ;
QString table_sqlinsert;
QString tablequery ="SELECT name, type, sql FROM sqlite_master WHERE type!='meta' AND sql NOT NULL ORDER BY name";
query.exec(tablequery);
QSqlRecord rec = query.record(); /* nummer col */
file_put_contents(dumpfile,"BEGIN TRANSACTION;\n"); /* reset file */
while (query.next()) {
table_name = query.value(rec.indexOf("name")).toString();
table_typ = query.value(rec.indexOf("type")).toString();
table_sqlinsert = query.value(rec.indexOf("sql")).toString();
file_put_contents_append(dumpfile,table_sqlinsert+";");
TablesDump(table_name,dumpfile);
}
file_put_contents_append(dumpfile,"COMMIT;"); /* last line append end \n */
}
void Gui_Main::TablesDump(QString t,QString file)
{
QString tablequery ="SELECT * FROM "+t;
QString line;
QString rowone;
QSqlQuery query;
query.exec(tablequery);
QSqlRecord rec = query.record(); /* nummer col */
int numcol = rec.count();
int loop;
while (query.next()) {
line="";
for(loop=0; loop < numcol; loop++) {
rowone = query.value(loop).toString();
if (loop !=numcol-1) {
line = line+QString( "'%1'," ).arg( rowone );
} else {
line = line+QString( "'%1'" ).arg( rowone );
}
}
line.prepend("INSERT INTO "+t+" VALUES (");
line.append(");");
file_put_contents_append(file,line);
}
}