annotate base/database/implementations-setup.lisp @ 216:e1842efb1dd4

amuse-database-admin add implementation and dataset functionality Ignore-this: 787cc01acf2d6a58640fec017de16c17 darcs-hash:20090716145807-16a00-6fe5ad4a2b6252b2c1f3d109a16455bb32243965.gz committer: Jamie Forth <j.forth@gold.ac.uk>
author j.forth <j.forth@gold.ac.uk>
date Thu, 24 Feb 2011 11:23:18 +0000
parents
children 385935631532
rev   line source
j@216 1 (cl:in-package #:amuse-database-admin)
j@216 2
j@216 3 (defun create-implementations-table (&optional
j@216 4 (database *amuse-database*))
j@216 5 (%create-implementations-table database)
j@216 6 (%create-implementation-stored-routines database))
j@216 7
j@216 8 (defun drop-implementations-table (&optional
j@216 9 (database *amuse-database*))
j@216 10 (%drop-implementations-table database)
j@216 11 (%drop-implementation-stored-routines database))
j@216 12
j@216 13 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
j@216 14 ;;; Helper functions
j@216 15
j@216 16 (defun %create-implementations-table (database)
j@216 17 #.(clsql:locally-enable-sql-reader-syntax)
j@216 18 (clsql:create-table "amuse_implementations"
j@216 19 '(([|implementation-id|] clsql:smallint :unsigned
j@216 20 :not-null :auto-increment :primary-key)
j@216 21 ([|implementation-name|] (varchar 255)
j@216 22 :not-null :unique))
j@216 23 :database database
j@216 24 :transactions t)
j@216 25 #.(clsql:locally-disable-sql-reader-syntax))
j@216 26
j@216 27 (defun %drop-implementations-table (database)
j@216 28 (clsql:drop-table "amuse_implementations"
j@216 29 :if-does-not-exist :ignore
j@216 30 :database database))
j@216 31
j@216 32 (defun %create-implementation-stored-routines (database)
j@216 33 (%create-db-fun-get-impl-id database)
j@216 34 (%create-db-fun-get-impl-name database))
j@216 35
j@216 36 (defun %drop-implementation-stored-routines (database)
j@216 37 (%drop-db-fun-get-impl-id database)
j@216 38 (%drop-db-fun-get-impl-name database))
j@216 39
j@216 40 (defun %create-db-fun-get-impl-id (database)
j@216 41 (clsql:execute-command "
j@216 42 CREATE FUNCTION get_impl_id (
j@216 43 impl_name VARCHAR(255))
j@216 44 RETURNS SMALLINT
j@216 45 RETURN (SELECT implementation_id
j@216 46 FROM amuse_implementations
j@216 47 WHERE implementation_name = impl_name);"
j@216 48 :database database))
j@216 49
j@216 50 (defun %drop-db-fun-get-impl-id (database)
j@216 51 (clsql:execute-command "
j@216 52 DROP FUNCTION get_impl_id"
j@216 53 :database database))
j@216 54
j@216 55 (defun %create-db-fun-get-impl-name (database)
j@216 56 (clsql:execute-command "
j@216 57 CREATE FUNCTION get_impl_name (
j@216 58 impl_id SMALLINT)
j@216 59 RETURNS VARCHAR(255)
j@216 60 RETURN (SELECT implementation_name
j@216 61 FROM amuse_implementations
j@216 62 WHERE implementation_id = impl_id);"
j@216 63 :database database))
j@216 64
j@216 65 (defun %drop-db-fun-get-impl-name (database)
j@216 66 (clsql:execute-command "
j@216 67 DROP FUNCTION get_impl_name"
j@216 68 :database database))