From bac9ab414127873b058d0b2ff3902399ef5d646f Mon Sep 17 00:00:00 2001 From: Silvio Date: Fri, 26 Mar 2010 18:22:33 -0300 Subject: Adding isis db module --- index.php | 7 ++++-- isis.php | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 isis.php diff --git a/index.php b/index.php index 071d06d..f5a5704 100644 --- a/index.php +++ b/index.php @@ -177,10 +177,13 @@ include('spyc/spyc.php');

query reading a record

read(3); + $r = $db->read(6); echo "
---\n", $r->toString(), "---\n

\n"; echo '
';
-    echo print_r($r);
+    //print_r($r);
+    //print_r($r->val[8]);
+    print_r(preg_split('/\t/', $r->val[7]));
+
     echo '
'; } // end else could contact server ?> diff --git a/isis.php b/isis.php new file mode 100644 index 0000000..66b3b7d --- /dev/null +++ b/isis.php @@ -0,0 +1,86 @@ + array( + 'name' => 'dbname', + ), + 'fields' => array( + 'field_name' => array( + 'id' => 1, + 'size' => 1000, + 'format' => 'numeric', + 'repeat' => TRUE, + 'subfields' => array( + 'a' => 'test', + 'b' => 'test2', + ), + ), + ), +); + +/** + * Generic interface for reading Isis databases. + */ +interface IsisDb { + // Constructor. + public function __construct($schema); + + // Return field data for a given entry. + public function fields($id); + + // Return subfield data for a given entry. + public function subfields($id); + + // Read an entry. + public function read($id); + + // Return number of rows in the database. + public function rows(); +} + +/** + * Malete implementation of IsisDb. + */ +class MaleteDb implements IsisDb { + var $fdt; + var $db; + var $format; + + public function __construct($schema) { + // Save db schema. + $format = $schema; + + // Setup $fdt used by malete. + foreach ($schema['fields'] as $field => $info) { + $fdt[$field] = $info['id']; + } + + // Open a database connection. + $db = new Isis_Db($fdt, $schema['db']['name'], new Isis_Server()); + } + + public function fields($id == NULL) { + } + + public function subfields($id == NULL) { + } + + // TODO: put result into $schema format. + public function read($id) { + if (!is_numeric($id) { + return FALSE; + } + return $this->$db->read($id); + } + + public function rows() { + } +} + +?> -- cgit v1.2.3