From 922aa22d64276a53a7b354a08a6a1e1a52fa42e4 Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Sun, 6 Oct 2013 18:44:46 +0200 Subject: [PATCH] Implement a MySQL list-views function to prepare for VIEWS support. --- mysql.lisp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/mysql.lisp b/mysql.lisp index 62f35d2..7ae01aa 100644 --- a/mysql.lisp +++ b/mysql.lisp @@ -33,6 +33,28 @@ ;; free resources (cl-mysql:disconnect))) +(defun list-views (dbname + &key + only-tables + (host *myconn-host*) + (user *myconn-user*) + (pass *myconn-pass*)) + "Return a flat list of all the view names and definitions known in given DBNAME" + (cl-mysql:connect :host host :user user :password pass) + + (unwind-protect + (progn + (cl-mysql:use dbname) + ;; that returns a pretty weird format, process it + (caar (cl-mysql:query (format nil " + select table_name, view_definition + from information_schema.views + where table_schema = '~a' + ~@[and table_name in (~{'~a'~^,~})~] +order by table_name" dbname only-tables)))) + ;; free resources + (cl-mysql:disconnect))) + ;;; ;;; Tools to get MySQL table and columns definitions and transform them to ;;; PostgreSQL CREATE TABLE statements, and run those.