mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 02:50:46 -06:00
Fix filter row SQL generation to always produce correct SQL statements
Always produce correct SQL statements, even when using an incomplete comparison operator. Fix escaping to make it possible to search for '-charachters.
This commit is contained in:
@@ -287,6 +287,7 @@ void SqliteTableModel::updateFilter(int column, const QString& value)
|
||||
// Check for any special comparison operators at the beginning of the value string. If there are none default to LIKE.
|
||||
QString op = "LIKE";
|
||||
QString val;
|
||||
bool numeric = false;
|
||||
if(value.left(2) == ">=" || value.left(2) == "<=" || value.left(2) == "<>")
|
||||
{
|
||||
bool ok;
|
||||
@@ -295,6 +296,7 @@ void SqliteTableModel::updateFilter(int column, const QString& value)
|
||||
{
|
||||
op = value.left(2);
|
||||
val = value.mid(2);
|
||||
numeric = true;
|
||||
}
|
||||
} else if(value.left(1) == ">" || value.left(1) == "<") {
|
||||
bool ok;
|
||||
@@ -303,20 +305,22 @@ void SqliteTableModel::updateFilter(int column, const QString& value)
|
||||
{
|
||||
op = value.left(1);
|
||||
val = value.mid(1);
|
||||
numeric = true;
|
||||
}
|
||||
} else {
|
||||
if(value.left(1) == "=")
|
||||
{
|
||||
op = "=";
|
||||
val = value.mid(1);
|
||||
} else {
|
||||
val = value;
|
||||
}
|
||||
val = QString("'%1'").arg(val.replace("'", ""));
|
||||
}
|
||||
if(val.isEmpty())
|
||||
val = value;
|
||||
if(!numeric)
|
||||
val = QString("'%1'").arg(val.replace("'", "''"));
|
||||
|
||||
// If the value was set to an empty string remove any filter for this column. Otherwise insert a new filter rule or replace the old one if there is already one
|
||||
if(value.isEmpty())
|
||||
if(val == "''")
|
||||
m_mWhere.remove(column);
|
||||
else
|
||||
m_mWhere.insert(column, QString("%1 %2").arg(op).arg(val));
|
||||
|
||||
Reference in New Issue
Block a user