ruricolist / cl-yesql

Common Lisp library for using SQL
67 stars 5 forks source link

Allow comments inside YESQL functions #12

Closed phoe closed 5 years ago

phoe commented 5 years ago
-- name: create-table-player-group @execute
-- Creates the player group table.
CREATE TABLE player_group (
    player_group_name text   NOT NULL,
    -------------
    player_group_id   serial NOT NULL PRIMARY KEY);

In this case, (create-table-player-group) signals an error:

Database error 42601: bd skadni w lub blisko ")"
QUERY: CREATE TABLE player_group (
    player_group_name text   NOT NULL,
-----------    player_group_id   serial NOT NULL PRIMARY KEY
);
   [Condition of type CL-POSTGRES-ERROR:COLUMNS-ERROR]

Modifying the function like this (adding an extra line break) causes it to function correctly:

-- name: create-table-player-group @execute
-- Creates the player group table.
CREATE TABLE player_group (
    player_group_name text   NOT NULL,
    -------------

    player_group_id   serial NOT NULL PRIMARY KEY);

Calling FUNCTION-LAMBDA-EXPRESSION on the original function shows the culprit:

GATEWAY/SQL> (function-lambda-expression #'create-table-player-group)
(LAMBDA (&KEY)
  "Creates the player group table."
  (BLOCK CL-YESQL/POSTMODERN::CREATE-TABLE-PLAYER-GROUP
    (CL-YESQL/POSTMODERN::CHECK-CONNECTION)
    (FUNCALL
     (LAMBDA ()
       (POSTMODERN:EXECUTE "CREATE TABLE player_group (
    player_group_name text   NOT NULL,
-----------    player_group_id   serial NOT NULL PRIMARY KEY
);")))))
T
(LABELS CL-YESQL/POSTMODERN::CREATE-TABLE-PLAYER-GROUP :IN "/home/phoe/Projects/Lisp/Gateway/src/sql/yesql/install.sql")

The newline after the comment line is ignored, causing the following line to be dropped, and the query to fail in Postgres due to bad syntax.