More work on a default encoding so that running through cffi-uffi,
[clsql.git] / db-sqlite3 / sqlite3-sql.lisp
index 927716a0c356f01a56861684bec099ce8ad05a04..8ce592c6fbe1978f1e0d0ee824b33f4ae9ca05a3 100644 (file)
@@ -31,7 +31,7 @@
 (defmethod database-name-from-spec (connection-spec
                                     (database-type (eql :sqlite3)))
   (check-sqlite3-connection-spec connection-spec)
-  (first connection-spec))
+  (princ-to-string (first connection-spec)))
 
 (defmethod database-connect (connection-spec (database-type (eql :sqlite3)))
   (check-sqlite3-connection-spec connection-spec)
 
 (declaim (inline sqlite3-table-info))
 (defun sqlite3-table-info (table database)
-  (database-query (format nil "PRAGMA table_info('~A')" table)
-                  database nil nil))
+  (let ((sql (format nil "PRAGMA table_info('~A')"
+                     (clsql-sys::unescaped-database-identifier table))))
+    (database-query sql database nil nil)))
 
 (defmethod database-list-attributes (table (database sqlite3-database)
                                            &key (owner nil))
                                     (database sqlite3-database)
                                     &key (owner nil))
   (declare (ignore owner))
-
+  
   (loop for field-info in (sqlite3-table-info table database)
-      when (string= attribute (second field-info))
+      when (string= (clsql-sys::unescaped-database-identifier attribute)
+                    (second field-info))
       return
         (let* ((raw-type (third field-info))
                (start-length (position #\( raw-type))
                   (if (string-equal (fourth field-info) "0")
                       1 0)))))
 
+(defmethod database-last-auto-increment-id ((database sqlite3-database) table column)
+  (declare (ignore table column))
+  (car (query "SELECT LAST_INSERT_ROWID();"
+             :flatp t :field-names nil
+             :database database)))
+
 (defmethod database-create (connection-spec (type (eql :sqlite3)))
   (declare (ignore connection-spec))
   ;; databases are created automatically by Sqlite3
     (or (string-equal ":memory:" name)
         (and (probe-file name) t))))
 
+(defmethod database-get-type-specifier ((type (eql 'integer))
+                                        args database
+                                        (db-type (eql :sqlite3)))
+  (declare (ignore database))
+  (if args
+      (format nil "INTEGER(~A)" (car args))
+      "INTEGER"))
+
+(defmethod database-get-type-specifier ((type (eql 'integer))
+                                        args database
+                                        (db-type (eql :sqlite3)))
+  (declare (ignore database))
+  (if args
+      (format nil "INTEGER(~A)" (car args))
+      "INTEGER"))
+
 ;;; Database capabilities
 
 (defmethod db-type-has-boolean-where? ((db-type (eql :sqlite3)))
   nil)
+
+(defmethod db-type-has-auto-increment? ((db-type (eql :sqlite3)))
+  t)