mirror of
https://github.com/rabbibotton/clog.git
synced 2026-01-03 07:42:32 -08:00
Handle unquoted values for field lists in clog-data
This commit is contained in:
parent
3d8d7f7136
commit
7df2be3541
3 changed files with 52 additions and 18 deletions
|
|
@ -153,23 +153,34 @@ stringified first. If :QUOTE-ALL t then all fields are in quotes."
|
|||
(push field result))
|
||||
(format nil "~{~A~}" result)))
|
||||
|
||||
;;;;;;;;;;;;;;;
|
||||
;; sql-quote ;;
|
||||
;;;;;;;;;;;;;;;
|
||||
|
||||
(defun sql-quote (value)
|
||||
"Returns value single quoted if string (single quote quoted by doubling)
|
||||
unless is the single character '?'. If value is a list the car is returned
|
||||
unquoted"
|
||||
(cond ((and (stringp value)
|
||||
(not (equal value "?")))
|
||||
(format nil "'~A'"
|
||||
(ppcre:regex-replace-all "'" value "''")))
|
||||
((consp value)
|
||||
(car value))
|
||||
(t
|
||||
value)))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;
|
||||
;; sql-value-list ;;
|
||||
;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defun sql-value-list (value-list)
|
||||
"Given list of values returns a string for use in a SQL insert value
|
||||
list. If a value is a string it is quoted with single quotes
|
||||
(and single quotes qutoed by doubling) unless is the single
|
||||
character '?'."
|
||||
"Given list of values each passed to SQL-QUOTE returns a string for
|
||||
use in a SQL insert value list."
|
||||
(let ((result))
|
||||
(dolist (value (reverse value-list))
|
||||
(setf value (format nil "~A~A"
|
||||
(if (and (stringp value)
|
||||
(not (equal value "?")))
|
||||
(format nil "'~A'"
|
||||
(ppcre:regex-replace-all "'" value "''"))
|
||||
(format nil "~A" value))
|
||||
(sql-quote value)
|
||||
(if result ", " "")))
|
||||
(push value result))
|
||||
(format nil "~{~A~}" result)))
|
||||
|
|
@ -179,10 +190,9 @@ character '?'."
|
|||
;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defun sql-update-list (plist)
|
||||
"Given plist of field names and values returns a string for use in a
|
||||
SQL update. if the 'key' is a cons the first 'key' used. If a value
|
||||
is a string it is quoted with single quotes (and single quotes qutoed
|
||||
by doubling) unless is the single character '?'."
|
||||
"Given plist of field names and values each passed to SQL-QUOTE and
|
||||
returns a string for use in a SQL update. if the 'key' is a cons the
|
||||
first 'key' used."
|
||||
(let ((result))
|
||||
(loop for (key value) on plist by #'cddr while value
|
||||
do
|
||||
|
|
@ -190,11 +200,7 @@ by doubling) unless is the single character '?'."
|
|||
(if (consp key)
|
||||
(car key)
|
||||
key)
|
||||
(if (and (stringp value)
|
||||
(not (equal value "?")))
|
||||
(format nil "'~A'"
|
||||
(ppcre:regex-replace-all "'" value "''"))
|
||||
(format nil "~A" value))
|
||||
(sql-quote value)
|
||||
(if result ", " ""))
|
||||
result))
|
||||
(format nil "~{~A~}" result)))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue