X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=base%2Futils.cl;h=1a34f78513a2c039b121b362e5a45ec15e2b2e3e;hb=1292822d0591897376e572152d3cbd6de9bee827;hp=a33fb41cfa121f46577dde15450cd5e5e9b84934;hpb=f8a2aab1c18bd495299ea3c542bc1b6daac52db2;p=clsql.git diff --git a/base/utils.cl b/base/utils.cl index a33fb41..1a34f78 100644 --- a/base/utils.cl +++ b/base/utils.cl @@ -7,7 +7,7 @@ ;;;; Programmer: Kevin M. Rosenberg ;;;; Date Started: Mar 2002 ;;;; -;;;; $Id: utils.cl,v 1.1 2002/05/15 17:19:42 kevin Exp $ +;;;; $Id: utils.cl,v 1.7 2002/09/30 01:57:32 kevin Exp $ ;;;; ;;;; This file, part of CLSQL, is Copyright (c) 2002 by Kevin M. Rosenberg ;;;; @@ -17,7 +17,7 @@ ;;;; ************************************************************************* (declaim (optimize (debug 3) (speed 3) (safety 1) (compilation-speed 0))) -(in-package :clsql-sys) +(in-package :clsql-base-sys) (defun number-to-sql-string (num) (etypecase num @@ -30,10 +30,39 @@ (defun float-to-sql-string (num) "Convert exponent character for SQL" - (substitute #\e #\f (substitute #\e #\d (write-to-string num :readably t)))) + (let ((str (write-to-string num :readably t))) + (cond + ((find #\f str) + (substitute #\e #\f str)) + ((find #\d str) + (substitute #\e #\d str)) + ((find #\F str) + (substitute #\e #\F str)) + ((find #\D str) + (substitute #\e #\D str)) + ((find #\S str) + (substitute #\e #\S str)) + (t + str)))) + + (defun sql-escape (identifier) + "Change hyphens to underscores, ensure string" + (let* ((unescaped (etypecase identifier + (symbol (symbol-name identifier)) + (string identifier))) + (escaped (make-string (length unescaped)))) + (dotimes (i (length unescaped)) + (setf (char escaped i) + (cond ((equal (char unescaped i) #\-) + #\_) + ;; ... + (t + (char unescaped i))))) + escaped)) + (defun sql-escape-quotes (s) - "Escape single quotes for SQL" + "Escape quotes for SQL string writing" (substitute-string-for-char s #\' "''")) (defun substitute-string-for-char (procstr match-char subst-str)