1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-06 06:07:39 +02:00

- DibiSQLiteDriver: added ability to convert strings to requested character encoding

- added experimental Microsoft SQL Server 2005 Driver for PHP
This commit is contained in:
David Grudl
2009-01-07 03:34:50 +00:00
parent 348af48ecd
commit 96acdb46dc
2 changed files with 432 additions and 6 deletions

View File

@@ -29,6 +29,8 @@
* - 'lazy' - if TRUE, connection will be established only when required
* - 'formatDate' - how to format date in SQL (@see date)
* - 'formatDateTime' - how to format datetime in SQL (@see date)
* - 'dbcharset' - database character encoding (will be converted to 'charset')
* - 'charset' - character encoding to set (default is UTF-8)
*
* @author David Grudl
* @copyright Copyright (c) 2005, 2009 David Grudl
@@ -36,22 +38,21 @@
*/
class DibiSqliteDriver extends DibiObject implements IDibiDriver
{
/** @var resource Connection resource */
private $connection;
/** @var resource Resultset resource */
private $resultSet;
/** @var bool Is buffered (seekable and countable)? */
private $buffered;
/** @var string Date and datetime format */
private $fmtDate, $fmtDateTime;
/** @var string character encoding */
private $dbcharset, $charset;
/**
@@ -89,6 +90,12 @@ class DibiSqliteDriver extends DibiObject implements IDibiDriver
}
$this->buffered = empty($config['unbuffered']);
$this->dbcharset = empty($config['dbcharset']) ? 'UTF-8' : $config['dbcharset'];
$this->charset = empty($config['charset']) ? 'UTF-8' : $config['charset'];
if (strcasecmp($this->dbcharset, $this->charset) === 0) {
$this->dbcharset = $this->charset = NULL;
}
}
@@ -112,6 +119,10 @@ class DibiSqliteDriver extends DibiObject implements IDibiDriver
*/
public function query($sql)
{
if ($this->dbcharset !== NULL) {
$sql = iconv($this->charset, $this->dbcharset . '//IGNORE', $sql);
}
DibiDriverException::tryError();
if ($this->buffered) {
$this->resultSet = sqlite_query($this->connection, $sql);
@@ -292,9 +303,13 @@ class DibiSqliteDriver extends DibiObject implements IDibiDriver
public function fetch($assoc)
{
$row = sqlite_fetch_array($this->resultSet, $assoc ? SQLITE_ASSOC : SQLITE_NUM);
if ($assoc && $row) {
$charset = $this->charset === NULL ? NULL : $this->charset . '//TRANSLIT';
if ($row && ($assoc || $charset)) {
$tmp = array();
foreach ($row as $k => $v) {
if ($charset !== NULL && is_string($v)) {
$v = iconv($this->dbcharset, $charset, $v);
}
$tmp[str_replace(array('[', ']'), '', $k)] = $v;
}
return $tmp;
@@ -381,7 +396,10 @@ class DibiSqliteDriver extends DibiObject implements IDibiDriver
SELECT name, type = 'view' as view FROM sqlite_temp_master WHERE type IN ('table', 'view')
ORDER BY name
");
$res = sqlite_fetch_all($this->resultSet, SQLITE_ASSOC);
$res = array();
while ($row = $this->fetch(TRUE)) {
$res[] = $row;
}
$this->free();
return $res;
}