diff options
| author | 2015-04-19 22:30:21 -0400 | |
|---|---|---|
| committer | 2015-04-19 22:30:21 -0400 | |
| commit | a308f430f694423064ebc86fd0506c8c6fdb3d93 (patch) | |
| tree | ceacd24fecf92f40980f8d8f3fd169e317c886af /SQLiteStudio3/coreSQLiteStudio/common/readwritelocker.cpp | |
| parent | a5b034d4a9c44f9bc1e83b01de82530f8fc63013 (diff) | |
Imported Upstream version 3.0.5upstream/3.0.5
Diffstat (limited to 'SQLiteStudio3/coreSQLiteStudio/common/readwritelocker.cpp')
| -rw-r--r-- | SQLiteStudio3/coreSQLiteStudio/common/readwritelocker.cpp | 55 |
1 files changed, 9 insertions, 46 deletions
diff --git a/SQLiteStudio3/coreSQLiteStudio/common/readwritelocker.cpp b/SQLiteStudio3/coreSQLiteStudio/common/readwritelocker.cpp index 0eaca75..cdf8110 100644 --- a/SQLiteStudio3/coreSQLiteStudio/common/readwritelocker.cpp +++ b/SQLiteStudio3/coreSQLiteStudio/common/readwritelocker.cpp @@ -1,8 +1,10 @@ #include "readwritelocker.h" #include "parser/lexer.h" +#include "common/utils_sql.h" #include <QReadWriteLock> #include <QReadLocker> #include <QWriteLocker> +#include <QDebug> ReadWriteLocker::ReadWriteLocker(QReadWriteLock* lock, Mode mode) { @@ -47,57 +49,18 @@ void ReadWriteLocker::init(QReadWriteLock* lock, ReadWriteLocker::Mode mode) ReadWriteLocker::Mode ReadWriteLocker::getMode(const QString &query, Dialect dialect, bool noLock) { - static QStringList readOnlyCommands = {"ANALYZE", "EXPLAIN", "PRAGMA"}; - if (noLock) return ReadWriteLocker::NONE; - TokenList tokens = Lexer::tokenize(query, dialect); - int keywordIdx = tokens.indexOf(Token::KEYWORD); - - if (keywordIdx > -1 && readOnlyCommands.contains(tokens[keywordIdx]->value.toUpper())) - return ReadWriteLocker::READ; - - if (keywordIdx > -1 && tokens[keywordIdx]->value.toUpper() == "WITH") + QueryAccessMode queryMode = getQueryAccessMode(query, dialect); + switch (queryMode) { - bool matched = false; - bool isSelect = false; - int depth = 0; - for (TokenPtr token : tokens) - { - switch (token->type) - { - case Token::PAR_LEFT: - depth++; - break; - case Token::PAR_RIGHT: - depth--; - break; - case Token::KEYWORD: - if (depth == 0) - { - QString val = token->value.toUpper(); - if (val == "SELECT") - { - matched = true; - isSelect = true; - } - else if (val == "DELETE" || val == "UPDATE" || val == "INSERT") - { - matched = true; - } - } - break; - default: - break; - } - - if (matched) - break; - } - if (isSelect) + case QueryAccessMode::READ: return ReadWriteLocker::READ; + case QueryAccessMode::WRITE: + return ReadWriteLocker::WRITE; } - return ReadWriteLocker::WRITE; + qCritical() << "Unhandled query access mode:" << static_cast<int>(queryMode); + return ReadWriteLocker::NONE; } |
