mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 02:50:46 -06:00
Completion of qualified table names
This adds the schema names to the possible completions and adds support for cascading completion of schema.table.field. See related issue #1433
This commit is contained in:
@@ -475,9 +475,10 @@ void MainWindow::populateStructure(const QString& old_table)
|
||||
return;
|
||||
|
||||
// Update table and column names for syntax highlighting
|
||||
SqlUiLexer::TablesAndColumnsMap tablesToColumnsMap;
|
||||
SqlUiLexer::QualifiedTablesMap qualifiedTablesMap;
|
||||
for(auto it=db.schemata.constBegin();it!=db.schemata.constEnd();++it)
|
||||
{
|
||||
SqlUiLexer::TablesAndColumnsMap tablesToColumnsMap;
|
||||
objectMap tab = db.getBrowsableObjects(it.key());
|
||||
for(auto it : tab)
|
||||
{
|
||||
@@ -487,8 +488,9 @@ void MainWindow::populateStructure(const QString& old_table)
|
||||
for(const sqlb::FieldInfo& f : fi)
|
||||
tablesToColumnsMap[objectname].append(f.name);
|
||||
}
|
||||
qualifiedTablesMap[it.key()] = tablesToColumnsMap;
|
||||
}
|
||||
SqlTextEdit::sqlLexer->setTableNames(tablesToColumnsMap);
|
||||
SqlTextEdit::sqlLexer->setTableNames(qualifiedTablesMap);
|
||||
ui->editLogApplication->reloadKeywords();
|
||||
ui->editLogUser->reloadKeywords();
|
||||
for(int i=0;i<ui->tabSqlAreas->count();i++)
|
||||
|
||||
@@ -130,24 +130,31 @@ void SqlUiLexer::setupAutoCompletion()
|
||||
}
|
||||
}
|
||||
|
||||
void SqlUiLexer::setTableNames(const TablesAndColumnsMap& tables)
|
||||
void SqlUiLexer::setTableNames(const QualifiedTablesMap& tables)
|
||||
{
|
||||
// Update list for auto completion
|
||||
autocompleteApi->clear();
|
||||
listTables.clear();
|
||||
setupAutoCompletion();
|
||||
for(auto it=tables.constBegin();it!=tables.constEnd();++it)
|
||||
for(auto itSchemas=tables.constBegin();itSchemas!=tables.constEnd();++itSchemas)
|
||||
{
|
||||
for(const QString& field : it.value()) {
|
||||
// Completion for table.field
|
||||
autocompleteApi->add(it.key() + "?" + QString::number(SqlUiLexer::ApiCompleterIconIdTable) + "." +
|
||||
field + "?" + QString::number(SqlUiLexer::ApiCompleterIconIdColumn));
|
||||
// Completion for isolated field
|
||||
autocompleteApi->add(field + "?" + QString::number(SqlUiLexer::ApiCompleterIconIdColumn));
|
||||
for(auto itTables=itSchemas.value().constBegin();itTables!=itSchemas.value().constEnd();++itTables)
|
||||
{
|
||||
// Completion for schema.table
|
||||
autocompleteApi->add(itSchemas.key() + "?" + QString::number(SqlUiLexer::ApiCompleterIconIdSchema) + "." +
|
||||
itTables.key() + "?" + QString::number(SqlUiLexer::ApiCompleterIconIdTable));
|
||||
|
||||
for(const QString& field : itTables.value()) {
|
||||
// Completion for table.field
|
||||
autocompleteApi->add(itTables.key() + "?" + QString::number(SqlUiLexer::ApiCompleterIconIdTable) + "." +
|
||||
field + "?" + QString::number(SqlUiLexer::ApiCompleterIconIdColumn));
|
||||
|
||||
// Completion for isolated field
|
||||
autocompleteApi->add(field + "?" + QString::number(SqlUiLexer::ApiCompleterIconIdColumn));
|
||||
}
|
||||
// Store the table name list in order to highlight them in a different colour
|
||||
listTables.append(itTables.key());
|
||||
}
|
||||
// Store the table name list in order to highlight them in a different colour
|
||||
listTables.append(it.key());
|
||||
}
|
||||
autocompleteApi->prepare();
|
||||
}
|
||||
|
||||
@@ -20,10 +20,13 @@ public:
|
||||
ApiCompleterIconIdFunction,
|
||||
ApiCompleterIconIdTable,
|
||||
ApiCompleterIconIdColumn,
|
||||
ApiCompleterIconIdSchema,
|
||||
};
|
||||
|
||||
typedef QMap<QString, QList<QString> > TablesAndColumnsMap;
|
||||
void setTableNames(const TablesAndColumnsMap& tables);
|
||||
typedef QMap<QString, TablesAndColumnsMap > QualifiedTablesMap;
|
||||
|
||||
void setTableNames(const QualifiedTablesMap& tables);
|
||||
|
||||
virtual const char* keywords(int set) const;
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ SqlTextEdit::SqlTextEdit(QWidget* parent) :
|
||||
registerImage(SqlUiLexer::ApiCompleterIconIdFunction, QImage(":/icons/function"));
|
||||
registerImage(SqlUiLexer::ApiCompleterIconIdTable, QImage(":/icons/table"));
|
||||
registerImage(SqlUiLexer::ApiCompleterIconIdColumn, QImage(":/icons/field"));
|
||||
registerImage(SqlUiLexer::ApiCompleterIconIdSchema, QImage(":/icons/database"));
|
||||
|
||||
// Do rest of initialisation
|
||||
reloadSettings();
|
||||
|
||||
Reference in New Issue
Block a user