Skip to content

Commit

Permalink
Merged fro 3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelsalawa committed Dec 5, 2024
2 parents 13d35ae + bbd0594 commit 269eba8
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/mac_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ on:

jobs:
build:
runs-on: ${{ matrix.runner || 'macos-12' }}
runs-on: ${{ matrix.runner || 'macos-13' }}

strategy:
fail-fast: false
Expand Down
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# ChangeLog

### 3.4.9
- BUGFIX: #5148 Fixed executing queries that refer to tables with database prefix (i.e. dbName.tableName).
- BUGFIX: #5149 Relaxed recent limitation on requiring Custom SQL Functions to have unique names, so that names can duplicate if input parameters differ.

### 3.4.8
- CHANGE: #5146 If user enters a relative file path to the database dialog, a warning will issued to the user pointing out actual resolved path for the relative path entered.
- BUGFIX: #5145 Fixed Extensions Manager crashing the app if the percentile extension was loaded before. The percentile SQLite extension became corrupted in SQLite 3.46.x, then it got fixed, but the fix is not included in SQLite 3.47.1 source package.
Expand Down
5 changes: 3 additions & 2 deletions SQLiteStudio3/coreSQLiteStudio/selectresolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,10 +805,11 @@ QList<SelectResolver::Column> SelectResolver::sqliteResolveColumns(Db* db, const
for (const AliasedColumn& queryColumn : queryColumns)
{
if (!queryColumn.getDatabase().isNull())
column.database = dbNameToAttach.valueByRight(queryColumn.getDatabase(), queryColumn.getDatabase(), Qt::CaseInsensitive);
column.originalDatabase = dbNameToAttach.valueByRight(queryColumn.getDatabase(), queryColumn.getDatabase(), Qt::CaseInsensitive);
else
column.database = QString();
column.originalDatabase = QString();

column.database = queryColumn.getDatabase();
column.displayName = queryColumn.getAlias();
if (queryColumn.getTable().isNull())
{
Expand Down
14 changes: 8 additions & 6 deletions SQLiteStudio3/guiSQLiteStudio/windows/functionseditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,12 @@ int FunctionsEditor::getCurrentFunctionRow() const
void FunctionsEditor::functionDeselected(int row)
{
model->setName(row, ui->nameEdit->text());
model->setUndefinedArgs(row, ui->undefArgsCheck->isChecked());
if (!ui->undefArgsCheck->isChecked())
model->setArguments(row, getCurrentArgList());

model->setLang(row, ui->langCombo->currentText());
model->setType(row, getCurrentFunctionType());
model->setUndefinedArgs(row, ui->undefArgsCheck->isChecked());
model->setAllDatabases(row, ui->allDatabasesRadio->isChecked());
model->setCode(row, ui->mainCodeEdit->toPlainText());
model->setDeterministic(row, ui->deterministicCheck->isChecked());
Expand All @@ -189,9 +192,6 @@ void FunctionsEditor::functionDeselected(int row)
model->setFinalCode(row, QString());
}

if (!ui->undefArgsCheck->isChecked())
model->setArguments(row, getCurrentArgList());

if (ui->selDatabasesRadio->isChecked())
model->setDatabases(row, getCurrentDatabases());

Expand Down Expand Up @@ -416,8 +416,10 @@ void FunctionsEditor::updateCurrentFunctionState()
}

QString name = ui->nameEdit->text();
bool nameOk = model->isAllowedName(row, name) && !name.trimmed().isEmpty();
setValidState(ui->nameEdit, nameOk, tr("Enter a non-empty, unique name of the function."));
QStringList argList = getCurrentArgList();
bool undefArgs = ui->undefArgsCheck->isChecked();
bool nameOk = model->isAllowedName(row, name, argList, undefArgs) && !name.trimmed().isEmpty();
setValidState(ui->nameEdit, nameOk, tr("Enter a unique, non-empty function name. Duplicate names are allowed if the number of input parameters differs."));

bool langOk = ui->langCombo->currentIndex() >= 0;
ui->initCodeGroup->setEnabled(langOk);
Expand Down
55 changes: 49 additions & 6 deletions SQLiteStudio3/guiSQLiteStudio/windows/functionseditormodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,16 +266,17 @@ QStringList FunctionsEditorModel::getFunctionNames() const

void FunctionsEditorModel::validateNames()
{
StrHash<QList<int>> counter;
QHash<UniqueFunctionName, QList<int>> counter;

int row = 0;
for (Function*& func : functionList)
{
func->valid &= true;
counter[func->data.name] << row++;
UniqueFunctionName uniqueName = func->toUniqueName();
counter[uniqueName] << row++;
}

QHashIterator<QString,QList<int>> cntIt = counter.iterator();
QHashIterator<UniqueFunctionName, QList<int>> cntIt(counter);
while (cntIt.hasNext())
{
cntIt.next();
Expand All @@ -294,11 +295,18 @@ void FunctionsEditorModel::validateNames()
}
}

bool FunctionsEditorModel::isAllowedName(int rowToSkip, const QString& nameToValidate)
bool FunctionsEditorModel::isAllowedName(int rowToSkip, const QString& nameToValidate, const QStringList& argList, bool undefinedArgs)
{
QStringList names = getFunctionNames();
QList<UniqueFunctionName> names = getUniqueFunctionNames();
names.removeAt(rowToSkip);
return !names.contains(nameToValidate, Qt::CaseInsensitive);

UniqueFunctionName validatedName;
validatedName.name = nameToValidate.toLower();
validatedName.undefArg = undefinedArgs;
if (!undefinedArgs)
validatedName.arguments = argList;

return !names.contains(validatedName);
}

int FunctionsEditorModel::rowCount(const QModelIndex& parent) const
Expand Down Expand Up @@ -347,6 +355,15 @@ void FunctionsEditorModel::emitDataChanged(int row)
emit dataChanged(idx, idx);
}

QList<FunctionsEditorModel::UniqueFunctionName> FunctionsEditorModel::getUniqueFunctionNames() const
{
QList<UniqueFunctionName> names;
for (Function* func : functionList)
names << func->toUniqueName();

return names;
}

FunctionsEditorModel::Function::Function()
{
}
Expand All @@ -356,3 +373,29 @@ FunctionsEditorModel::Function::Function(FunctionManager::ScriptFunction* other)
data = FunctionManager::ScriptFunction(*other);
originalName = data.name;
}

