started to clean up the query situation
This commit is contained in:
parent
8c68f16373
commit
85a7a78ac1
41
source/queries.inc
Normal file
41
source/queries.inc
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
static const char * const insert_entry_sql =
|
||||||
|
"INSERT INTO entries (stamp, data) VALUES (?, ?);"
|
||||||
|
;
|
||||||
|
static const char * const empty_query =
|
||||||
|
"SELECT * FROM entries "
|
||||||
|
"ORDER BY stamp DESC "
|
||||||
|
"LIMIT ? "
|
||||||
|
"OFFSET ?;"
|
||||||
|
;
|
||||||
|
static const char * const literal_query =
|
||||||
|
"SELECT * FROM entries "
|
||||||
|
"WHERE data GLOB CONCAT('*', ?, '*') "
|
||||||
|
"GROUP BY data "
|
||||||
|
"ORDER BY stamp DESC "
|
||||||
|
"LIMIT ? "
|
||||||
|
"OFFSET ?;"
|
||||||
|
;
|
||||||
|
static const char * const literal_caseless_query =
|
||||||
|
"SELECT * FROM entries "
|
||||||
|
"WHERE data LIKE CONCAT('%', ?, '%') "
|
||||||
|
"GROUP BY data "
|
||||||
|
"ORDER BY stamp DESC "
|
||||||
|
"LIMIT ? "
|
||||||
|
"OFFSET ?;"
|
||||||
|
;
|
||||||
|
static const char * const levenstein_query =
|
||||||
|
"SELECT * FROM entries "
|
||||||
|
"GROUP BY data "
|
||||||
|
"ORDER BY DAMERAU_LEVENSHTEIN_SUBSTRING(data, ?), "
|
||||||
|
"stamp DESC "
|
||||||
|
"LIMIT ? "
|
||||||
|
"OFFSET ?;"
|
||||||
|
;
|
||||||
|
static const char * const levenstein_caseless_query =
|
||||||
|
"SELECT * FROM entries "
|
||||||
|
"GROUP BY data "
|
||||||
|
"ORDER BY DAMERAU_LEVENSHTEIN_SUBSTRING(LOWER(data), LOWER(?)), "
|
||||||
|
"stamp DESC "
|
||||||
|
"LIMIT ? "
|
||||||
|
"OFFSET ?;"
|
||||||
|
;
|
@ -9,53 +9,12 @@
|
|||||||
* This might became a scaling issue in the future tho,
|
* This might became a scaling issue in the future tho,
|
||||||
* but untill then hardcoding will work.
|
* but untill then hardcoding will work.
|
||||||
*/
|
*/
|
||||||
|
#include "queries.inc"
|
||||||
|
static const char * const * query_method;
|
||||||
|
|
||||||
bool is_levenstein = false;
|
bool is_levenstein = false;
|
||||||
bool is_caseless = false;
|
bool is_caseless = false;
|
||||||
|
|
||||||
static const char * const insert_entry_sql =
|
|
||||||
"INSERT INTO entries (stamp, data) VALUES (?, ?);"
|
|
||||||
;
|
|
||||||
static const char * const empty_query =
|
|
||||||
"SELECT * FROM entries "
|
|
||||||
"ORDER BY stamp DESC "
|
|
||||||
"LIMIT ? "
|
|
||||||
"OFFSET ?;"
|
|
||||||
;
|
|
||||||
static const char * const literal_query =
|
|
||||||
"SELECT * FROM entries "
|
|
||||||
"WHERE data GLOB CONCAT('*', ?, '*') "
|
|
||||||
"GROUP BY data "
|
|
||||||
"ORDER BY stamp DESC "
|
|
||||||
"LIMIT ? "
|
|
||||||
"OFFSET ?;"
|
|
||||||
;
|
|
||||||
static const char * const literal_caseless_query =
|
|
||||||
"SELECT * FROM entries "
|
|
||||||
"WHERE data LIKE CONCAT('%', ?, '%') "
|
|
||||||
"GROUP BY data "
|
|
||||||
"ORDER BY stamp DESC "
|
|
||||||
"LIMIT ? "
|
|
||||||
"OFFSET ?;"
|
|
||||||
;
|
|
||||||
static const char * const levenstein_query =
|
|
||||||
"SELECT * FROM entries "
|
|
||||||
"GROUP BY data "
|
|
||||||
"ORDER BY DAMERAU_LEVENSHTEIN_SUBSTRING(data, ?), "
|
|
||||||
"stamp DESC "
|
|
||||||
"LIMIT ? "
|
|
||||||
"OFFSET ?;"
|
|
||||||
;
|
|
||||||
static const char * const levenstein_caseless_query =
|
|
||||||
"SELECT * FROM entries "
|
|
||||||
"GROUP BY data "
|
|
||||||
"ORDER BY DAMERAU_LEVENSHTEIN_SUBSTRING(LOWER(data), LOWER(?)), "
|
|
||||||
"stamp DESC "
|
|
||||||
"LIMIT ? "
|
|
||||||
"OFFSET ?;"
|
|
||||||
;
|
|
||||||
static const char * const * query_method;
|
|
||||||
|
|
||||||
static sqlite3 * db = NULL;
|
static sqlite3 * db = NULL;
|
||||||
|
|
||||||
/* These statements must be global so they can be prepared once
|
/* These statements must be global so they can be prepared once
|
||||||
|
Loading…
x
Reference in New Issue
Block a user