Visitar URL original
Merge pull request #4198 from anandghegde/fix-sql-export-generated-co… · sqlitebrowser/sqlitebrowser@25c6eff · GitHub
Skip to content

Commit 25c6eff

Browse files
authored
Merge pull request #4198 from anandghegde/fix-sql-export-generated-columns
Leave generated columns out of Export to SQL
2 parents 73d3e07 + 106d7cb commit 25c6eff

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

‎src/sqlitedb.cpp‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,19 @@ bool DBBrowserDB::dump(const QString& filePath,
990990
// get columns
991991
sqlb::StringVector cols = it->fieldNames();
992992

993+
// Generated columns cannot be inserted into, so leave them out of both the SELECT and the
994+
// INSERT statements, like the sqlite3 shell's .dump does
993995
std::string sQuery = "SELECT * FROM " + sqlb::escapeIdentifier(it->name());
996+
if(std::any_of(it->fields.begin(), it->fields.end(), [](const sqlb::Field& f) { return f.generated() != nullptr; }))
997+
{
998+
cols.clear();
999+
for(const sqlb::Field& f : it->fields)
1000+
{
1001+
if(!f.generated())
1002+
cols.push_back(f.name());
1003+
}
1004+
sQuery = "SELECT " + sqlb::joinStringVector(sqlb::escapeIdentifier(cols), ",") + " FROM " + sqlb::escapeIdentifier(it->name());
1005+
}
9941006
sqlite3_stmt *stmt;
9951007
QString lineSep(QString(")%1\n").arg(insertNewSyntx?',':';'));
9961008

0 commit comments

Comments
 (0)