diff --git a/dibi/#todo.txt b/dibi/#todo.txt deleted file mode 100644 index 12cc0cb1..00000000 --- a/dibi/#todo.txt +++ /dev/null @@ -1,3 +0,0 @@ -- current PDO & MSSQL drivers are untested alphas! -- make better examples & documentation - diff --git a/dibi/drivers/odbc.php b/dibi/drivers/odbc.php index e26b96e2..404513a4 100644 --- a/dibi/drivers/odbc.php +++ b/dibi/drivers/odbc.php @@ -45,15 +45,15 @@ class DibiOdbcDriver extends DibiDriver if (empty($config['database'])) $config['database'] = ini_get('odbc.default_db'); if (empty($config['username'])) { - throw new DibiException("Username must be specified (driver odbc)"); + throw new DibiException("Username must be specified"); } if (empty($config['password'])) { - throw new DibiException("Password must be specified (driver odbc)"); + throw new DibiException("Password must be specified"); } if (empty($config['database'])) { - throw new DibiException("Database must be specified (driver odbc)"); + throw new DibiException("Database must be specified"); } parent::__construct($config); diff --git a/dibi/drivers/postgre.php b/dibi/drivers/postgre.php index 497eee14..53601ab6 100644 --- a/dibi/drivers/postgre.php +++ b/dibi/drivers/postgre.php @@ -40,7 +40,7 @@ class DibiPostgreDriver extends DibiDriver public function __construct($config) { if (empty($config['string'])) { - throw new DibiException("Connection string must be specified (driver postgre)"); + throw new DibiException("Connection string must be specified"); } if (empty($config['type'])) $config['type'] = NULL; diff --git a/dibi/drivers/sqlite.php b/dibi/drivers/sqlite.php index 4bccadd5..0cd574c6 100644 --- a/dibi/drivers/sqlite.php +++ b/dibi/drivers/sqlite.php @@ -34,7 +34,7 @@ class DibiSqliteDriver extends DibiDriver public function __construct($config) { if (empty($config['database'])) { - throw new DibiException("Database must be specified (driver sqlite)"); + throw new DibiException("Database must be specified"); } if (!isset($config['mode'])) $config['mode'] = 0666; diff --git a/dibi/drivers/mssql.php b/dibi/drivers/untested/mssql.php similarity index 100% rename from dibi/drivers/mssql.php rename to dibi/drivers/untested/mssql.php diff --git a/dibi/drivers/untested/oracle.php b/dibi/drivers/untested/oracle.php new file mode 100644 index 00000000..48a8676c --- /dev/null +++ b/dibi/drivers/untested/oracle.php @@ -0,0 +1,236 @@ + "1", + 'FALSE' => "0", + 'date' => "U", + 'datetime' => "U", + ); + + private $autocommit = TRUE; + + + + /** + * @param array connect configuration + * @throws DibiException + */ + public function __construct($config) + { + if (empty($config['username'])) { + throw new DibiException("Username must be specified"); + } + + if (empty($config['password'])) { + throw new DibiException("Password must be specified"); + } + + if (!isset($config['db'])) $config['db'] = NULL; + if (!isset($config['charset'])) $config['charset'] = NULL; + + parent::__construct($config); + } + + + + protected function connect() + { + if (!extension_loaded('oci8')) { + throw new DibiException("PHP extension 'oci8' is not loaded"); + } + + $config = $this->getConfig(); + $connection = @oci_new_connect($config['username'], $config['password'], $config['db'], $config['charset']); + + if (!$connection) { + $err = oci_error(); + throw new DibiDatabaseException($err['message'], $err['code']); + } + + dibi::notify('connected', $this); + return $connection; + } + + + + protected function doQuery($sql) + { + $connection = $this->getConnection(); + + $statement = oci_parse($connection, $sql); + if ($statement) { + $res = oci_execute($statement, $this->autocommit ? OCI_COMMIT_ON_SUCCESS : OCI_DEFAULT); + if (!$res) { + $err = oci_error($statement); + throw new DibiDatabaseException($err['message'], $err['code'], $sql); + } + } else { + $err = oci_error($connection); + throw new DibiDatabaseException($err['message'], $err['code'], $sql); + } + + // TODO! + return is_resource($res) ? new DibiOracleResult($statement) : TRUE; + } + + + + public function affectedRows() + { + throw new DibiException(__METHOD__ . ' is not implemented'); + } + + + + public function insertId() + { + throw new DibiException(__METHOD__ . ' is not implemented'); + } + + + + public function begin() + { + $this->autocommit = FALSE; + } + + + + public function commit() + { + $connection = $this->getConnection(); + if (!oci_commit($connection)) { + $err = oci_error($connection); + throw new DibiDatabaseException($err['message'], $err['code']); + } + $this->autocommit = TRUE; + dibi::notify('commit', $this); + } + + + + public function rollback() + { + $connection = $this->getConnection(); + if (!oci_rollback($connection)) { + $err = oci_error($connection); + throw new DibiDatabaseException($err['message'], $err['code']); + } + $this->autocommit = TRUE; + dibi::notify('rollback', $this); + } + + + + public function errorInfo() + { + return oci_error($this->getConnection()); + } + + + + public function escape($value, $appendQuotes = TRUE) + { + return $appendQuotes + ? "'" . sqlite_escape_string($value) . "'" + : sqlite_escape_string($value); + } + + + + public function delimite($value) + { + return '[' . str_replace('.', '].[', $value) . ']'; + } + + + + public function getMetaData() + { + throw new DibiException(__METHOD__ . ' is not implemented'); + } + + + + /** + * @see DibiDriver::applyLimit() + */ + public function applyLimit(&$sql, $limit, $offset = 0) + { + if ($limit < 0 && $offset < 1) return; + $sql .= ' LIMIT ' . $limit . ($offset > 0 ? ' OFFSET ' . (int) $offset : ''); + } + +} // class DibiOracleDriver + + + + + + + + + +class DibiOracleResult extends DibiResult +{ + + public function rowCount() + { + return oci_num_rows($this->resource); + } + + + + protected function doFetch() + { + return oci_fetch_assoc($this->resource); + } + + + + public function seek($row) + { + //throw new DibiException(__METHOD__ . ' is not implemented'); + } + + + + protected function free() + { + oci_free_statement($this->resource); + } + + + + /** this is experimental */ + protected function buildMeta() + { + $count = oci_num_fields($this->resource); + $this->meta = $this->convert = array(); + for ($index = 0; $index < $count; $index++) { + $name = oci_field_name($this->resource, $index + 1); + $this->meta[$name] = array('type' => dibi::FIELD_UNKNOWN); + $this->convert[$name] = dibi::FIELD_UNKNOWN; + } + } + + +} // class DibiOracleResult diff --git a/dibi/drivers/pdo.php b/dibi/drivers/untested/pdo.php similarity index 93% rename from dibi/drivers/pdo.php rename to dibi/drivers/untested/pdo.php index 7f03668b..ed5c5b91 100644 --- a/dibi/drivers/pdo.php +++ b/dibi/drivers/untested/pdo.php @@ -34,7 +34,7 @@ class DibiPdoDriver extends DibiDriver public function __construct($config) { if (empty($config['dsn'])) { - throw new DibiException("DSN must be specified (driver odbc)"); + throw new DibiException("DSN must be specified"); } if (empty($config['username'])) $config['username'] = NULL;