Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
(r)query: new case insensitives operators for -e
Baptiste Daroussin committed 3 years ago
commit 78ddf4692bdf50ced742191b7498ed802dec29bf
parent cacd3d7
3 files changed +46 -15
modified docs/pkg-query.8
@@ -14,7 +14,7 @@
.\"
.\"     @(#)pkg.8
.\"
-
.Dd November 18, 2016
+
.Dd October 06, 2022
.Dt PKG-QUERY 8
.Os
.Sh NAME
@@ -336,14 +336,22 @@ The numerical value of
is less than
.Op or equal to
the given number.
-
.It Va var Cm = Ns Oo = Oc Ar num
-
The numerical value of
+
.It Va var Cm = Ns Oo = Oc Oo Ar num | Ar string Oc
+
The value of
.Va var
-
is equal to the given number.
-
.It Va var Cm != Ar num
-
The numerical value of
+
is equal to the given number or string.
+
.It Va var Cm =~ Oo Ar num | Ar string Oc
+
The value of
+
.Va var
+
is equal (case insensitive) to the given number or string.
+
.It Va var Cm != Oo Ar num | Ar string Oc
+
The value of
+
.Va var
+
is not equal to the given number or string.
+
.It Va var Cm !=~  Oo Ar num | Ar string Oc
+
The value of
.Va var
-
is not equal to the given number.
+
is not equal case insensitive to the given number or string.
.El
.Sh ENVIRONMENT
The following environment variables affect the execution of
modified docs/pkg-rquery.8
@@ -14,7 +14,7 @@
.\"
.\"     @(#)pkg.8
.\"
-
.Dd July 15, 2018
+
.Dd October 06, 2022
.Dt PKG-RQUERY 8
.Os
.Sh NAME
@@ -309,14 +309,22 @@ The numerical value of
is less than
.Op or equal to
the given number.
-
.It Va var Cm = Ns Oo = Oc Ar num
-
The numerical value of
+
.It Va var Cm = Ns Oo = Oc Oo Ar num | Ar string Oc
+
The value of
.Va var
-
is equal to the given number.
-
.It Va var Cm != Ar num
-
The numerical value of
+
is equal to the given number or string.
+
.It Va var Cm =~ Oo Ar num | Ar string Oc
+
The value of
+
.Va var
+
is equal (case insensitive) to the given number or string.
+
.It Va var Cm != Oo Ar num | Ar string Oc
+
The value of
+
.Va var
+
is not equal to the given number or string.
+
.It Va var Cm !=~  Oo Ar num | Ar string Oc
+
The value of
.Va var
-
is not equal to the given number.
+
is not equal case insensitive to the given number or string.
.El
.Sh ENVIRONMENT
The following environment variables affect the execution of
modified src/query.c
@@ -475,6 +475,7 @@ format_sql_condition(const char *str, xstring *sqlcond, bool for_remote)
	state_t state = NONE;
	unsigned int bracket_level = 0;
	const char *sqlop;
+
	bool collate_nocase = false;

	fprintf(sqlcond->fp, " WHERE ");
	while (str[0] != '\0') {
@@ -689,7 +690,9 @@ bad_option:
				fprintf(sqlcond->fp, "%c", str[0]);
				if (str[1] == '=') {
					str++;
-
					fprintf(sqlcond->fp, "%c", str[0]);
+
				} else if (str[1] == '~' && state == NEXT_IS_STRING) {
+
					str++;
+
					collate_nocase = true;
				}
			} else if (str[0] == '!') {
				if (str[1] == '=') {
@@ -707,6 +710,10 @@ bad_option:
				} else {
					state = NEXT_IS_INT;
				}
+
				if (str[0] == "~" && state == NEXT_IS_STRING) {
+
					str++;
+
					collate_nocase = true;
+
				}
			} else {
				fprintf(stderr, "an operator is expected, got %c\n", str[0]);
				return (EPKG_FATAL);
@@ -747,6 +754,10 @@ bad_option:
			    (state == SQUOTEDSTRING && str[0] == '\'')) {
				fprintf(sqlcond->fp, "%c", '\'');
				state = POST_EXPR;
+
				if (collate_nocase) {
+
					fprintf(sqlcond->fp, " COLLATE NOCASE ");
+
					collate_nocase = false;
+
				}
			} else {
				fprintf(sqlcond->fp, "%c", str[0]);
				if (str[0] == '\'')
@@ -760,6 +771,10 @@ bad_option:
	if (state == STRING) {
		fprintf(sqlcond->fp, "%c", '\'');
		state = POST_EXPR;
+
		if (collate_nocase) {
+
			fprintf(sqlcond->fp, " COLLATE NOCASE ");
+
			collate_nocase = false;
+
		}
	}

	if (state != POST_EXPR && state != INT) {