Source for file DbStore.php

Documentation is available at DbStore.php

  1. <?php
  2.  
  3. // ----------------------------------------------------------------------------------
  4. // Class: DbStore
  5. // ----------------------------------------------------------------------------------
  6.  
  7. /**
  8.  * DbStore is a persistent store of RDF data using relational database technology.
  9.  * DbStore uses ADOdb Library for PHP V3.60 (http://php.weblogs.com/ADODB),
  10.  * which allows to connect to multiple databases in a portable manner.
  11.  * This class also provides methods for creating tables for MsAccess, MySQL, and MS SQL Server.
  12.  * If you want to use other databases, you will have to create tables by yourself
  13.  * according to the abstract database schema described in the API documentation.
  14.  *
  15.  *
  16.  * @version  $Id: fsource_model__modelDbStore.php.html,v 1.10 2006/06/26 12:34:12 tgauss Exp $
  17.  * @author   Radoslaw Oldakowski <radol@gmx.de>
  18.  * @author   Daniel Westphal (http://www.d-westphal.de)
  19.  *
  20.  * @package model
  21.  * @access    public
  22.  */
  23.  
  24.  
  25. class DbStore extends Object{
  26.  
  27. /**
  28.  * Database connection object
  29.  *
  30.  * @var     object ADOConnection 
  31.  * @access    private
  32.  */
  33.  var $dbConn;
  34.  
  35.  
  36. /**
  37.  * Constructor:
  38.  * Set the database connection with the given parameters.
  39.  *
  40.  * @param   string   $dbDriver 
  41.  * @param   string   $host 
  42.  * @param   string   $dbName 
  43.  * @param   string   $user 
  44.  * @param   string   $password 
  45.  * @access    public
  46.  */
  47.  function DbStore ($dbDriver=ADODB_DB_DRIVER$host=ADODB_DB_HOST$dbName=ADODB_DB_NAME,
  48.                    $user=ADODB_DB_USER$password=ADODB_DB_PASSWORD{
  49.                   
  50.    // include DBase Package
  51.    require_once(RDFAPI_INCLUDE_DIR.PACKAGE_DBASE);
  52.                        
  53.    // create a new connection object
  54.    $this->dbConn =ADONewConnection($dbDriver);
  55.    
  56.    // connect to database
  57.    $this->dbConn->connect($host$user$password$dbName);
  58.    
  59.    // optimized for speed
  60.    $this->dbConn->setFetchMode(ADODB_FETCH_NUM);
  61.    $ADODB_COUNTRECS FALSE;
  62.    
  63.    //activate the ADOdb DEBUG mode
  64.    if (ADODB_DEBUG_MODE =='1')
  65.       $this->dbConn->debug TRUE;
  66.  }
  67.  
  68.  
  69. /**
  70.  * Create tables and indexes for the given database type.
  71.  * Currently supported: MsAccess and MySQL.
  72.  * If you want to use other databases, you will have to create tables by yourself
  73.  * according to the abstract <a href="database_schema.html">database schema</a>
  74.  * described in the API documentation.
  75.  *
  76.  * @param   string  $databaseType 
  77.  * @throws    PhpError
  78.  * @access    public
  79.  */
  80.  function createTables($databaseType{
  81.  
  82.    if (!strcasecmp($databaseType'MsAccess'))
  83.    $this->_createTables_MsAccess();
  84.    elseif (!strcasecmp($databaseType'MySQL'))
  85.        $this->_createTables_MySql();
  86.    elseif (!strcasecmp($databaseType'MSSQL'))
  87.            $this->_createTables_mssql();
  88.    else {
  89.        $errmsg RDFAPI_ERROR "(classDbStoremethodcreateTables('$databaseType')):
  90.                                   Currently only MsAccesMySQL and MSSQL supported.";
  91.        trigger_error($errmsgE_USER_ERROR);
  92.    }
  93.  }
  94.  
  95.  
  96. /**
  97.  * List all DbModels stored in the database.
  98.  *
  99.  * @return  array 
  100.  * @throws    SqlError
  101.  * @access    public
  102.  */
  103.  function listModels({
  104.  
  105.    $recordSet =$this->dbConn->execute("SELECT modelURI, baseURI
  106.                                          FROM models");
  107.    if (!$recordSet)
  108.       echo $this->dbConn->errorMsg();
  109.    else {
  110.       $models array();
  111.       $i=0;
  112.       while (!$recordSet->EOF{
  113.  
  114.           $models[$i]['modelURI'$recordSet->fields[0];
  115.           $models[$i]['baseURI'$recordSet->fields[1];
  116.             
  117.           ++$i;
  118.           $recordSet->moveNext();
  119.       }
  120.       return $models;
  121.    }
  122.  }
  123.  
  124.  
  125. /**
  126.  * Check if the DbModel with the given modelURI is already stored in the database
  127.  *
  128.  * @param   string   $modelURI 
  129.  * @return  boolean 
  130.  * @throws    SqlError
  131.  * @access    public
  132.  */
  133.  function modelExists($modelURI{
  134.  
  135.    $res =$this->dbConn->execute("SELECT COUNT(*) FROM models
  136.                                    WHERE modelURI = '" .$modelURI ."'");
  137.    if (!$res)
  138.       echo $this->dbConn->errorMsg();
  139.    else {
  140.       if (!$res->fields[0])
  141.          return FALSE;
  142.       return TRUE;
  143.    }
  144.  }
  145.  
  146.  
  147. /**
  148.  * Create a new instance of DbModel with the given $modelURI and
  149.  * load the corresponding values of modelID and baseURI from the database.
  150.  * Return FALSE if the DbModel does not exist.
  151.  *
  152.  * @param   string   $modelURI 
  153.  * @return  object DbModel 
  154.  * @access    public
  155.  */
  156.  function getModel($modelURI{
  157.  
  158.    if (!$this->modelExists($modelURI))
  159.       return FALSE;
  160.    else {
  161.       $modelVars =$this->dbConn->execute("SELECT modelURI, modelID, baseURI
  162.                                             FROM models
  163.                                             WHERE modelURI='" .$modelURI ."'");
  164.  
  165.       return new DbModel($this->dbConn$modelVars->fields[0],
  166.                          $modelVars->fields[1]$modelVars->fields[2]);
  167.    }
  168.  }
  169.  
  170.  
  171. /**
  172.  * Create a new instance of DbModel with the given $modelURI
  173.  * and insert the DbModel variables into the database.
  174.  * Return FALSE if there is already a model with the given URI.
  175.  *
  176.  * @param   string   $modelURI 
  177.  * @param   string   $baseURI 
  178.  * @return  object DbModel 
  179.  * @throws  SqlError
  180.  * @access    public
  181.  */
  182.  function getNewModel($modelURI$baseURI=NULL{
  183.  
  184.    if ($this->modelExists($modelURI))
  185.       return FALSE;
  186.    else {
  187.       $modelID $this->_createUniqueModelID();
  188.       
  189.       $rs =$this->dbConn->execute("INSERT INTO models
  190.                                             VALUES ('" .$modelID ."',
  191.                                                     '" .$modelURI ."',
  192.                                                     '" .$baseURI ."')");
  193.       if (!$rs)
  194.          $this->dbConn->errorMsg();
  195.       else
  196.          return new DbModel($this->dbConn$modelURI$modelID$baseURI);
  197.    }
  198.  }
  199.  
  200.  
  201. /**
  202.  * Store a MemModel or another DbModel from a different DbStore in the database.
  203.  * Return FALSE if there is already a model with modelURI matching the modelURI
  204.  * of the given model.
  205.  *
  206.  * @param   object Model  &$model 
  207.  * @param   string $modelURI 
  208.  * @return  boolean 
  209.  * @access    public
  210.  */
  211.  function putModel(&$model$modelURI=NULL{
  212.  
  213.    if (!$modelURI{
  214.       if (is_a($model'MemModel'))
  215.          $modelURI 'DbModel-' .$this->_createUniqueModelID();
  216.       else
  217.          $modelURI $model->modelURI;
  218.    }else
  219.       if ($this->modelExists($modelURI))
  220.          return FALSE;
  221.  
  222.          
  223.    $newDbModel $this->getNewModel($modelURI$model->getBaseURI());
  224.    $newDbModel->addModel($model);
  225.  }
  226.  
  227.  
  228. /**
  229.  * Close the DbStore.
  230.  * !!! Warning: If you close the DbStore all active instances of DbModel from this
  231.  * !!!          DbStore will lose their database connection !!!
  232.  *
  233.  * @access    public
  234.  */
  235.  function close({
  236.  
  237.    $this->dbConn->close();
  238.    unset($this);
  239.  }
  240.  
  241.    
  242. // =============================================================================
  243. // **************************** private methods ********************************
  244. // =============================================================================
  245.  
  246.  
  247. /**
  248.  * Create a unique ID for the DbModel to be insert into the models table.
  249.  * This method was implemented because some databases do not support auto-increment.
  250.  *
  251.  * @return  integer 
  252.  * @access    private
  253.  */
  254.  function _createUniqueModelID({
  255.  
  256.    $maxModelID =$this->dbConn->GetOne('SELECT MAX(modelID) FROM models');
  257.    return ++$maxModelID;
  258.  }
  259.  
  260.  /**
  261.  * Create a unique ID for the dataset to be insert into the datasets table.
  262.  * This method was implemented because some databases do not support auto-increment.
  263.  *
  264.  * @return  integer 
  265.  * @access    private
  266.  */
  267.  function _createUniqueDatasetID({
  268.  
  269.    $maxDatasetID =$this->dbConn->GetOne('SELECT MAX(datasetId) FROM datasets');
  270.    return ++$maxDatasetID;
  271.  }
  272.  
  273.  
  274. /**
  275.  * Create tables and indexes for MsAccess database
  276.  *
  277.  * @throws  SqlError
  278.  * @access    private
  279.  */
  280.  function _createTables_MsAccess({
  281.  
  282.    $this->dbConn->startTrans();
  283.    
  284.    $this->dbConn->execute('CREATE TABLE models
  285.                            (modelID long primary key,
  286.                             modelURI varchar not null,
  287.                             baseURI varchar)');
  288.  
  289.    $this->dbConn->execute('CREATE UNIQUE INDEX m_modURI_idx ON models (modelURI)');
  290.  
  291.    $this->dbConn->execute('CREATE TABLE statements
  292.                            (modelID long,
  293.                             subject varchar,
  294.                             predicate varchar,
  295.                             object Memo,
  296.                             l_language varchar,
  297.                             l_datatype varchar,
  298.                             subject_is varchar(1),
  299.                             object_is varchar(1),
  300.                             primary key (modelID, subject, predicate, object,
  301.                                          l_language, l_datatype))');
  302.    
  303.    $this->dbConn->execute('CREATE INDEX s_mod_idx ON statements (modelID)');
  304.    $this->dbConn->execute('CREATE INDEX s_sub_idx ON statements (subject)');
  305.    $this->dbConn->execute('CREATE INDEX s_pred_idx ON statements (predicate)');
  306.    $this->dbConn->execute('CREATE INDEX s_obj_idx ON statements (object)');
  307.  
  308.      $this->dbConn->execute('CREATE TABLE namespaces
  309.                            (modelID long,
  310.                             namespace varchar,
  311.                             prefix varchar,
  312.                             primary key (modelID, namespace, prefix))');
  313.  
  314.    $this->dbConn->execute('CREATE INDEX n_name_idx ON namespaces (namespace)');
  315.    $this->dbConn->execute('CREATE INDEX n_pref_idx ON namespaces (prefix)');
  316.  
  317.      $this->dbConn->execute("CREATE TABLE datasets
  318.                            (datasetName varchar,
  319.                               defaultModelUri varchar,
  320.                             primary key (datasetName))");
  321.    
  322.    $this->dbConn->execute('CREATE INDEX nGS_idx1 ON datasets (datasetName)');
  323.  
  324.    
  325.    $this->dbConn->execute("CREATE TABLE `dataset_model` (
  326.                               datasetName varchar,
  327.                               modelId long,
  328.                             graphURI varchar,
  329.                             PRIMARY KEY  (modelId,datasetName))");
  330.    
  331.    
  332.    if (!$this->dbConn->completeTrans())
  333.       echo $this->dbConn->errorMsg();
  334.  }
  335.  
  336.  
  337. /**
  338.  * Create tables and indexes for MySQL database
  339.  *
  340.  * @throws  SqlError
  341.  * @access    private
  342.  */
  343.  function _createTables_MySql({
  344.  
  345.    $this->dbConn->startTrans();
  346.  
  347.    $this->dbConn->execute("CREATE TABLE models
  348.                            (modelID bigint NOT NULL,
  349.                             modelURI varchar(255) NOT NULL,
  350.                             baseURI varchar(255) DEFAULT '',
  351.                             primary key (modelID))");
  352.                             
  353.    $this->dbConn->execute('CREATE UNIQUE INDEX m_modURI_idx ON models (modelURI)');
  354.  
  355.    $this->dbConn->execute("CREATE TABLE statements
  356.                            (modelID bigint NOT NULL,
  357.                             subject varchar(255) NOT NULL,
  358.                             predicate varchar(255) NOT NULL,
  359.                             object text,
  360.                             l_language varchar(255) DEFAULT '',
  361.                             l_datatype varchar(255) DEFAULT '',
  362.                             subject_is varchar(1) NOT NULL,
  363.                             object_is varchar(1) NOT NULL)");
  364.     
  365.    $this->dbConn->execute("CREATE TABLE namespaces
  366.                            (modelID bigint NOT NULL,
  367.                             namespace varchar(255) NOT NULL,
  368.                             prefix varchar(255) NOT NULL,
  369.                                primary key (modelID,namespace))");
  370.  
  371.   $this->dbConn->execute("CREATE TABLE `dataset_model` (
  372.                               `datasetName` varchar(255) NOT NULL default '0',
  373.                               `modelId` bigint(20) NOT NULL default '0',
  374.                             `graphURI` varchar(255) NOT NULL default '',
  375.                              PRIMARY KEY  (`modelId`,`datasetName`))");
  376.   
  377.   $this->dbConn->execute("CREATE TABLE `datasets` (
  378.                               `datasetName` varchar(255) NOT NULL default '',
  379.                             `defaultModelUri` varchar(255) NOT NULL default '0',
  380.                              PRIMARY KEY  (`datasetName`),
  381.                              KEY `datasetName` (`datasetName`))");
  382.    
  383.    $this->dbConn->execute('CREATE INDEX s_mod_idx ON statements (modelID)');
  384.    $this->dbConn->execute('CREATE INDEX n_mod_idx ON namespaces (modelID)');
  385.    
  386.    $this->dbConn->execute('CREATE INDEX s_sub_pred_idx ON statements
  387.                           (subject(200),predicate(200))');
  388.    $this->dbConn->execute('CREATE INDEX s_obj_idx ON statements (object(250))');
  389.  
  390.    if (!$this->dbConn->completeTrans())
  391.       echo $this->dbConn->errorMsg();
  392.  }
  393.  
  394.  /**
  395.  * Create tables and indexes for MSSQL database
  396.  *
  397.  * @throws  SqlError
  398.  * @access    private
  399.  */
  400.  function _createTables_mssql(){
  401.      
  402.    $this->dbConn->startTrans();
  403.  
  404.    $this->dbConn->execute("CREATE TABLE [dbo].[models] (
  405.                             [modelID] [int] NOT NULL ,
  406.                             [modelURI] [nvarchar] (200) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
  407.                             [baseURI] [nvarchar] (200) COLLATE SQL_Latin1_General_CP1_CI_AS NULL 
  408.                             ) ON [PRIMARY]");
  409.                            
  410.    $this->dbConn->execute("CREATE TABLE [dbo].[statements] (
  411.                             [modelID] [int] NOT NULL ,
  412.                             [subject] [nvarchar] (200) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
  413.                             [predicate] [nvarchar] (200) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
  414.                             [object] [text] COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
  415.                             [l_language] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
  416.                             [l_datatype] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
  417.                             [subject_is] [nchar] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
  418.                             [object_is] [nchar] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL 
  419.                             ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]");
  420.    
  421.    
  422.     $this->dbConn->execute("CREATE TABLE [dbo].[namespaces] (
  423.                             [modelID] [int] NOT NULL ,
  424.                             [namespace] [nvarchar] (200) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
  425.                             [prefix] [nvarchar] (200) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
  426.                             ) ON [PRIMARY]");
  427.  
  428.    $this->dbConn->execute("ALTER TABLE [dbo].[models] WITH NOCHECK ADD 
  429.                             CONSTRAINT [PK_models] PRIMARY KEY  CLUSTERED 
  430.                             (
  431.                                 [modelID]
  432.                             )  ON [PRIMARY] ");
  433.    $this->dbConn->execute("ALTER TABLE [dbo].[namespaces] WITH NOCHECK ADD 
  434.                             CONSTRAINT [PK_namespaces] PRIMARY KEY  CLUSTERED 
  435.                             (
  436.                                 [modelID],[namespace]
  437.                             )  ON [PRIMARY] ");
  438.    
  439.    $this->dbConn->execute("CREATE  INDEX [joint index on subject and predicate] ON [dbo].[statements]([subject], [predicate]) ON [PRIMARY]");
  440.    
  441.  
  442.    if (!$this->dbConn->completeTrans())
  443.        echo $this->dbConn->errorMsg();
  444.   
  445.  }
  446.  
  447.   
  448.   /** 
  449.   * Checks if tables are setup for RAP
  450.   * 
  451.   * @param   string  $databaseType 
  452.   * @throws SqlError
  453.   * @access public
  454.   ***/
  455.  function isSetup($databaseType="MySQL"
  456.    if ($databaseType=="MySQL"
  457.      return $this->_isSetup_MySql()
  458.     if ($databaseType=="MSSQL"
  459.      return $this->_isSetup_MSSQL()
  460.    else {
  461.        if ($databaseType=='MsAccess'){
  462.            return $this->_isSetup_MsAccess();
  463.        }else{
  464.      $errmsg=RDFAPI_ERROR."(classDbStoremethod isSetup('$databaseType')):\nCurrently only MySQLMsAccess and MSSQL are supported!";
  465.      trigger_error($errmsgE_USER_ERROR);}
  466.    }                            
  467.  }
  468.  
  469.  /** 
  470.   * Checks if tables are setup for RAP (MySql)
  471.   * 
  472.   * @throws SqlError
  473.   * @access private
  474.   ***/
  475.  function _isSetup_MySql({
  476.    $recordSet =$this->dbConn->execute("SHOW TABLES");
  477.    if (!$recordSet)
  478.      echo $this->dbConn->errorMsg();
  479.    else 
  480.      $tables array();
  481.      while (!$recordSet->EOF{
  482.  
  483.        $tables[]$recordSet->fields[0];
  484.        
  485.        if(isset($i)){++$i;}
  486.        $recordSet->moveNext();
  487.      }
  488.      if (in_array("models",$tables&& in_array("statements",$tables)&& in_array("namespaces",$tables)) return true;
  489.    }
  490.    return false
  491.    
  492.  }
  493.  
  494.  
  495.   /** 
  496.   * Checks if tables are setup for RAP (MsAccess)
  497.   * 
  498.   * @throws SqlError
  499.   * @access private
  500.   ***/
  501.  function _isSetup_MsAccess({
  502.        $tables =$this->dbConn->MetaTables();
  503.        if (!$tables)
  504.      echo $this->dbConn->errorMsg();
  505.    if (count($tables)==0){
  506.      return false;}
  507.    else {
  508.            if (in_array("models",$tables&& in_array("statements",$tables&& in_array("namespaces",$tables))return true;
  509.            }else{return false;}
  510.    
  511.  }
  512.  
  513.   /** 
  514.   * Checks if tables are setup for RAP (MSSQL)
  515.   * 
  516.   * @throws SqlError
  517.   * @access private
  518.   ***/
  519.  function _isSetup_MSSQL({
  520.        $tables =$this->dbConn->MetaTables();
  521.        if (!$tables)
  522.      echo $this->dbConn->errorMsg();
  523.    if (count($tables)==0){
  524.      return false;}
  525.    else {
  526.            if (in_array("models",$tables&& in_array("statements",$tables&& in_array("namespaces",$tables))return true;
  527.            }else{return false;}
  528.    
  529.  }
  530.  
  531.  
  532.  /**
  533.  * Create a new instance of DatasetDb with the given $datasetName
  534.  * and insert the DatasetDb variables into the database.
  535.  * Return FALSE if there is already a model with the given URI.
  536.  *
  537.  * @param   $datasetName string
  538.  * @return  object DatasetDB 
  539.  * @throws  SqlError
  540.  * @access    public
  541.  */
  542.  function getNewDatasetDb($datasetName
  543.  {
  544.  
  545.      require_once(RDFAPI_INCLUDE_DIR PACKAGE_DATASET);
  546.      
  547.    if ($this->datasetExists($datasetName))
  548.       return FALSE;
  549.    else 
  550.    {
  551.            $defaultModelUri=uniqid('http://rdfapi-php/dataset_defaultmodel_');
  552.            $defaultModel=$this->getNewModel($defaultModelUri);
  553.       
  554.           $rs =$this->dbConn->execute("INSERT INTO datasets
  555.                                             VALUES ('" .$datasetName ."',
  556.                                                     '" .$defaultModelUri."')");
  557.           
  558.       if (!$rs)
  559.          $this->dbConn->errorMsg();
  560.       else
  561.         $return=new DatasetDb(&$this->dbConn,&$this,$datasetName);
  562.            return ($return)
  563.    }
  564.  }
  565.  
  566.  /**
  567.  * Check if the Dataset with the given $datasetName is already stored in the database
  568.  *
  569.  * @param   $datasetName string
  570.  * @return  boolean 
  571.  * @throws    SqlError
  572.  * @access    public
  573.  */
  574. function datasetExists($datasetName{
  575.  
  576.    $res =$this->dbConn->execute("SELECT COUNT(*) FROM datasets
  577.                                    WHERE datasetName = '" .$datasetName ."'");
  578.    if (!$res)
  579.       echo $this->dbConn->errorMsg();
  580.    else {
  581.       if (!$res->fields[0])
  582.          return FALSE;
  583.       return TRUE;
  584.    }
  585.  }
  586.  
  587.  
  588.  /**
  589.  * Create a new instance of DatasetDb with the given $datasetName and
  590.  * load the corresponding values from the database.
  591.  * Return FALSE if the DbModel does not exist.
  592.  *
  593.  * @param   $datasetId string
  594.  * @return  object DatasetDb 
  595.  * @access    public
  596.  */
  597.  function getDatasetDb($datasetName{
  598.      
  599.   require_once(RDFAPI_INCLUDE_DIR PACKAGE_DATASET);
  600.  
  601.    if (!$this->datasetExists($datasetName))
  602.       return FALSE;
  603.    else 
  604.    {
  605.        $return=new DatasetDb(&$this->dbConn,&$this,$datasetName);
  606.            return ($return);   
  607.    }
  608.  }
  609.  
  610.  /**
  611.  * Create a new instance of namedGraphDb with the given $modelURI and graphName and
  612.  * load the corresponding values of modelID and baseURI from the database.
  613.  * Return FALSE if the DbModel does not exist.
  614.  *
  615.  * @param   $modelURI string
  616.  * @param   $graphName string
  617.  * @return  object NamedGraphMem 
  618.  * @access    public
  619.  */
  620.  function getNamedGraphDb($modelURI$graphName
  621.  {
  622.     require_once(RDFAPI_INCLUDE_DIR PACKAGE_DATASET);
  623.     
  624.    if (!$this->modelExists($modelURI))
  625.       return FALSE;
  626.    else {
  627.       $modelVars =$this->dbConn->execute("SELECT modelURI, modelID, baseURI
  628.                                             FROM models
  629.                                             WHERE modelURI='" .$modelURI ."'");
  630.  
  631.       return new NamedGraphDb($this->dbConn$modelVars->fields[0],
  632.                          $modelVars->fields[1]$graphName ,$modelVars->fields[2]);
  633.    }
  634.  }
  635.  
  636.  /**
  637.  * Create a new instance of namedGraphDb with the given $modelURI and graphName
  638.  * and insert the DbModel variables into the database (not the graphName. This
  639.  * is only stored persistently, when added to dataset).
  640.  * Return FALSE if there is already a model with the given URI.
  641.  *
  642.  * @param   $modelURI string
  643.  * @param      $graphName string
  644.  * @param   $baseURI string
  645.  * @return  object namedGraphDb 
  646.  * @throws  SqlError
  647.  * @access    public
  648.  */
  649.  function getNewNamedGraphDb($modelURI$graphName$baseURI=NULL{
  650.  
  651.    if ($this->modelExists($modelURI))
  652.       return FALSE;
  653.    else {
  654.       $modelID $this->_createUniqueModelID();
  655.       
  656.       $rs =$this->dbConn->execute("INSERT INTO models
  657.                                             VALUES ('" .$modelID ."',
  658.                                                     '" .$modelURI ."',
  659.                                                     '" .$baseURI ."')");
  660.       if (!$rs)
  661.          $this->dbConn->errorMsg();
  662.       else
  663.          return new NamedGraphDb($this->dbConn$modelURI$modelID$graphName$baseURI);
  664.    }
  665.  }
  666.  
  667.  /**
  668.  * Removes the graph with all statements from the database.
  669.  * Warning: A single namedGraph can be added to several datasets. So it'll be
  670.  * removed from all datasets.
  671.  *
  672.  * @param   $modelURI string
  673.  * @return  boolean 
  674.  * @throws  SqlError
  675.  * @access    public
  676.  */
  677.  function removeNamedGraphDb($modelURI
  678.  {
  679.     if (!$this->modelExists($modelURI))
  680.         return FALSE;
  681.     
  682.     $modelID $this->dbConn->GetOne("SELECT modelID FROM models WHERE modelURI='".$modelURI."'");
  683.     
  684.     $this->dbConn->execute("DELETE FROM models WHERE modelID=".$modelID);
  685.     $this->dbConn->execute("DELETE FROM dataset_model WHERE modelId=".$modelID);
  686.     $this->dbConn->execute("DELETE FROM statements WHERE modelID=".$modelID);
  687.     
  688.     return true;
  689.  }
  690.  
  691. // end: Class DbStore
  692. ?>

Documentation generated on Mon, 26 Jun 2006 14:25:25 +0200 by phpDocumentor 1.3.0RC6