summaryrefslogtreecommitdiffstats
path: root/database/sqlite/sqlite.c
diff options
context:
space:
mode:
Diffstat (limited to 'database/sqlite/sqlite.c')
-rw-r--r--database/sqlite/sqlite.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/database/sqlite/sqlite.c b/database/sqlite/sqlite.c
index 1e8e265..1e79fb5 100644
--- a/database/sqlite/sqlite.c
+++ b/database/sqlite/sqlite.c
@@ -343,7 +343,11 @@ char *_build_sqlpart(int btyp, eDBfieldMap *map) {
first = 0;
}
if( btyp == btWHERE ) {
- append_str(buf, ")", 8192);
+ if( (strlen_nullsafe(buf) > 1) ) {
+ append_str(buf, ")", 8192);
+ } else {
+ *buf = '\0';
+ }
}
break;
@@ -403,9 +407,12 @@ dbresult *sqlite_query_mapped(eurephiaCTX *ctx, SQLqueryType qType, const char *
if( whereMap != NULL ) {
tmp1 = _build_sqlpart(btWHERE, whereMap);
if( sortkeys == NULL ) {
- res = sqlite_query(ctx, "%s WHERE %s", sqlstub, tmp1);
+ res = sqlite_query(ctx, "%s %s %s",
+ sqlstub, (strlen_nullsafe(tmp1) > 0 ? "WHERE" : ""), tmp1);
} else {
- res = sqlite_query(ctx, "%s WHERE %s ORDER BY %s", sqlstub, tmp1, sortkeys);
+ res = sqlite_query(ctx, "%s %s %s ORDER BY %s",
+ sqlstub, (strlen_nullsafe(tmp1) > 0 ? "WHERE" : ""), tmp1,
+ sortkeys);
}
free_nullsafe(tmp1);
}