Permalink
Browse files

Fix some little issues. See http://pear.php.net/bugs/bug.php?id=19517

…for more details.
  • Loading branch information...
1 parent 26a78cd commit 7f3f89477823963b4423deab80bbc4e013c9dd20 @raziel057 raziel057 committed Jul 20, 2012
Showing with 27 additions and 15 deletions.
  1. +27 −15 MDB2/Driver/sqlsrv.php
View
@@ -160,6 +160,7 @@ function errorInfo($error = null, $connection = null)
2627 => MDB2_ERROR_CONSTRAINT,
2714 => MDB2_ERROR_ALREADY_EXISTS,
3607 => MDB2_ERROR_DIVZERO,
+ 3621 => MDB2_ERROR_CONSTRAINT,
3701 => MDB2_ERROR_NOSUCHTABLE,
7630 => MDB2_ERROR_SYNTAX,
8134 => MDB2_ERROR_DIVZERO,
@@ -334,6 +335,9 @@ function _doConnect($username, $password, $database=null, $persistent = false)
if ($this->dsn['port'] && $this->dsn['port'] != 1433) {
$host .= ','.$this->dsn['port'];
}
+ if (!empty($this->dsn['charset'])) {
+ $params['CharacterSet'] = $this->dsn['charset'];
+ }
$connection = @sqlsrv_connect($host, $params);
if (!$connection) {
@@ -344,13 +348,6 @@ function _doConnect($username, $password, $database=null, $persistent = false)
$this->connected_database_name = $database;
}
- if (!empty($this->dsn['charset'])) {
- $result = $this->setCharset($this->dsn['charset'], $connection);
- if (PEAR::isError($result)) {
- return $result;
- }
- }
-
if (empty($this->dsn['disable_iso_date'])) {
@sqlsrv_query($connection,'SET DATEFORMAT ymd');
}
@@ -784,11 +781,18 @@ function __construct($db, $result, $limit = 0, $offset = 0)
$this->offset_count++;
continue;
}
+ $i = 0;
foreach ($row as $k => $v) {
if (is_object($v) && method_exists($v, 'format')) {
- //DateTime Object
- $row[$k] = $v->format('Y-m-d H:i:s');
+ if ($this->fieldMeta[$i]['Type'] === 91) {
+ //DateTime Object to be transformed to date string
+ $row[$k] = $v->format('Y-m-d');
+ } else {
+ //DateTime Object to be transformed to datetime string
+ $row[$k] = $v->format('Y-m-d H:i:s');
+ }
}
+ ++$i;
}
$this->rows[] = $row; //read results into memory, cursors are not supported
}
@@ -874,15 +878,12 @@ function fetchRow($fetchmode = MDB2_FETCHMODE_DEFAULT, $rownum = null)
}
switch($fetchmode) {
case MDB2_FETCHMODE_ASSOC:
+ case MDB2_FETCHMODE_OBJECT:
$row = $this->rows[$this->cursor];
break;
case MDB2_FETCHMODE_ORDERED:
$row = $arrNum;
break;
- case MDB2_FETCHMODE_OBJECT:
- $o = new $this->db->options['fetch_class'];
- $row = $this->array_to_obj($this->rows[$this->cursor], $o);
- break;
}
$this->cursor++;
@@ -945,6 +946,10 @@ function fetchRow($fetchmode = MDB2_FETCHMODE_DEFAULT, $rownum = null)
if (!empty($this->values)) {
$this->_assignBindColumns($row);
}
+ if ($fetchmode == MDB2_FETCHMODE_OBJECT) {
+ $o = new $this->db->options['fetch_class'];
+ $row = $this->array_to_obj($row, $o);
+ }
++$this->rownum;
return $row;
}
@@ -1037,11 +1042,18 @@ function nextResult()
$this->offset_count++;
continue;
}
+ $i = 0;
foreach ($row as $k => $v) {
if (is_object($v) && method_exists($v, 'format')) {//DateTime Object
- //$v->setTimezone(new DateTimeZone('GMT'));//TS_ISO_8601 with a trailing 'Z' is GMT
- $row[$k] = $v->format("Y-m-d H:i:s");
+ if ($this->fieldMeta[$i]['Type'] === 91) {
+ //DateTime Object to be transformed to date string
+ $row[$k] = $v->format('Y-m-d');
+ } else {
+ //DateTime Object to be transformed to datetime string
+ $row[$k] = $v->format('Y-m-d H:i:s');
+ }
}
+ ++$i;
}
$this->rows[] = $row;//read results into memory, cursors are not supported
}

0 comments on commit 7f3f894

Please sign in to comment.