Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
add argument to format_sql_condition telling it if the query will be used for the local or a remote repository. The latter doesn't have some fields (so don't accept to query them). Also, the successive code is passing the sql statement through sprintf, so % (percent) characters need to be escaped.
Rolf Grossmann committed 13 years ago
commit 2cfea8e87b552a08882faa9a31932df165437825
parent fe0c65c
3 files changed +15 -4
modified pkg/pkgcli.h
@@ -176,7 +176,7 @@ struct query_flags {
};

void print_query(struct pkg *pkg, char *qstr, char multiline);
-
int format_sql_condition(const char *str, struct sbuf *sqlcond);
+
int format_sql_condition(const char *str, struct sbuf *sqlcond, bool for_remote);
int analyse_query_string(char *qstr, struct query_flags *q_flags, const unsigned int q_flags_len, int *flags, char *multiline);

#endif
modified pkg/query.c
@@ -395,7 +395,7 @@ typedef enum {
} state_t;

int
-
format_sql_condition(const char *str, struct sbuf *sqlcond)
+
format_sql_condition(const char *str, struct sbuf *sqlcond, bool for_remote)
{
	state_t state = NONE;
	unsigned int bracket_level = 0;
@@ -435,22 +435,31 @@ format_sql_condition(const char *str, struct sbuf *sqlcond)
						state = OPERATOR_INT;
						break;
					case 'a':
+
						if (for_remote)
+
							goto bad_option;
						sbuf_cat(sqlcond, "automatic");
						state = OPERATOR_INT;
						break;
					case 'M':
+
						if (for_remote)
+
							goto bad_option;
						sbuf_cat(sqlcond, "message");
						state = OPERATOR_STRING;
						break;
					case 'i':
+
						if (for_remote)
+
							goto bad_option;
						sbuf_cat(sqlcond, "infos");
						state = OPERATOR_STRING;
						break;
					case 't':
+
						if (for_remote)
+
							goto bad_option;
						sbuf_cat(sqlcond, "time");
						state = OPERATOR_INT;
						break;
					default:
+
bad_option:
						fprintf(stderr, "malformed evaluation string");
						return (EPKG_FATAL);
				}
@@ -595,6 +604,8 @@ format_sql_condition(const char *str, struct sbuf *sqlcond)
				sbuf_putc(sqlcond, str[0]);
				if (str[0] == '\'')
					sbuf_putc(sqlcond, str[0]);
+
				else if (str[0] == '%' && for_remote)
+
					sbuf_putc(sqlcond, str[0]);
			}
		}
		str++;
@@ -783,7 +794,7 @@ exec_query(int argc, char **argv)

	if (condition != NULL) {
		sqlcond = sbuf_new_auto();
-
		if (format_sql_condition(condition, sqlcond) != EPKG_OK) {
+
		if (format_sql_condition(condition, sqlcond, false) != EPKG_OK) {
			sbuf_delete(sqlcond);
			return (EX_USAGE);
		}
modified pkg/rquery.c
@@ -139,7 +139,7 @@ exec_rquery(int argc, char **argv)

	if (condition != NULL) {
		sqlcond = sbuf_new_auto();
-
		if (format_sql_condition(condition, sqlcond) != EPKG_OK)
+
		if (format_sql_condition(condition, sqlcond, true) != EPKG_OK)
			return (EX_USAGE);
		sbuf_finish(sqlcond);
	}