Disable automatic conversions from 8-bit strings
This commit is contained in:
@@ -58,22 +58,22 @@ CollectionQuery::CollectionQuery(const QSqlDatabase &db, const QString &songs_ta
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
QStringList tokens(filter_text.split(QRegularExpression(QStringLiteral("\\s+")), Qt::SkipEmptyParts));
|
||||
#else
|
||||
QStringList tokens(filter_text.split(QRegularExpression("\\s+"), QString::SkipEmptyParts));
|
||||
QStringList tokens(filter_text.split(QRegularExpression(QStringLiteral("\\s+")), QString::SkipEmptyParts));
|
||||
#endif
|
||||
QString query;
|
||||
for (QString token : tokens) {
|
||||
token.remove('(')
|
||||
.remove(')')
|
||||
.remove('"')
|
||||
.replace('-', ' ');
|
||||
token.remove(QLatin1Char('('))
|
||||
.remove(QLatin1Char(')'))
|
||||
.remove(QLatin1Char('"'))
|
||||
.replace(QLatin1Char('-'), QLatin1Char(' '));
|
||||
|
||||
if (token.contains(':')) {
|
||||
const QString columntoken = token.section(':', 0, 0);
|
||||
QString subtoken = token.section(':', 1, -1).replace(QLatin1String(":"), QLatin1String(" ")).trimmed();
|
||||
if (token.contains(QLatin1Char(':'))) {
|
||||
const QString columntoken = token.section(QLatin1Char(':'), 0, 0);
|
||||
QString subtoken = token.section(QLatin1Char(':'), 1, -1).replace(QLatin1String(":"), QLatin1String(" ")).trimmed();
|
||||
if (subtoken.isEmpty()) continue;
|
||||
if (Song::kFtsColumns.contains("fts" + columntoken, Qt::CaseInsensitive)) {
|
||||
if (!query.isEmpty()) query.append(" ");
|
||||
query += "fts" + columntoken + ":\"" + subtoken + "\"*";
|
||||
if (Song::kFtsColumns.contains(QLatin1String("fts") + columntoken, Qt::CaseInsensitive)) {
|
||||
if (!query.isEmpty()) query.append(QLatin1String(" "));
|
||||
query += QStringLiteral("fts") + columntoken + QStringLiteral(":\"") + subtoken + QStringLiteral("\"*");
|
||||
}
|
||||
else if (Song::kNumericalColumns.contains(columntoken, Qt::CaseInsensitive)) {
|
||||
QString comparator = RemoveSqlOperator(subtoken);
|
||||
@@ -82,7 +82,7 @@ CollectionQuery::CollectionQuery(const QSqlDatabase &db, const QString &songs_ta
|
||||
}
|
||||
else if (columntoken.compare(QLatin1String("length"), Qt::CaseInsensitive) == 0) {
|
||||
// Time is saved in nanoseconds, so add 9 0's
|
||||
QString parsedTime = QString::number(Utilities::ParseSearchTime(subtoken)) + "000000000";
|
||||
QString parsedTime = QString::number(Utilities::ParseSearchTime(subtoken)) + QStringLiteral("000000000");
|
||||
AddWhere(columntoken, parsedTime, comparator);
|
||||
}
|
||||
else {
|
||||
@@ -93,14 +93,14 @@ CollectionQuery::CollectionQuery(const QSqlDatabase &db, const QString &songs_ta
|
||||
else {
|
||||
token = token.replace(QLatin1String(":"), QLatin1String(" ")).trimmed();
|
||||
if (!token.isEmpty()) {
|
||||
if (!query.isEmpty()) query.append(" ");
|
||||
query += "\"" + token + "\"*";
|
||||
if (!query.isEmpty()) query.append(QLatin1Char(' '));
|
||||
query += QLatin1Char('\"') + token + QStringLiteral("\"*");
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!query.isEmpty()) query.append(" ");
|
||||
query += "\"" + token + "\"*";
|
||||
if (!query.isEmpty()) query.append(QLatin1Char(' '));
|
||||
query += QLatin1Char('\"') + token + QStringLiteral("\"*");
|
||||
}
|
||||
}
|
||||
if (!query.isEmpty()) {
|
||||
@@ -141,7 +141,7 @@ QString CollectionQuery::RemoveSqlOperator(QString &token) {
|
||||
}
|
||||
token.remove(rxOp);
|
||||
|
||||
if (op == "!=") {
|
||||
if (op == QStringLiteral("!=")) {
|
||||
op = QStringLiteral("<>");
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ void CollectionQuery::AddWhere(const QString &column, const QVariant &value, con
|
||||
bound_values_ << single_value;
|
||||
}
|
||||
|
||||
where_clauses_ << QString("%1 IN (" + final_values.join(QStringLiteral(",")) + ")").arg(column);
|
||||
where_clauses_ << QStringLiteral("%1 IN (%2)").arg(column, final_values.join(QStringLiteral(",")));
|
||||
}
|
||||
else {
|
||||
// Do integers inline - sqlite seems to get confused when you pass integers to bound parameters
|
||||
@@ -205,19 +205,19 @@ void CollectionQuery::AddWhereRating(const QVariant &value, const QString &op) {
|
||||
// You can't query the database for a float, due to float precision errors,
|
||||
// So we have to use a certain tolerance, so that the searched value is definetly included.
|
||||
const float tolerance = 0.001F;
|
||||
if (op == "<") {
|
||||
if (op == QStringLiteral("<")) {
|
||||
AddWhere(QStringLiteral("rating"), parsed_rating-tolerance, QStringLiteral("<"));
|
||||
}
|
||||
else if (op == ">") {
|
||||
else if (op == QStringLiteral(">")) {
|
||||
AddWhere(QStringLiteral("rating"), parsed_rating+tolerance, QStringLiteral(">"));
|
||||
}
|
||||
else if (op == "<=") {
|
||||
else if (op == QStringLiteral("<=")) {
|
||||
AddWhere(QStringLiteral("rating"), parsed_rating+tolerance, QStringLiteral("<="));
|
||||
}
|
||||
else if (op == ">=") {
|
||||
else if (op == QStringLiteral(">=")) {
|
||||
AddWhere(QStringLiteral("rating"), parsed_rating-tolerance, QStringLiteral(">="));
|
||||
}
|
||||
else if (op == "<>") {
|
||||
else if (op == QStringLiteral("<>")) {
|
||||
where_clauses_ << QStringLiteral("(rating<? OR rating>?)");
|
||||
bound_values_ << parsed_rating - tolerance;
|
||||
bound_values_ << parsed_rating + tolerance;
|
||||
@@ -239,7 +239,7 @@ void CollectionQuery::AddCompilationRequirement(const bool compilation) {
|
||||
|
||||
QString CollectionQuery::GetInnerQuery() const {
|
||||
return duplicates_only_
|
||||
? QString(" INNER JOIN (select * from duplicated_songs) dsongs "
|
||||
? QStringLiteral(" INNER JOIN (select * from duplicated_songs) dsongs "
|
||||
"ON (%songs_table.artist = dsongs.dup_artist "
|
||||
"AND %songs_table.album = dsongs.dup_album "
|
||||
"AND %songs_table.title = dsongs.dup_title) ")
|
||||
@@ -262,14 +262,14 @@ bool CollectionQuery::Exec() {
|
||||
where_clauses << QStringLiteral("unavailable = 0");
|
||||
}
|
||||
|
||||
if (!where_clauses.isEmpty()) sql += " WHERE " + where_clauses.join(QStringLiteral(" AND "));
|
||||
if (!where_clauses.isEmpty()) sql += QStringLiteral(" WHERE ") + where_clauses.join(QStringLiteral(" AND "));
|
||||
|
||||
if (!order_by_.isEmpty()) sql += " ORDER BY " + order_by_;
|
||||
if (!order_by_.isEmpty()) sql += QStringLiteral(" ORDER BY ") + order_by_;
|
||||
|
||||
if (limit_ != -1) sql += " LIMIT " + QString::number(limit_);
|
||||
if (limit_ != -1) sql += QStringLiteral(" LIMIT ") + QString::number(limit_);
|
||||
|
||||
sql.replace(QLatin1String("%songs_table"), songs_table_);
|
||||
sql.replace(QLatin1String("%fts_table_noprefix"), fts_table_.section('.', -1, -1));
|
||||
sql.replace(QLatin1String("%fts_table_noprefix"), fts_table_.section(QLatin1Char('.'), -1, -1));
|
||||
sql.replace(QLatin1String("%fts_table"), fts_table_);
|
||||
|
||||
if (!QSqlQuery::prepare(sql)) return false;
|
||||
|
||||
Reference in New Issue
Block a user