Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/3.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelsalawa committed Dec 28, 2024
2 parents dd2309e + 59403ee commit 5c0b20d
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 2 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

### 3.4.13
- BUGFIX: #5183 Fixed completer proposals in the column names of the INSERT INTO statement.
- BUGFIX: #5184 Fixed completer to show tables from implicitly attached database in case of 'SELECT other_database.'
- BUGFIX: System tables (sqlite_*) are now pushed further in the competer proposals.
- BUGFIX: Restored missing completer entries: string, number, BLOB literal.
- BUGFIX: Fixed Linux installer issue related to the logname command on some Linux distributions.

### 3.4.12
- BIGFIX: #5179 Fixed results returned from query joining the same table twice.
Expand Down
5 changes: 5 additions & 0 deletions SQLiteStudio3/Tests/TestUtils/dbmanagermock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ QStringList DbManagerMock::getDbNames()
return QStringList();
}

QStringList DbManagerMock::getValidDbNames()
{
return QStringList();
}

Db* DbManagerMock::getByName(const QString&, Qt::CaseSensitivity)
{
return nullptr;
Expand Down
1 change: 1 addition & 0 deletions SQLiteStudio3/Tests/TestUtils/dbmanagermock.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class DbManagerMock : public DbManager
QList<Db*> getValidDbList();
QList<Db*> getConnectedDbList();
QStringList getDbNames();
QStringList getValidDbNames();
Db* getByName(const QString&, Qt::CaseSensitivity);
Db* getByPath(const QString&);
Db* createInMemDb(bool = false);
Expand Down
3 changes: 3 additions & 0 deletions SQLiteStudio3/coreSQLiteStudio/completionhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,9 @@ QList<ExpectedTokenPtr> CompletionHelper::getColumns(const QString &prefixTable)
label = prefixTable+" = "+table;
}

if (!dbName.isNull())
dbName = translateDatabase(dbName);

// CREATE TRIGGER has a special "old" and "new" keywords as aliases for deleted/inserted/updated rows.
// They should refer to a table that the trigger is created for.
QString tableLower = table;
Expand Down
7 changes: 6 additions & 1 deletion SQLiteStudio3/coreSQLiteStudio/parser/ast/sqliteexpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,9 @@ QStringList SqliteExpr::getTablesInStatement()

QStringList SqliteExpr::getDatabasesInStatement()
{
if (database.isNull() && !table.isNull() && validDbNames.contains(table, Qt::CaseInsensitive))
return getStrListFromValue(table); // it's a "db.", not a "db.table."

return getStrListFromValue(database);
}

Expand Down Expand Up @@ -494,7 +497,9 @@ TokenList SqliteExpr::getTableTokensInStatement()
TokenList SqliteExpr::getDatabaseTokensInStatement()
{
TokenList list;
if (!database.isNull())
if (database.isNull() && !table.isNull() && validDbNames.contains(table, Qt::CaseInsensitive))
list << tokens[0]; // it's a "db.", not a "db.table."
else if (!database.isNull())
list << tokens[0];

return list;
Expand Down
14 changes: 14 additions & 0 deletions SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitestatement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "../token.h"
#include "../lexer.h"
#include "common/unused.h"
#include "services/dbmanager.h"
#include <QDebug>

SqliteStatement::SqliteStatement()
Expand Down Expand Up @@ -35,6 +36,7 @@ QStringList SqliteStatement::getContextTables(bool checkParent, bool checkChilds

QStringList SqliteStatement::getContextDatabases(bool checkParent, bool checkChilds)
{
prepareDbNames();
return getContextDatabases(this, checkParent, checkChilds);
}

Expand All @@ -50,6 +52,7 @@ TokenList SqliteStatement::getContextTableTokens(bool checkParent, bool checkChi

TokenList SqliteStatement::getContextDatabaseTokens(bool checkParent, bool checkChilds)
{
prepareDbNames();
return getContextDatabaseTokens(this, checkParent, checkChilds);
}

Expand Down Expand Up @@ -125,7 +128,10 @@ QStringList SqliteStatement::getContextDatabases(SqliteStatement *caller, bool c
{
QStringList results = getDatabasesInStatement();
for (SqliteStatement* stmt : getContextStatements(caller, checkParent, checkChilds))
{
stmt->validDbNames = this->validDbNames;
results += stmt->getContextDatabases(this, checkParent, checkChilds);
}

return results;
}
Expand All @@ -152,7 +158,10 @@ TokenList SqliteStatement::getContextDatabaseTokens(SqliteStatement *caller, boo
{
TokenList results = getDatabaseTokensInStatement();
for (SqliteStatement* stmt : getContextStatements(caller, checkParent, checkChilds))
{
stmt->validDbNames = this->validDbNames;
results += stmt->getContextDatabaseTokens(this, checkParent, checkChilds);
}

return results;
}
Expand Down Expand Up @@ -236,6 +245,11 @@ QList<SqliteStatement *> SqliteStatement::getContextStatements(SqliteStatement *
return results;
}

void SqliteStatement::prepareDbNames()
{
validDbNames = DBLIST->getValidDbNames();
}

TokenList SqliteStatement::extractPrintableTokens(const TokenList &tokens, bool skipMeaningless)
{
TokenList list;
Expand Down
8 changes: 8 additions & 0 deletions SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitestatement.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,16 @@ class API_EXPORT SqliteStatement : public QObject
*/
TokenPtr dbTokenForFullObjects;

/**
* @brief List of database names as seen in the side Database List.
* It is resoled at top-level statement being queried for databases and then it's propagated down to all child statements.
* It helps to identify whether the xyz in "xyz." is a table or a database prefix.
*/
QStringList validDbNames;

private:
QList<SqliteStatement*> getContextStatements(SqliteStatement* caller, bool checkParent, bool checkChilds);
void prepareDbNames();
};

#endif // SQLITESTATEMENT_H
8 changes: 7 additions & 1 deletion SQLiteStudio3/coreSQLiteStudio/services/dbmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class API_EXPORT DbManager : public QObject

/**
* @brief Gives list of valid databases.
* @return List of open databases.
* @return List of valid databases.
*/
virtual QList<Db*> getValidDbList() = 0;

Expand All @@ -123,6 +123,12 @@ class API_EXPORT DbManager : public QObject
*/
virtual QStringList getDbNames() = 0;

/**
* @brief Gives list of valid database names.
* @return List of database names that are registered and valid (no errors) in the application.
*/
virtual QStringList getValidDbNames() = 0;

/**
* @brief Gives database object by its name.
* @param name Symbolic name of the database.
Expand Down
12 changes: 12 additions & 0 deletions SQLiteStudio3/coreSQLiteStudio/services/impl/dbmanagerimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,18 @@ QStringList DbManagerImpl::getDbNames()
return nameToDb.keys();
}

QStringList DbManagerImpl::getValidDbNames()
{
QReadLocker lock(&listLock);
QStringList result;
for (Db* db : dbList)
{
if (db->isValid())
result << db->getName();
}
return result;
}

Db* DbManagerImpl::getByName(const QString &name, Qt::CaseSensitivity cs)
{
QReadLocker lock(&listLock);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class API_EXPORT DbManagerImpl : public DbManager
QList<Db*> getValidDbList();
QList<Db*> getConnectedDbList();
QStringList getDbNames();
QStringList getValidDbNames();
Db* getByName(const QString& name, Qt::CaseSensitivity cs = Qt::CaseInsensitive);
Db* getByPath(const QString& path);
Db* createInMemDb(bool pureInit = false);
Expand Down

0 comments on commit 5c0b20d

Please sign in to comment.