aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/coreSQLiteStudio/db/sqlquery.cpp
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@ubuntu.com>2014-12-06 17:33:25 -0500
committerLibravatarUnit 193 <unit193@ubuntu.com>2014-12-06 17:33:25 -0500
commit7167ce41b61d2ba2cdb526777a4233eb84a3b66a (patch)
treea35c14143716e1f2c98f808c81f89426045a946f /SQLiteStudio3/coreSQLiteStudio/db/sqlquery.cpp
Imported Upstream version 2.99.6upstream/2.99.6
Diffstat (limited to 'SQLiteStudio3/coreSQLiteStudio/db/sqlquery.cpp')
-rw-r--r--SQLiteStudio3/coreSQLiteStudio/db/sqlquery.cpp142
1 files changed, 142 insertions, 0 deletions
diff --git a/SQLiteStudio3/coreSQLiteStudio/db/sqlquery.cpp b/SQLiteStudio3/coreSQLiteStudio/db/sqlquery.cpp
new file mode 100644
index 0000000..4217711
--- /dev/null
+++ b/SQLiteStudio3/coreSQLiteStudio/db/sqlquery.cpp
@@ -0,0 +1,142 @@
+#include "sqlquery.h"
+#include "db/sqlerrorcodes.h"
+
+SqlQuery::~SqlQuery()
+{
+}
+
+bool SqlQuery::execute()
+{
+ if (queryArgs.type() == QVariant::Hash)
+ return execInternal(queryArgs.toHash());
+ else
+ return execInternal(queryArgs.toList());
+}
+
+SqlResultsRowPtr SqlQuery::next()
+{
+ if (preloaded)
+ {
+ if (preloadedRowIdx >= preloadedData.size())
+ return SqlResultsRowPtr();
+
+ return preloadedData[preloadedRowIdx++];
+ }
+ return nextInternal();
+}
+
+bool SqlQuery::hasNext()
+{
+ if (preloaded)
+ return (preloadedRowIdx < preloadedData.size());
+
+ return hasNextInternal();
+}
+
+qint64 SqlQuery::rowsAffected()
+{
+ return affected;
+}
+
+QList<SqlResultsRowPtr> SqlQuery::getAll()
+{
+ if (!preloaded)
+ preload();
+
+ return preloadedData;
+}
+
+void SqlQuery::preload()
+{
+ if (preloaded)
+ return;
+
+ QList<SqlResultsRowPtr> allRows;
+ while (hasNextInternal())
+ allRows << nextInternal();
+
+ preloadedData = allRows;
+ preloaded = true;
+ preloadedRowIdx = 0;
+}
+
+QVariant SqlQuery::getSingleCell()
+{
+ SqlResultsRowPtr row = next();
+ if (row.isNull())
+ return QVariant();
+
+ return row->value(0);
+}
+
+bool SqlQuery::isError()
+{
+ return getErrorCode() != 0;
+}
+
+bool SqlQuery::isInterrupted()
+{
+ return SqlErrorCode::isInterrupted(getErrorCode());
+}
+
+RowId SqlQuery::getInsertRowId()
+{
+ return insertRowId;
+}
+
+qint64 SqlQuery::getRegularInsertRowId()
+{
+ return insertRowId["ROWID"].toLongLong();
+}
+
+QString SqlQuery::getQuery() const
+{
+ return query;
+}
+
+void SqlQuery::setFlags(Db::Flags flags)
+{
+ this->flags = flags;
+}
+
+void SqlQuery::clearArgs()
+{
+ queryArgs = QVariant();
+}
+
+void SqlQuery::setArgs(const QList<QVariant>& args)
+{
+ queryArgs = args;
+}
+
+void SqlQuery::setArgs(const QHash<QString, QVariant>& args)
+{
+ queryArgs = args;
+}
+
+
+void RowIdConditionBuilder::setRowId(const RowId& rowId)
+{
+ static const QString argTempalate = QStringLiteral(":rowIdArg%1");
+
+ QString arg;
+ QHashIterator<QString,QVariant> it(rowId);
+ int i = 0;
+ while (it.hasNext())
+ {
+ it.next();
+ arg = argTempalate.arg(i++);
+ queryArgs[arg] = it.value();
+ conditions << it.key() + " = " + arg;
+ }
+}
+
+const QHash<QString, QVariant>& RowIdConditionBuilder::getQueryArgs()
+{
+ return queryArgs;
+}
+
+QString RowIdConditionBuilder::build()
+{
+ return conditions.join(" AND ");
+}