From 1c10cdd27e21604ec9a78ac55c9f1e9856bbe99f Mon Sep 17 00:00:00 2001 From: Russ Tyndall Date: Mon, 6 Apr 2015 10:31:08 -0400 Subject: [PATCH] Add postgresql escape string expression/operator --- ChangeLog | 5 +++++ sql/expressions.lisp | 15 +++++++++++++-- sql/operations.lisp | 3 +++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 45fa7d7..947d2eb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-04-06 Russ Tyndall + * sql/operations, sql/expressions: add postgresql E-string + operator / expression. Needed for correct regex handling + EG: [E "some string"]=> E'some string' + 2015-03-24 Russ Tyndall * sql/oodml.lisp: fixed call-next-method in the base of read-sql-value and replaced with a continuable diff --git a/sql/expressions.lisp b/sql/expressions.lisp index 4c57bc3..4f0baf1 100644 --- a/sql/expressions.lisp +++ b/sql/expressions.lisp @@ -450,8 +450,6 @@ (remove-duplicates tabs :test #'database-identifier-equal)) nil))) - - (defmethod output-sql ((expr sql-value-exp) database) (with-slots (modifier components) expr @@ -1234,3 +1232,16 @@ uninclusive, and the args from that keyword to the end." returns nil if there are no children" (clsql-ors clauses)) + +(defclass sql-escape-string-exp (%sql-expression) + ((string + :initarg :string + :initform nil)) + (:documentation + "An escaped string string expression (postgresql E'stuff') .")) + +(defmethod output-sql ((exp sql-escape-string-exp) database) + (with-slots (string) exp + (when string + (write-char #\E *sql-stream*) + (output-sql string database)))) diff --git a/sql/operations.lisp b/sql/operations.lisp index 37d751e..faa22b5 100644 --- a/sql/operations.lisp +++ b/sql/operations.lisp @@ -46,6 +46,9 @@ (make-instance 'sql-function-exp :name 'all :args rest)) +(defsql sql-e-string (:symbol "E") (&rest rest) + (make-instance 'sql-escape-string-exp :string (first rest))) + (defsql sql-not (:symbol "not") (&rest rest) (make-instance 'sql-value-exp :modifier 'not :components rest)) -- 2.34.1