Discussion:
[Chicken-users] Awful ($db ...)
David Ireland
2018-10-07 11:08:48 UTC
Permalink
Hi,

I'm using the database access in Awful and I'm having the troubles
recreating an example in the docs. After setting up a dummy postgres
database I tried this example:

($db "insert into foo (bar, baz) values (?, ?)" values: '("bar-val" "baz-val"))

Which produced this error:

<eval> ($db "insert into foo (bar, baz) values (?, ?)" values:
(quote ("bar-val" "baz-val"))) <--

Error: (get-last-result) ERROR: syntax error at or near ","
LINE 1: insert into foo (bar, baz) values (?, ?)

If I manually add the values using:

($db "insert into company (bar, baz) values ('bar-val', 'baz-val')")

It works fine. Am I missing something with the former?

Thanks.

David
Peter Bex
2018-10-07 11:20:29 UTC
Permalink
Post by David Ireland
Hi,
I'm using the database access in Awful and I'm having the troubles
recreating an example in the docs. After setting up a dummy postgres
($db "insert into foo (bar, baz) values (?, ?)" values: '("bar-val" "baz-val"))
(quote ("bar-val" "baz-val"))) <--
Error: (get-last-result) ERROR: syntax error at or near ","
LINE 1: insert into foo (bar, baz) values (?, ?)
I don't know if Awful does any processing of the SQL string, but if it
does not, you will need to use the Postgres-native method of passing
parameterized values, which uses $1, $2 etc placeholders to refer to
the positional arguments.

Cheers,
Peter
Mario Domenech Goulart
2018-10-07 15:39:21 UTC
Permalink
Hi,
Post by Peter Bex
Post by David Ireland
Hi,
I'm using the database access in Awful and I'm having the troubles
recreating an example in the docs. After setting up a dummy postgres
($db "insert into foo (bar, baz) values (?, ?)" values: '("bar-val" "baz-val"))
(quote ("bar-val" "baz-val"))) <--
Error: (get-last-result) ERROR: syntax error at or near ","
LINE 1: insert into foo (bar, baz) values (?, ?)
I don't know if Awful does any processing of the SQL string, but if it
does not, you will need to use the Postgres-native method of passing
parameterized values, which uses $1, $2 etc placeholders to refer to
the positional arguments.
Indeed, awful doesn't do anything to the SQL string. For Postgres, you
have to use Postgres' syntax for placeholders.

All the best.
Mario
--
http://parenteses.org/mario
Continue reading on narkive:
Loading...