diff options
| author | 2021-12-17 07:06:30 -0500 | |
|---|---|---|
| committer | 2021-12-17 07:06:30 -0500 | |
| commit | 1fdc150116cad39aae5c5da407c3312b47a59e3a (patch) | |
| tree | 123c79a4d7ad2d45781ba03ce939f7539fb428d8 /Plugins/SqlExport/sqlexport.cpp | |
| parent | feda8a7db8d1d7c5439aa8f8feef7cc0dd2b59a0 (diff) | |
New upstream version 3.3.3+dfsg1.upstream/3.3.3+dfsg1
Diffstat (limited to 'Plugins/SqlExport/sqlexport.cpp')
| -rw-r--r-- | Plugins/SqlExport/sqlexport.cpp | 62 |
1 files changed, 46 insertions, 16 deletions
diff --git a/Plugins/SqlExport/sqlexport.cpp b/Plugins/SqlExport/sqlexport.cpp index 0ae91ff..331bfd6 100644 --- a/Plugins/SqlExport/sqlexport.cpp +++ b/Plugins/SqlExport/sqlexport.cpp @@ -44,10 +44,9 @@ bool SqlExport::beforeExportQueryResults(const QString& query, QList<QueryExecut UNUSED(providedData); static_qstring(dropDdl, "DROP TABLE IF EXISTS %1;"); - Dialect dialect = db->getDialect(); QStringList colDefs; for (QueryExecutor::ResultColumnPtr resCol : columns) - colDefs << wrapObjIfNeeded(resCol->displayName, dialect); + colDefs << wrapObjIfNeeded(resCol->displayName); this->columns = colDefs.join(", "); @@ -61,10 +60,10 @@ bool SqlExport::beforeExportQueryResults(const QString& query, QList<QueryExecut writeBegin(); + theTable = wrapObjIfNeeded(cfg.SqlExport.QueryTable.get()); if (!cfg.SqlExport.GenerateCreateTable.get()) return true; - theTable = wrapObjIfNeeded(cfg.SqlExport.QueryTable.get(), dialect); QString ddl = "CREATE TABLE " + theTable + " (" + this->columns + ");"; writeln(""); @@ -88,6 +87,14 @@ bool SqlExport::exportTable(const QString& database, const QString& table, const { UNUSED(createTable); UNUSED(providedData); + + tableGeneratedColumns.clear(); + for (SqliteCreateTable::Column* col : createTable->columns) + { + if (col->hasConstraint(SqliteCreateTable::Column::Constraint::GENERATED)) + tableGeneratedColumns << col->name; + } + return exportTable(database, table, columnNames, ddl); } @@ -102,11 +109,20 @@ bool SqlExport::exportTable(const QString& database, const QString& table, const { static_qstring(dropDdl, "DROP TABLE IF EXISTS %1;"); - Dialect dialect = db->getDialect(); - + generatedColumnIndexes.clear(); QStringList colList; + int colIdx = 0; for (const QString& colName : columnNames) - colList << wrapObjIfNeeded(colName, dialect); + { + if (tableGeneratedColumns.contains(colName, Qt::CaseInsensitive)) + { + generatedColumnIndexes << colIdx++; + continue; + } + + colList << wrapObjIfNeeded(colName); + colIdx++; + } columns = colList.join(", "); @@ -121,7 +137,7 @@ bool SqlExport::exportTable(const QString& database, const QString& table, const writeln(""); writeln(tr("-- Table: %1").arg(fullName)); - theTable = getNameForObject(database, table, true, dialect); + theTable = getNameForObject(database, table, true); if (cfg.SqlExport.GenerateDrop.get()) writeln(formatQuery(dropDdl.arg(theTable))); @@ -132,7 +148,7 @@ bool SqlExport::exportTable(const QString& database, const QString& table, const bool SqlExport::exportTableRow(SqlResultsRowPtr data) { - QStringList argList = rowToArgList(data); + QStringList argList = rowToArgList(data, true); QString argStr = argList.join(", "); QString sql = "INSERT INTO " + theTable + " (" + columns + ") VALUES (" + argStr + ");"; if (!cfg.SqlExport.FormatDdlsOnly.get()) @@ -167,7 +183,7 @@ bool SqlExport::exportIndex(const QString& database, const QString& name, const writeln(""); writeln(tr("-- Index: %1").arg(index)); - QString fullName = getNameForObject(database, name, true, db->getDialect()); + QString fullName = getNameForObject(database, name, true); if (cfg.SqlExport.GenerateDrop.get()) writeln(formatQuery(dropDdl.arg(fullName))); @@ -184,7 +200,7 @@ bool SqlExport::exportTrigger(const QString& database, const QString& name, cons writeln(""); writeln(tr("-- Trigger: %1").arg(trig)); - QString fullName = getNameForObject(database, name, true, db->getDialect()); + QString fullName = getNameForObject(database, name, true); if (cfg.SqlExport.GenerateDrop.get()) writeln(dropDdl.arg(fullName)); @@ -201,7 +217,7 @@ bool SqlExport::exportView(const QString& database, const QString& name, const Q writeln(""); writeln(tr("-- View: %1").arg(view)); - QString fullName = getNameForObject(database, name, true, db->getDialect()); + QString fullName = getNameForObject(database, name, true); if (cfg.SqlExport.GenerateDrop.get()) writeln(dropDdl.arg(fullName)); @@ -254,18 +270,32 @@ QString SqlExport::formatQuery(const QString& sql) return sql.trimmed() + ";"; } -QString SqlExport::getNameForObject(const QString& database, const QString& name, bool wrapped, Dialect dialect) +QString SqlExport::getNameForObject(const QString& database, const QString& name, bool wrapped) { - QString obj = wrapped ? wrapObjIfNeeded(name, dialect) : name; + QString obj = wrapped ? wrapObjIfNeeded(name) : name; if (!database.isNull() && database.toLower() != "main") - obj = (wrapped ? wrapObjIfNeeded(database, dialect) : database) + "." + obj; + obj = (wrapped ? wrapObjIfNeeded(database) : database) + "." + obj; return obj; } -QStringList SqlExport::rowToArgList(SqlResultsRowPtr row) +QStringList SqlExport::rowToArgList(SqlResultsRowPtr row, bool honorGeneratedColumns) { - return valueListToSqlList(row->valueList(), db->getDialect()); + if (honorGeneratedColumns) + { + QList<QVariant> filteredValues; + int i = 0; + for (const QVariant& value : row->valueList()) + { + if (generatedColumnIndexes.contains(i++)) + continue; + + filteredValues << value; + } + return valueListToSqlList(filteredValues); + } + + return valueListToSqlList(row->valueList()); } void SqlExport::validateOptions() |
