aboutsummaryrefslogtreecommitdiff
path: root/ext/misc/nextchar.c
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2013-09-28 13:28:40 +0000
committerdrh <drh@noemail.net>2013-09-28 13:28:40 +0000
commitf42747246af61e7a37b87d2f62f456e5faecbb7c (patch)
tree629bc1d7ce6b9c407092eaa63a4f370a023ab21e /ext/misc/nextchar.c
parent2f312ee65f7692156259d849dc6db2ae74ad5d76 (diff)
downloadsqlite-f42747246af61e7a37b87d2f62f456e5faecbb7c.tar.gz
sqlite-f42747246af61e7a37b87d2f62f456e5faecbb7c.zip
In the nextchar.c extension, allow the second argument to the next_char()
function to be a subquery. FossilOrigin-Name: 59b9fa223681a7329533b350be7bf5a0a3609255
Diffstat (limited to 'ext/misc/nextchar.c')
-rw-r--r--ext/misc/nextchar.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/ext/misc/nextchar.c b/ext/misc/nextchar.c
index 6dcbd2dbc..bf7e023b4 100644
--- a/ext/misc/nextchar.c
+++ b/ext/misc/nextchar.c
@@ -38,6 +38,19 @@
** out) run the following query:
**
** SELECT next_char('cha','dictionary','word');
+**
+** IMPLEMENTATION NOTES:
+**
+** The next_char function is implemented using recursive SQL that makes
+** use of the table name and column name as part of a query. If either
+** the table name or column name are keywords or contain special characters,
+** then they should be escaped. For example:
+**
+** SELECT next_char('cha','[dictionary]','[word]');
+**
+** This also means that the table name can be a subquery:
+**
+** SELECT next_char('cha','(SELECCT word AS w FROM dictionary)','w');
*/
#include "sqlite3ext.h"
SQLITE_EXTENSION_INIT1
@@ -231,9 +244,9 @@ static void nextCharFunc(
zColl = "";
}
zSql = sqlite3_mprintf(
- "SELECT \"%w\" FROM \"%w\""
- " WHERE \"%w\">=(?1 || ?2) %s"
- " AND \"%w\"<=(?1 || char(1114111)) %s" /* 1114111 == 0x10ffff */
+ "SELECT %s FROM %s"
+ " WHERE %s>=(?1 || ?2) %s"
+ " AND %s<=(?1 || char(1114111)) %s" /* 1114111 == 0x10ffff */
" %s"
" ORDER BY 1 %s ASC LIMIT 1",
zField, zTable, zField, zColl, zField, zColl, zWhereClause, zColl