Skip to content

Commit 1d957e3

Browse files
committed
Extract bind method
1 parent b0d8d0d commit 1d957e3

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@file:JvmName("DatabaseUtils")
2+
package io.snabble.sdk
3+
4+
@JvmName("bindArgs")
5+
fun String.bindSqlArgs(args: Array<String>?): String {
6+
if (args == null) {
7+
return this
8+
}
9+
var printSql = this
10+
for (arg in args) {
11+
printSql = printSql.replaceFirst("\\?".toRegex(), "'$arg'")
12+
}
13+
return printSql
14+
}

core/src/main/java/io/snabble/sdk/ProductDatabase.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ private Cursor rawQuery(String sql, String[] args, CancellationSignal cancellati
506506
long time2 = SystemClock.elapsedRealtime() - time;
507507
if (time2 >= 16) {
508508
Logger.d("Query performance warning (%d ms, %d rows) for SQL: %s",
509-
time2, count, bindArgs(sql, args));
509+
time2, count, DatabaseUtils.bindArgs(sql, args));
510510
}
511511
} catch (Exception e) {
512512
// query could not be executed
@@ -1111,23 +1111,12 @@ private void exec(String sql) {
11111111
}
11121112
}
11131113

1114-
public static String bindArgs(String sql, String[] args) {
1115-
if (args == null) {
1116-
return sql;
1117-
}
1118-
1119-
String printSql = sql;
1120-
for (String arg : args) {
1121-
printSql = printSql.replaceFirst("\\?", "'" + arg + "'");
1122-
}
1123-
return printSql;
1124-
}
1125-
11261114
/**
11271115
* Deprecated. Will be removed in a future version of the SDK.
11281116
* <p>
11291117
* Returns products that have a discounted price and a valid image url.
11301118
*/
1119+
@Deprecated
11311120
public Product[] getDiscountedProducts() {
11321121
Shop shop = project.getCheckedInShop();
11331122

0 commit comments

Comments
 (0)