aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/coreSQLiteStudio/schemaresolver.cpp
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@ubuntu.com>2017-02-09 04:37:26 -0500
committerLibravatarUnit 193 <unit193@ubuntu.com>2017-02-09 04:37:26 -0500
commitc9d6debf9015b7853c3e061bbc64a555d85e2fcd (patch)
tree53341bc57ae9fbad2beb5b6c08d97a68bee0ec8e /SQLiteStudio3/coreSQLiteStudio/schemaresolver.cpp
parentd5caba2b1f36dc3b92fa705a06097d0597fa2ddd (diff)
parentd9aa870e5d509cc7309ab82dd102a937ab58613a (diff)
Merge tag 'upstream/3.1.1+dfsg1'
Upstream version 3.1.1+dfsg1 # gpg: Signature made Thu 09 Feb 2017 04:37:24 AM EST # gpg: using RSA key 5001E1B09AA3744B # gpg: issuer "unit193@ubuntu.com" # gpg: Good signature from "Unit 193 <unit193@ubuntu.com>" [unknown] # gpg: aka "Unit 193 <unit193@gmail.com>" [unknown] # gpg: WARNING: This key is not certified with a trusted signature! # gpg: There is no indication that the signature belongs to the owner. # Primary key fingerprint: 8DB3 E586 865D 2B4A 2B18 5A5C 5001 E1B0 9AA3 744B
Diffstat (limited to 'SQLiteStudio3/coreSQLiteStudio/schemaresolver.cpp')
-rw-r--r--SQLiteStudio3/coreSQLiteStudio/schemaresolver.cpp76
1 files changed, 64 insertions, 12 deletions
diff --git a/SQLiteStudio3/coreSQLiteStudio/schemaresolver.cpp b/SQLiteStudio3/coreSQLiteStudio/schemaresolver.cpp
index 0044c3e..48fe541 100644
--- a/SQLiteStudio3/coreSQLiteStudio/schemaresolver.cpp
+++ b/SQLiteStudio3/coreSQLiteStudio/schemaresolver.cpp
@@ -1,5 +1,6 @@
#include "schemaresolver.h"
#include "db/db.h"
+#include "db/sqlresultsrow.h"
#include "parser/parsererror.h"
#include "parser/ast/sqlitecreatetable.h"
#include "parser/ast/sqlitecreateindex.h"
@@ -303,6 +304,67 @@ QString SchemaResolver::getObjectDdl(const QString &database, const QString &nam
return cache.object(key, true)->toString();
// Get the DDL
+ QString resStr = getObjectDdlWithSimpleName(dbName, lowerName, targetTable, type);
+ if (resStr.isNull())
+ resStr = getObjectDdlWithDifficultName(dbName, lowerName, targetTable, type);
+
+ // If the DDL doesn't have semicolon at the end (usually the case), add it.
+ if (!resStr.trimmed().endsWith(";"))
+ resStr += ";";
+
+ if (useCache)
+ cache.insert(key, new QVariant(resStr));
+
+ // Return the DDL
+ return resStr;
+}
+
+QString SchemaResolver::getObjectDdlWithDifficultName(const QString &dbName, const QString &lowerName, QString targetTable, SchemaResolver::ObjectType type)
+{
+ //
+ // Slower, but works with Russian names, etc, because "string lower" is done only at Qt level, not at SQLite level.
+ //
+ QString typeStr = objectTypeToString(type);
+ SqlQueryPtr queryResults;
+ if (type != ANY)
+ {
+ queryResults = db->exec(QString(
+ "SELECT name, sql FROM %1.%4 WHERE type = '%3';").arg(dbName, typeStr, targetTable),
+ dbFlags
+ );
+
+ }
+ else
+ {
+ queryResults = db->exec(QString(
+ "SELECT name, sql FROM %1.%3;").arg(dbName, targetTable),
+ dbFlags
+ );
+ }
+
+ // Validate query results
+ if (queryResults->isError())
+ {
+ qDebug() << "Could not get object's DDL:" << dbName << "." << lowerName << ", details:" << queryResults->getErrorText();
+ return QString::null;
+ }
+
+ // The DDL string
+ SqlResultsRowPtr row;
+ while (queryResults->hasNext())
+ {
+ row = queryResults->next();
+ if (row->value("name").toString().toLower() != lowerName)
+ continue;
+
+ return row->value("sql").toString();
+ }
+ return QString();
+}
+
+QString SchemaResolver::getObjectDdlWithSimpleName(const QString &dbName, const QString &lowerName, QString targetTable, SchemaResolver::ObjectType type)
+{
+ QString typeStr = objectTypeToString(type);
QVariant results;
SqlQueryPtr queryResults;
if (type != ANY)
@@ -324,23 +386,13 @@ QString SchemaResolver::getObjectDdl(const QString &database, const QString &nam
// Validate query results
if (queryResults->isError())
{
- qDebug() << "Could not get object's DDL:" << dbName << "." << name << ", details:" << queryResults->getErrorText();
+ qDebug() << "Could not get object's DDL:" << dbName << "." << lowerName << ", details:" << queryResults->getErrorText();
return QString::null;
}
// The DDL string
results = queryResults->getSingleCell();
- QString resStr = results.toString();
-
- // If the DDL doesn't have semicolon at the end (usually the case), add it.
- if (!resStr.trimmed().endsWith(";"))
- resStr += ";";
-
- if (useCache)
- cache.insert(key, new QVariant(resStr));
-
- // Return the DDL
- return resStr;
+ return results.toString();
}
QStringList SchemaResolver::getColumnsFromDdlUsingPragma(const QString& ddl)