diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/base/database/implementations-setup.lisp	Thu Feb 24 11:23:18 2011 +0000
@@ -0,0 +1,68 @@
+(cl:in-package #:amuse-database-admin)
+
+(defun create-implementations-table (&optional
+				     (database *amuse-database*))
+  (%create-implementations-table database)
+  (%create-implementation-stored-routines database))
+
+(defun drop-implementations-table (&optional
+				   (database *amuse-database*))
+  (%drop-implementations-table database)
+  (%drop-implementation-stored-routines database))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;; Helper functions
+
+(defun %create-implementations-table (database)
+  #.(clsql:locally-enable-sql-reader-syntax)
+  (clsql:create-table "amuse_implementations"
+		      '(([|implementation-id|] clsql:smallint :unsigned
+			 :not-null :auto-increment :primary-key)
+			([|implementation-name|] (varchar 255)
+			 :not-null :unique))
+		      :database database
+		      :transactions t)
+  #.(clsql:locally-disable-sql-reader-syntax))
+
+(defun %drop-implementations-table (database)
+  (clsql:drop-table "amuse_implementations"
+		    :if-does-not-exist :ignore
+		    :database database))
+
+(defun %create-implementation-stored-routines (database)
+  (%create-db-fun-get-impl-id database)
+  (%create-db-fun-get-impl-name database))
+
+(defun %drop-implementation-stored-routines (database)
+  (%drop-db-fun-get-impl-id database)
+  (%drop-db-fun-get-impl-name database))
+
+(defun %create-db-fun-get-impl-id (database)
+  (clsql:execute-command "
+CREATE FUNCTION get_impl_id (
+impl_name VARCHAR(255))
+RETURNS SMALLINT
+RETURN (SELECT implementation_id
+FROM amuse_implementations
+WHERE implementation_name = impl_name);"
+			 :database database))
+
+(defun %drop-db-fun-get-impl-id (database)
+  (clsql:execute-command "
+DROP FUNCTION get_impl_id"
+			 :database database))
+
+(defun %create-db-fun-get-impl-name (database)
+  (clsql:execute-command "
+CREATE FUNCTION get_impl_name (
+impl_id SMALLINT)
+RETURNS VARCHAR(255)
+RETURN (SELECT implementation_name
+FROM amuse_implementations
+WHERE implementation_id = impl_id);"
+			 :database database))
+
+(defun %drop-db-fun-get-impl-name (database)
+  (clsql:execute-command "
+DROP FUNCTION get_impl_name"
+			 :database database))