diff options
| author | 2016-06-13 18:42:57 -0400 | |
|---|---|---|
| committer | 2016-06-13 18:42:57 -0400 | |
| commit | 65d5f68cc6dc81799c5a5d90400a2c1f0dd02547 (patch) | |
| tree | 6f245ba901b87ef42fed69965aea22f5eea6b590 /SQLiteStudio3/coreSQLiteStudio/dbobjectorganizer.cpp | |
| parent | aeb6bad01630d325a4e768e798a7a6d44e18fdaf (diff) | |
| parent | 5d9314f134ddd3dc4c853e398ac90ba247fb2e4f (diff) | |
Merge tag 'upstream/3.1.0'
Upstream version 3.1.0
# gpg: Signature made Mon 13 Jun 2016 06:42:54 PM EDT using RSA key ID EBE9BD91
# gpg: Good signature from "Unit 193 <unit193@gmail.com>"
# gpg: aka "Unit 193 <unit193@ninthfloor.org>"
# gpg: aka "Unit 193 <unit193@ubuntu.com>"
# gpg: aka "Unit 193 <unit193@ninthfloor.com>"
Diffstat (limited to 'SQLiteStudio3/coreSQLiteStudio/dbobjectorganizer.cpp')
| -rw-r--r-- | SQLiteStudio3/coreSQLiteStudio/dbobjectorganizer.cpp | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/SQLiteStudio3/coreSQLiteStudio/dbobjectorganizer.cpp b/SQLiteStudio3/coreSQLiteStudio/dbobjectorganizer.cpp index f8c51dc..542668b 100644 --- a/SQLiteStudio3/coreSQLiteStudio/dbobjectorganizer.cpp +++ b/SQLiteStudio3/coreSQLiteStudio/dbobjectorganizer.cpp @@ -559,7 +559,21 @@ bool DbObjectOrganizer::copySimpleObjectToDb(const QString& name, const QString& if (convertedDdl.trimmed() == ";") // empty query, result of ignored errors in UI return true; - SqlQueryPtr result = dstDb->exec(convertedDdl); + SqlQueryPtr result; + + if (!attachName.isNull()) + { + convertedDdl = prefixSimpleObjectWithAttachName(name, convertedDdl); + if (convertedDdl.isNull()) + return false; + + result = srcDb->exec(convertedDdl); + } + else + { + result = dstDb->exec(convertedDdl); + } + if (result->isError()) { notifyError(errorMessage.arg(result->getErrorText())); @@ -750,6 +764,37 @@ bool DbObjectOrganizer::execConfirmFunctionInMainThread(const QStringList& table return res; } +QString DbObjectOrganizer::prefixSimpleObjectWithAttachName(const QString& objName, const QString& ddl) +{ + Parser parser(srcDb->getDialect()); + if (!parser.parse(ddl)) + { + qDebug() << "Parsing error while copying or moving object:" << objName << ", details:" << parser.getErrorString(); + notifyError(tr("Could not parse object '%1' in order to move or copy it.").arg(objName)); + return QString(); + } + + if (parser.getQueries().isEmpty()) + { + qDebug() << "Empty queries from parser while copying or moving object:" << objName; + notifyError(tr("Could not parse object '%1' in order to move or copy it.").arg(objName)); + return QString(); + } + + SqliteQueryPtr query = parser.getQueries().first(); + SqliteDdlWithDbContextPtr ddlWithDb = query.dynamicCast<SqliteDdlWithDbContext>(); + if (!ddlWithDb) + { + qDebug() << "Not instance of SqliteDdlWithDbContext while copying or moving object:" << objName << ", it's type is:" << (int)query->queryType; + notifyError(tr("Could not parse object '%1' in order to move or copy it.").arg(objName)); + return QString(); + } + + ddlWithDb->setTargetDatabase(attachName); + query->rebuildTokens(); + return query->tokens.detokenize(); +} + void DbObjectOrganizer::processPreparationFinished() { if (errorsToConfirm.size() > 0 && !conversionErrorsConfimFunction(errorsToConfirm)) |
