Skip to content

Commit

Permalink
Merge pull request #8 from jgarzik/fix
Browse files Browse the repository at this point in the history
Fix
  • Loading branch information
jgarzik authored Feb 13, 2024
2 parents 5257170 + 247fd3d commit 1fc6d13
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 3 deletions.
15 changes: 12 additions & 3 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pkgconfig_DATA = libsqlpars.pc
# noinst_PROGRAMS = $(TESTS)
EXTRA_DIST = sql.y sql.l \
pscan.js \
test-ok.sh test-fail.sh \
test-ok.sh test-tst.sh test-fail.sh \
fail1.sql \
fail3.sql \
fail4.sql \
Expand All @@ -27,7 +27,16 @@ EXTRA_DIST = sql.y sql.l \
ok7.sql \
ok8.sql \
ok9.sql \
ok10.sql
ok10.sql \
tst-create-db.sql \
tst-create-table.sql \
tst-delete.sql \
tst-drop-db.sql \
tst-drop-table.sql \
tst-insert.sql \
tst-select-null.sql \
tst-select-null2.sql \
tst-select-null3.sql

sql_SOURCES = exec.c lib.c main.c sql-parser.h yyl.h
sql_LDADD = @JANSSON_LIBS@
Expand All @@ -42,5 +51,5 @@ sql.tab.c sql.tab.h: sql.y Makefile
sql.c sql.lex.h: sql.l Makefile
${LEX} -o $@ $<

TESTS = test-ok.sh test-fail.sh
TESTS = test-ok.sh test-fail.sh test-tst.sh

10 changes: 10 additions & 0 deletions exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ void sqlp_bool(struct psql_state *pstate, int val)
boolout("BOOL", val);
}

void sqlp_null(struct psql_state *pstate)
{
strout("CONST", "NULL"); /* probably this should be a different func */
}

void sqlp_call(struct psql_state *pstate, int n_args, const char *name)
{
json_t *obj = json_object();
Expand Down Expand Up @@ -397,6 +402,11 @@ void sqlp_expr_is_in(struct psql_state *pstate, int val)
boolout("EXPR-IS-IN", val);
}

void sqlp_expr_paren(struct psql_state *pstate)
{
opout("PARENS"); /* probably this should be a different function */
}

void sqlp_expr_op(struct psql_state *pstate, enum sqlp_expr_ops op)
{
strout("EXPR-OP", op_names[op]);
Expand Down
2 changes: 2 additions & 0 deletions sql-parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ extern void sqlp_alias(struct psql_state *pstate, const char *alias);
extern void sqlp_assign(struct psql_state *pstate, const char *db_name, const char *name);
extern void sqlp_assign_at(struct psql_state *pstate, const char *name);
extern void sqlp_bool(struct psql_state *pstate, int val);
extern void sqlp_null(struct psql_state *pstate);
extern void sqlp_call(struct psql_state *pstate, int n_args, const char *name);
extern void sqlp_call_date(struct psql_state *pstate, int n_args, enum sqlp_expr_ops op);
extern void sqlp_call_trim_opts(struct psql_state *pstate, int trim_opts);
Expand Down Expand Up @@ -99,6 +100,7 @@ extern void sqlp_delete_multi(struct psql_state *pstate, int opts, int n_del, in
extern void sqlp_drop_db(struct psql_state *pstate, int if_exists, const char *name);
extern void sqlp_drop_table(struct psql_state *pstate, int temp, int if_exists, int n_tables);
extern void sqlp_enum_val(struct psql_state *pstate, const char *val);
extern void sqlp_expr_paren(struct psql_state *pstate);
extern void sqlp_expr_op(struct psql_state *pstate, enum sqlp_expr_ops op);
extern void sqlp_expr_cmp(struct psql_state *pstate, int comp);
extern void sqlp_expr_cmp_sel(struct psql_state *pstate, int sel_type, int comp);
Expand Down
4 changes: 4 additions & 0 deletions sql.y
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,7 @@ expr: NAME { sqlp_name(pstate, $1); free($1); }
| INTNUM { sqlp_number(pstate, $1); }
| APPROXNUM { sqlp_float(pstate, $1); }
| BOOL { sqlp_bool(pstate, $1); }
| NULLX { sqlp_null(pstate); }
;

expr: expr '+' expr { sqlp_expr_op(pstate, SEO_ADD); }
Expand Down Expand Up @@ -961,6 +962,9 @@ expr: CURRENT_TIMESTAMP { sqlp_now(pstate); };
expr: BINARY expr %prec UMINUS { sqlp_expr_op(pstate, SEO_STRTOBIN); }
;

expr: '(' expr ')' { sqlp_expr_paren(pstate); }
;

%%

void
Expand Down
12 changes: 12 additions & 0 deletions test-tst.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

for testfn in $srcdir/tst-*.sql
do
cat $testfn | ./sql
if [ $? -ne 0 ]
then
echo "Failed on $testfn"
exit 1
fi
done

1 change: 1 addition & 0 deletions tst-select-null.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select null from t;
1 change: 1 addition & 0 deletions tst-select-null2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select (1) from t;
1 change: 1 addition & 0 deletions tst-select-null3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select ((1+2) + (2+3)) from t;

0 comments on commit 1fc6d13

Please sign in to comment.