1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
5 ;;;; Name: mysql-usql.cl
6 ;;;; Purpose: MySQL interface functions to support UncommonSQL
7 ;;;; Programmers: Kevin M. Rosenberg and onShore Development Inc
8 ;;;; Date Started: Mar 2002
10 ;;;; $Id: mysql-usql.cl,v 1.3 2002/04/07 15:11:04 kevin Exp $
12 ;;;; This file, part of CLSQL, is Copyright (c) 2002 by Kevin M. Rosenberg
13 ;;;; and by onShore Development Inc.
15 ;;;; CLSQL users are granted the rights to distribute and use this software
16 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
17 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
18 ;;;; *************************************************************************
20 (declaim (optimize (debug 3) (speed 3) (safety 1) (compilation-speed 0)))
21 (in-package :clsql-mysql)
23 (defmethod database-list-tables ((database mysql-database)
24 &key (system-tables nil))
25 (declare (ignore system-tables))
26 (mapcar #'car (database-query "show tables" database :auto)))
30 (defmethod database-list-attributes ((table string) (database mysql-database))
33 (format nil "SHOW COLUMNS FROM ~A" table)
36 (defmethod database-attribute-type (attribute (table string)
37 (database mysql-database))
42 "SHOW COLUMNS FROM ~A LIKE '~A'" table attribute)
44 (let* ((str (car result))
45 (end-str (position #\( str))
46 (substr (subseq str 0 end-str)))
48 (intern (string-upcase substr) :keyword) nil))))
51 (defun %sequence-name-to-table (sequence-name)
52 (concatenate 'string "_usql_seq_" (sql-escape sequence-name)))
54 (defmethod database-create-sequence (sequence-name
55 (database mysql-database))
56 (let ((table-name (%sequence-name-to-table sequence-name)))
57 (database-execute-command
58 (concatenate 'string "CREATE TABLE " table-name
59 " (id int NOT NULL PRIMARY KEY AUTO_INCREMENT)")
61 (database-execute-command
62 (concatenate 'string "INSERT INTO " table-name
66 (defmethod database-drop-sequence (sequence-name
67 (database mysql-database))
68 (database-execute-command
69 (concatenate 'string "DROP TABLE " (%sequence-name-to-table sequence-name))
72 (defmethod database-sequence-next (sequence-name (database mysql-database))
73 (database-execute-command
74 (concatenate 'string "UPDATE " (%sequence-name-to-table sequence-name)
75 " SET id=LAST_INSERT_ID(id+1)")
77 (mysql:mysql-insert-id (clsql-mysql::database-mysql-ptr database)))
80 (defmethod database-output-sql ((expr clsql-sys::sql-typecast-exp)
81 (database mysql-database))
82 (with-slots (clsql-sys::modifier clsql-sys::components)
84 (if clsql-sys::modifier
86 (clsql-sys::output-sql clsql-sys::components database)
87 (write-char #\: sql-sys::*sql-stream*)
88 (write-char #\: sql-sys::*sql-stream*)
89 (write-string (symbol-name clsql-sys::modifier)
90 clsql-sys::*sql-stream*)))))
93 (defmethod database-output-sql-as-type ((type (eql 'integer)) val
94 (database mysql-database))
95 ;; typecast it so it uses the indexes
97 (make-instance 'clsql-sys::sql-typecast-exp