r9335: Automated commit for Debian build of clsql upstream-version-2.10.16
[clsql.git] / base / utils.lisp
index 55f2bc91e540401d957a3e3679f18ebfc4b9bc60..8a96df6642846289ab4603f1449dda00cf95e9b7 100644 (file)
@@ -16,7 +16,7 @@
 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
 ;;;; *************************************************************************
 
-(in-package #:clsql-base-sys)
+(in-package #:clsql-base)
 
 (defun number-to-sql-string (num)
   (etypecase num
@@ -76,7 +76,7 @@
   #+allegro (mp:make-process-lock :name name)
   #+cmu (mp:make-lock name)
   #+lispworks (mp:make-lock :name name)
-  #+openmcl (ccl:make-lock :name name)
+  #+openmcl (ccl:make-lock name)
   #+sb-thread (sb-thread:make-mutex :name name)
   #+scl (thread:make-lock name)
   #-(or allegro cmu lispworks openmcl sb-thread scl) (declare (ignore name))
@@ -185,23 +185,33 @@ synchronously execute the result using a Bourne-compatible shell,
 returns (VALUES string-output error-output exit-status)"
   (let ((command (apply #'format nil control-string args)))
     #+sbcl
-    (let ((process (sb-ext:run-program  
+    (let* ((process (sb-ext:run-program  
                    "/bin/sh"
                    (list "-c" command)
-                   :input nil :output :stream :error :stream)))
+                   :input nil :output :stream :error :stream))
+          (output (read-stream-to-string (sb-impl::process-output process)))
+          (error (read-stream-to-string (sb-impl::process-error process))))
+      (close (sb-impl::process-output process))
+      (close (sb-impl::process-error process))
       (values
-       (sb-impl::process-output process)
-       (sb-impl::process-error process)
-       (sb-impl::process-exit-code process)))
+       output
+       error
+       (sb-impl::process-exit-code process)))    
+
     
     #+(or cmu scl)
-    (let ((process (ext:run-program  
-                   "/bin/sh"
-                   (list "-c" command)
-                   :input nil :output :stream :error :stream)))
+    (let* ((process (ext:run-program  
+                    "/bin/sh"
+                    (list "-c" command)
+                    :input nil :output :stream :error :stream))
+          (output (read-stream-to-string (ext::process-output process)))
+          (error (read-stream-to-string (ext::process-error process))))
+      (close (ext::process-output process))
+      (close (ext::process-error process))
+
       (values
-       (ext::process-output process)
-       (ext::process-error process)
+       output
+       error
        (ext::process-exit-code process)))    
 
     #+allegro
@@ -247,23 +257,6 @@ returns (VALUES string-output error-output exit-status)"
 
     ))
 
-(eval-when (:compile-toplevel :load-toplevel :execute)
-  (when (char= #\a (schar (symbol-name '#:a) 0))
-    (pushnew :lowercase-reader *features*)))
-
-(defun string-default-case (str)
-  #-lowercase-reader
-  (string-upcase str)
-  #+lowercase-reader
-  (string-downcase str))
-
-;; From KMRCL
-(defun ensure-keyword (name)
-  "Returns keyword for a name"
-  (etypecase name
-    (keyword name)
-    (string (nth-value 0 (intern (string-default-case name) :keyword)))
-    (symbol (nth-value 0 (intern (symbol-name name) :keyword)))))
 
 ;; From KMRCL
 (defmacro in (obj &rest choices)
@@ -321,3 +314,30 @@ list of characters and replacement strings."
          (setf (char new-string dpos) c)
          (incf dpos))))))
 
+
+(eval-when (:compile-toplevel :load-toplevel :execute)
+  (when (char= #\a (schar (symbol-name '#:a) 0))
+    (pushnew :lowercase-reader *features*)))
+
+(defun symbol-name-default-case (str)
+  #-lowercase-reader
+  (string-upcase str)
+  #+lowercase-reader
+  (string-downcase str))
+
+(defun convert-to-db-default-case (str database)
+  (if database
+      (case (db-type-default-case (database-underlying-type database))
+       (:upper (string-upcase str))
+       (:lower (string-downcase str))
+       (t str))
+    ;; Default CommonSQL behavior is to upcase strings
+    (string-upcase str)))
+           
+
+(defun ensure-keyword (name)
+  "Returns keyword for a name"
+  (etypecase name
+    (keyword name)
+    (string (nth-value 0 (intern (symbol-name-default-case name) :keyword)))
+    (symbol (nth-value 0 (intern (symbol-name name) :keyword)))))