summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2005-09-16 20:54:57 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:38:13 -0500
commit5c708830bc07e1b59c063ae1c04b8fdf2b972318 (patch)
treeb81001cf30c0c6ebe9c843c585f222a85c4373cc /source4
parent48b513fd2388840454d257cd110b576b08fb2abd (diff)
downloadsamba-5c708830bc07e1b59c063ae1c04b8fdf2b972318.tar.gz
samba-5c708830bc07e1b59c063ae1c04b8fdf2b972318.tar.bz2
samba-5c708830bc07e1b59c063ae1c04b8fdf2b972318.zip
r10277: do not ovverride LIKE, thanks to derrel I found out how to do
the same thing with a harmless user function (This used to be commit 158693b4064bd731aa4f6cdb2fde51d7aa596cf5)
Diffstat (limited to 'source4')
-rw-r--r--source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c50
1 files changed, 24 insertions, 26 deletions
diff --git a/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c b/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c
index 1a855e0850..f136fb7072 100644
--- a/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c
+++ b/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c
@@ -388,7 +388,7 @@ static char *parsetree_to_sql(struct ldb_module *module,
return lsqlite3_tprintf(mem_ctx,
"SELECT eid FROM ldb_attribute_values "
"WHERE norm_attr_name = '%q' "
- "AND norm_attr_value LIKE '>=%q' ESCAPE '%q' ",
+ "AND ldap_compare(norm_attr_value, '>=', '%q', '%q') ",
attr,
value.data,
attr);
@@ -407,7 +407,7 @@ static char *parsetree_to_sql(struct ldb_module *module,
return lsqlite3_tprintf(mem_ctx,
"SELECT eid FROM ldb_attribute_values "
"WHERE norm_attr_name = '%q' "
- "AND norm_attr_value LIKE '<=%q' ESCAPE '%q' ",
+ "AND ldap_compare(norm_attr_value, '<=', '%q', '%q') ",
attr,
value.data,
attr);
@@ -439,7 +439,7 @@ static char *parsetree_to_sql(struct ldb_module *module,
return lsqlite3_tprintf(mem_ctx,
"SELECT eid FROM ldb_attribute_values "
"WHERE norm_attr_name = '%q' "
- "AND norm_attr_value LIKE '~%q' ESCAPE '%q' ",
+ "AND ldap_compare(norm_attr_value, '~%', 'q', '%q') ",
attr,
value.data,
attr);
@@ -606,34 +606,33 @@ query_int(const struct lsqlite3_private * lsqlite3,
/*
* This is a bad hack to support ldap style comparisons whithin sqlite.
- * This function substitues the X LIKE Y ESCAPE Z expression
- * X is an expression + value to compare against (eg: ">=test")
- * Y is the attribute in the row currently under test
- * Z is the attribute name the value of which we want to test
+ * val is the attribute in the row currently under test
+ * func is the desired test "<=" ">=" "~" ":"
+ * cmp is the value to compare against (eg: "test")
+ * attr is the attribute name the value of which we want to test
*/
static void lsqlite3_compare(sqlite3_context *ctx, int argc,
sqlite3_value **argv)
{
struct ldb_context *ldb = (struct ldb_context *)sqlite3_user_data(ctx);
- const unsigned char *X = sqlite3_value_text(argv[0]);
- const unsigned char *Y = sqlite3_value_text(argv[1]);
- const unsigned char *Z = sqlite3_value_text(argv[2]);
- const unsigned char *p;
+ const unsigned char *val = sqlite3_value_text(argv[0]);
+ const unsigned char *func = sqlite3_value_text(argv[1]);
+ const unsigned char *cmp = sqlite3_value_text(argv[2]);
+ const unsigned char *attr = sqlite3_value_text(argv[3]);
const struct ldb_attrib_handler *h;
struct ldb_val valX;
struct ldb_val valY;
int ret;
- switch (X[0]) {
+ switch (func[0]) {
/* greater */
case '>': /* >= */
- p = &(X[2]);
- h = ldb_attrib_handler(ldb, Z);
- valX.data = p;
- valX.length = strlen(p);
- valY.data = Y;
- valY.length = strlen(Y);
+ h = ldb_attrib_handler(ldb, attr);
+ valX.data = cmp;
+ valX.length = strlen(cmp);
+ valY.data = val;
+ valY.length = strlen(val);
ret = h->comparison_fn(ldb, ldb, &valY, &valX);
if (ret >= 0)
sqlite3_result_int(ctx, 1);
@@ -643,12 +642,11 @@ static void lsqlite3_compare(sqlite3_context *ctx, int argc,
/* lesser */
case '<': /* <= */
- p = &(X[2]);
- h = ldb_attrib_handler(ldb, Z);
- valX.data = p;
- valX.length = strlen(p);
- valY.data = Y;
- valY.length = strlen(Y);
+ h = ldb_attrib_handler(ldb, attr);
+ valX.data = cmp;
+ valX.length = strlen(cmp);
+ valY.data = val;
+ valY.length = strlen(val);
ret = h->comparison_fn(ldb, ldb, &valY, &valX);
if (ret <= 0)
sqlite3_result_int(ctx, 1);
@@ -1694,8 +1692,8 @@ static int initialize(struct lsqlite3_private *lsqlite3,
/* Create a function, callable from sql, to perform various comparisons */
if ((ret =
sqlite3_create_function(lsqlite3->sqlite, /* handle */
- "like", /* function name */
- 3, /* number of args */
+ "ldap_compare", /* function name */
+ 4, /* number of args */
SQLITE_ANY, /* preferred text type */
ldb , /* user data */
lsqlite3_compare, /* called func */