|
From: <cw...@us...> - 2007-10-10 17:41:16
|
Revision: 545
http://rdfapi-php.svn.sourceforge.net/rdfapi-php/?rev=545&view=rev
Author: cweiske
Date: 2007-10-10 10:41:15 -0700 (Wed, 10 Oct 2007)
Log Message:
-----------
- Support MySQLi (link to MySQL methods)
- Fix wrong cAsE in database drivers
Modified Paths:
--------------
trunk/rdfapi-php/api/model/DbStore.php
trunk/rdfapi-php/test/setup.php
Modified: trunk/rdfapi-php/api/model/DbStore.php
===================================================================
--- trunk/rdfapi-php/api/model/DbStore.php 2007-10-09 16:24:08 UTC (rev 544)
+++ trunk/rdfapi-php/api/model/DbStore.php 2007-10-10 17:41:15 UTC (rev 545)
@@ -35,6 +35,7 @@
*/
public static $arSupportedDbTypes = array(
"MySQL",
+ "MySQLi",
"MSSQL",
'MsAccess'
);
@@ -453,6 +454,16 @@
/**
+ * Creates tables on a MySQLi database
+ */
+ function _createTables_MySQLi()
+ {
+ return $this->_createTables_MySQL();
+ }//function _createTables_MySQLi()
+
+
+
+ /**
* Create tables and indexes for MSSQL database
*
* @return boolean true If all is ok
@@ -481,7 +492,7 @@
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]");
- $this->dbConn->execute("CREATE TABLE [dbo].[namespaces] (
+ $this->dbConn->execute("CREATE TABLE [dbo].[namespaces] (
[modelID] [int] NOT NULL ,
[namespace] [nvarchar] (200) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[prefix] [nvarchar] (200) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
@@ -532,9 +543,11 @@
* You can pass NULL or omit the parameter to
* use the parameter from the dbstore constructor
*
- * @return string Database driver string
+ * @param string $databaseType Database driver name (e.g. MySQL)
+ *
+ * @return string Database driver string (e.g. MySQL)
*/
- protected function getDriver($databaseType = null)
+ public function getDriver($databaseType = null)
{
if ($databaseType === null) {
if ($this->driver === null) {
@@ -544,12 +557,32 @@
$databaseType = $this->driver;
}
}
+ if (!self::isDriverSupported($databaseType)) {
+ //check if it is a known driver in wrong case
+ $arLowercases = array_map('strtolower', self::$arSupportedDbTypes);
+ $arMapping = array_combine($arLowercases, self::$arSupportedDbTypes);
+ if (isset($arMapping[strtolower($databaseType)])) {
+ $databaseType = $arMapping[strtolower($databaseType)];
+ }
+ }
return $databaseType;
- }//protected function getDriver($databaseType = null)
+ }//public function getDriver($databaseType = null)
/**
+ * Returns if the given driver is supported
+ *
+ * @return boolean True if it supported, false if not
+ */
+ public static function isDriverSupported($databaseType)
+ {
+ return in_array($databaseType, self::$arSupportedDbTypes);
+ }//public static function isDriverSupported($databaseType)
+
+
+
+ /**
* Checks if the given driver is supported and throws an
* Exception if not.
*
@@ -561,7 +594,7 @@
*/
public static function assertDriverSupported($databaseType)
{
- if (!in_array($databaseType, self::$arSupportedDbTypes)) {
+ if (!self::isDriverSupported($databaseType)) {
throw new Exception(
'Unsupported database type, only supported: '
. implode(', ', self::$arSupportedDbTypes)
@@ -572,69 +605,99 @@
- /**
- * Checks if tables are setup for RAP (MySql)
- *
- * @throws SqlError
- * @access private
- **/
- function _isSetup_MySql() {
- $recordSet =& $this->dbConn->execute("SHOW TABLES");
- if (!$recordSet)
- echo $this->dbConn->errorMsg();
- else {
- $tables = array();
- while (!$recordSet->EOF) {
+ /**
+ * Checks if tables are setup for RAP (MySql)
+ *
+ * @throws SqlError
+ * @access private
+ **/
+ function _isSetup_MySQL()
+ {
+ $recordSet =& $this->dbConn->execute("SHOW TABLES");
+ if (!$recordSet) {
+ throw new Exception($this->dbConn->errorMsg());
+ } else {
+ $tables = array();
+ while (!$recordSet->EOF) {
+ $tables[]= $recordSet->fields[0];
+ if (isset($i)) {
+ ++$i;
+ }
+ $recordSet->moveNext();
+ }
+ if (in_array("models",$tables) && in_array("statements",$tables)
+ && in_array("namespaces",$tables)) {
+ return true;
+ }
+ }
+ return false;
+ }//function _isSetup_MySQL()
- $tables[]= $recordSet->fields[0];
- if(isset($i)){++$i;}
- $recordSet->moveNext();
- }
- if (in_array("models",$tables) && in_array("statements",$tables)&& in_array("namespaces",$tables)) return true;
- }
- return false;
- }
+ /**
+ * Checks if tables are setup for RAP (MySQLi)
+ *
+ * @see _isSetup_MySQL()
+ */
+ function _isSetup_MySQLi()
+ {
+ return $this->_isSetup_MySQL();
+ }//function _isSetup_MySQLi()
- /**
- * Checks if tables are setup for RAP (MsAccess)
- *
- * @throws SqlError
- * @access private
- **/
- function _isSetup_MsAccess() {
- $tables =& $this->dbConn->MetaTables();
- if (!$tables)
- echo $this->dbConn->errorMsg();
- if (count($tables)==0){
- return false;}
- else {
- if (in_array("models",$tables) && in_array("statements",$tables) && in_array("namespaces",$tables)){ return true;
- }else{return false;}
- }
- }
- /**
- * Checks if tables are setup for RAP (MSSQL)
- *
- * @throws SqlError
- * @access private
- **/
- function _isSetup_MSSQL() {
- $tables =& $this->dbConn->MetaTables();
- if (!$tables)
- echo $this->dbConn->errorMsg();
- if (count($tables)==0){
- return false;}
- else {
- if (in_array("models",$tables) && in_array("statements",$tables) && in_array("namespaces",$tables)){ return true;
- }else{return false;}
- }
- }
+ /**
+ * Checks if tables are setup for RAP (MsAccess)
+ *
+ * @throws SqlError
+ * @access private
+ **/
+ function _isSetup_MsAccess()
+ {
+ $tables =& $this->dbConn->MetaTables();
+ if (!$tables) {
+ throw new Exception($this->dbConn->errorMsg());
+ }
+ if (count($tables) == 0) {
+ return false;
+ } else {
+ if (in_array("models",$tables) && in_array("statements",$tables)
+ && in_array("namespaces",$tables)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ }//function _isSetup_MsAccess()
+
+ /**
+ * Checks if tables are setup for RAP (MSSQL)
+ *
+ * @throws SqlError
+ * @access private
+ **/
+ function _isSetup_MSSQL()
+ {
+ $tables =& $this->dbConn->MetaTables();
+ if (!$tables) {
+ throw new Exception($this->dbConn->errorMsg());
+ }
+ if (count($tables) == 0) {
+ return false;
+ } else {
+ if (in_array("models",$tables) && in_array("statements",$tables)
+ && in_array("namespaces",$tables)){
+ return true;
+ } else {
+ return false;
+ }
+ }
+ }//function _isSetup_MSSQL()
+
+
/**
* Create a new instance of DatasetDb with the given $datasetName
* and insert the DatasetDb variables into the database.
Modified: trunk/rdfapi-php/test/setup.php
===================================================================
--- trunk/rdfapi-php/test/setup.php 2007-10-09 16:24:08 UTC (rev 544)
+++ trunk/rdfapi-php/test/setup.php 2007-10-10 17:41:15 UTC (rev 545)
@@ -13,7 +13,8 @@
require_once RDFAPI_INCLUDE_DIR . '/model/ModelFactory.php';
try {
- DbStore::assertDriverSupported($GLOBALS['dbConf']['type']);
+ $type = DbStore::getDriver($GLOBALS['dbConf']['type']);
+ DbStore::assertDriverSupported($type);
} catch (Exception $e) {
echo "Error: " . $e->getMessage() . "\n";
echo "Be sure to write the driver type in the same cAsE\n";
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|