summaryrefslogtreecommitdiffstats
path: root/system/database/drivers/odbc/odbc_result.php
diff options
context:
space:
mode:
authorEric Roberts <eric@cryode.com>2012-12-12 14:02:11 +0100
committerEric Roberts <eric@cryode.com>2012-12-12 14:02:11 +0100
commitb9e35f21e1c70b6aa67c47e9244ed83195abc00a (patch)
tree64f82db362deeac48cc20d1d1afd80651f36f5a5 /system/database/drivers/odbc/odbc_result.php
parent0b05705c52c3bca7f9b3aee657c888e8ad1ff422 (diff)
parent545a7c86701875e1412bcde316e9bcc76d9a23a0 (diff)
Merge branch 'refs/heads/develop' into feature/form_error_msgs
Conflicts: system/language/english/form_validation_lang.php user_guide_src/source/libraries/form_validation.rst Signed-off-by: Eric Roberts <eric@cryode.com>
Diffstat (limited to 'system/database/drivers/odbc/odbc_result.php')
-rw-r--r--system/database/drivers/odbc/odbc_result.php177
1 files changed, 65 insertions, 112 deletions
diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php
index ecba5977e..2c50c255b 100644
--- a/system/database/drivers/odbc/odbc_result.php
+++ b/system/database/drivers/odbc/odbc_result.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* ODBC Result Class
@@ -33,11 +34,10 @@
* @category Database
* @author EllisLab Dev Team
* @link http://codeigniter.com/user_guide/database/
+ * @since 1.3
*/
class CI_DB_odbc_result extends CI_DB_result {
- public $num_rows;
-
/**
* Number of rows in the result set
*
@@ -49,14 +49,22 @@ class CI_DB_odbc_result extends CI_DB_result {
{
return $this->num_rows;
}
+ elseif (($this->num_rows = @odbc_num_rows($this->result_id)) !== -1)
+ {
+ return $this->num_rows;
+ }
// Work-around for ODBC subdrivers that don't support num_rows()
- if (($this->num_rows = @odbc_num_rows($this->result_id)) === -1)
+ if (count($this->result_array) > 0)
{
- $this->num_rows = count($this->result_array());
+ return $this->num_rows = count($this->result_array);
+ }
+ elseif (count($this->result_object) > 0)
+ {
+ return $this->num_rows = count($this->result_object);
}
- return $this->num_rows;
+ return $this->num_rows = count($this->result_array());
}
// --------------------------------------------------------------------
@@ -148,14 +156,7 @@ class CI_DB_odbc_result extends CI_DB_result {
*/
protected function _fetch_assoc()
{
- if (function_exists('odbc_fetch_array'))
- {
- return odbc_fetch_array($this->result_id);
- }
- else
- {
- return $this->_odbc_fetch_array($this->result_id);
- }
+ return odbc_fetch_array($this->result_id);
}
// --------------------------------------------------------------------
@@ -165,141 +166,93 @@ class CI_DB_odbc_result extends CI_DB_result {
*
* Returns the result set as an object
*
+ * @param string $class_name
* @return object
*/
- protected function _fetch_object()
+ protected function _fetch_object($class_name = 'stdClass')
{
- if (function_exists('odbc_fetch_object'))
- {
- return odbc_fetch_object($this->result_id);
- }
- else
+ $row = odbc_fetch_object($this->result_id);
+
+ if ($class_name === 'stdClass' OR ! $row)
{
- return $this->_odbc_fetch_object($this->result_id);
+ return $row;
}
- }
-
- // --------------------------------------------------------------------
- /**
- * Result - object
- *
- * subsititutes the odbc_fetch_object function when
- * not available (odbc_fetch_object requires unixODBC)
- *
- * @return object
- */
- protected function _odbc_fetch_object(& $odbc_result)
- {
- $rs = array();
- $rs_obj = FALSE;
- if (odbc_fetch_into($odbc_result, $rs))
+ $class_name = new $class_name();
+ foreach ($row as $key => $value)
{
- foreach ($rs as $k => $v)
- {
- $field_name = odbc_field_name($odbc_result, $k+1);
- $rs_obj->$field_name = $v;
- }
+ $class_name->$key = $value;
}
- return $rs_obj;
+
+ return $class_name;
}
- // --------------------------------------------------------------------
+}
+
+// --------------------------------------------------------------------
+if ( ! function_exists('odbc_fetch_array'))
+{
/**
- * Result - array
+ * ODBC Fetch array
*
- * subsititutes the odbc_fetch_array function when
- * not available (odbc_fetch_array requires unixODBC)
+ * Emulates the native odbc_fetch_array() function when
+ * it is not available (odbc_fetch_array() requires unixODBC)
*
+ * @param resource &$result
+ * @param int $rownumber
* @return array
*/
- protected function _odbc_fetch_array(& $odbc_result)
+ function odbc_fetch_array(&$result, $rownumber = 1)
{
$rs = array();
- $rs_assoc = FALSE;
- if (odbc_fetch_into($odbc_result, $rs))
+ if ( ! odbc_fetch_into($result, $rs, $rownumber))
{
- $rs_assoc = array();
- foreach ($rs as $k => $v)
- {
- $field_name = odbc_field_name($odbc_result, $k+1);
- $rs_assoc[$field_name] = $v;
- }
+ return FALSE;
}
- return $rs_assoc;
- }
- // --------------------------------------------------------------------
-
- /**
- * Query result. Array version.
- *
- * @return array
- */
- public function result_array()
- {
- if (count($this->result_array) > 0)
- {
- return $this->result_array;
- }
- elseif (($c = count($this->result_object)) > 0)
- {
- for ($i = 0; $i < $c; $i++)
- {
- $this->result_array[$i] = (array) $this->result_object[$i];
- }
- }
- elseif ($this->result_id === FALSE)
+ $rs_assoc = array();
+ foreach ($rs as $k => $v)
{
- return array();
- }
- else
- {
- while ($row = $this->_fetch_assoc())
- {
- $this->result_array[] = $row;
- }
+ $field_name = odbc_field_name($result, $k+1);
+ $rs_assoc[$field_name] = $v;
}
- return $this->result_array;
+ return $rs_assoc;
}
+}
- // --------------------------------------------------------------------
+// --------------------------------------------------------------------
+if ( ! function_exists('odbc_fetch_object'))
+{
/**
- * Query result. Object version.
+ * ODBC Fetch object
*
- * @return array
+ * Emulates the native odbc_fetch_object() function when
+ * it is not available.
+ *
+ * @param resource &$result
+ * @param int $rownumber
+ * @return object
*/
- public function result_object()
+ function odbc_fetch_object(&$result, $rownumber = 1)
{
- if (count($this->result_object) > 0)
- {
- return $this->result_object;
- }
- elseif (($c = count($this->result_array)) > 0)
- {
- for ($i = 0; $i < $c; $i++)
- {
- $this->result_object[$i] = (object) $this->result_array[$i];
- }
- }
- elseif ($this->result_id === FALSE)
+ $rs = array();
+ if ( ! odbc_fetch_into($result, $rs, $rownumber))
{
- return array();
+ return FALSE;
}
- else
+
+ $rs_object = new stdClass();
+ foreach ($rs as $k => $v)
{
- while ($row = $this->_fetch_object())
- {
- $this->result_object[] = $row;
- }
+ $field_name = odbc_field_name($result, $k+1);
+ $rs_object->$field_name = $v;
}
- return $this->result_object;
+ return $rs_object;
}
-
}
/* End of file odbc_result.php */