FunctionsEditorModel::UniqueFunctionName FunctionsEditorModel::Function::toUniqueName() const
{
UniqueFunctionName uniqName;
uniqName.name = data.name.toLower();
uniqName.undefArg = data.undefinedArgs;
if (!data.undefinedArgs)
uniqName.arguments = data.arguments;

return uniqName;
}

int FunctionsEditorModel::UniqueFunctionName::argCount() const
{
return undefArg ? -1 : arguments.size();
}

bool FunctionsEditorModel::UniqueFunctionName::operator==(const UniqueFunctionName &other) const
{
return name == other.name && argCount() == other.argCount();
}

int qHash(FunctionsEditorModel::UniqueFunctionName fnName)
{
return qHash(fnName.name) ^ fnName.argCount();
}
18 changes: 17 additions & 1 deletion SQLiteStudio3/guiSQLiteStudio/windows/functionseditormodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,28 @@ class GUI_API_EXPORT FunctionsEditorModel : public QAbstractListModel
QList<FunctionManager::ScriptFunction*> generateFunctions() const;
QStringList getFunctionNames() const;
void validateNames();
bool isAllowedName(int rowToSkip, const QString& nameToValidate);
bool isAllowedName(int rowToSkip, const QString& nameToValidate, const QStringList &argList, bool undefinedArgs);
bool isValidRowIndex(int row) const;

int rowCount(const QModelIndex& parent = QModelIndex()) const;
QVariant data(const QModelIndex& index, int role) const;

private:
struct UniqueFunctionName
{
QString name;
QStringList arguments;
bool undefArg;

int argCount() const;
bool operator==(const UniqueFunctionName& other) const;
};

struct Function
{
Function();
Function(FunctionManager::ScriptFunction* other);
UniqueFunctionName toUniqueName() const;

FunctionManager::ScriptFunction data;
bool modified = false;
Expand All @@ -80,6 +91,9 @@ class GUI_API_EXPORT FunctionsEditorModel : public QAbstractListModel

void init();
void emitDataChanged(int row);
QList<UniqueFunctionName> getUniqueFunctionNames() const;

friend int qHash(FunctionsEditorModel::UniqueFunctionName fnName);

QList<Function*> functionList;

Expand All @@ -96,4 +110,6 @@ class GUI_API_EXPORT FunctionsEditorModel : public QAbstractListModel
bool listModified = false;
};

int qHash(FunctionsEditorModel::UniqueFunctionName fnName);

#endif // FUNCTIONSEDITORMODEL_H

0 comments on commit 269eba8

Please sign in to comment.