annotate base/database/implementations-setup.lisp @ 287:00d35eb70ef9

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