summaryrefslogtreecommitdiffstats
path: root/system/database/drivers/sqlite3
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2012-07-06 10:57:37 +0200
committerAndrey Andreev <narf@bofh.bg>2012-07-06 10:57:37 +0200
commit9a4f356846daa078c077cbadb227524c857b8f97 (patch)
treebb6b3ee33c3056438149a252a593cae9eed92390 /system/database/drivers/sqlite3
parent9e3a83a65668cc26b685f0b35a4428809435f7c9 (diff)
_fetch_object(), custom_result_object() to utilize PHP's native capability to directly return custom class results
Diffstat (limited to 'system/database/drivers/sqlite3')
-rw-r--r--system/database/drivers/sqlite3/sqlite3_result.php29
1 files changed, 22 insertions, 7 deletions
diff --git a/system/database/drivers/sqlite3/sqlite3_result.php b/system/database/drivers/sqlite3/sqlite3_result.php
index 4d59bb08a..8e9b9c15f 100644
--- a/system/database/drivers/sqlite3/sqlite3_result.php
+++ b/system/database/drivers/sqlite3/sqlite3_result.php
@@ -26,13 +26,13 @@
*/
/**
- * SQLite Result Class
+ * SQLite3 Result Class
*
* This class extends the parent result class: CI_DB_result
*
* @category Database
- * @author Andrey Andreev
- * @link http://codeigniter.com/user_guide/database/
+ * @author Andrey Andreev
+ * @link http://codeigniter.com/user_guide/database/
* @since 3.0
*/
class CI_DB_sqlite3_result extends CI_DB_result {
@@ -134,13 +134,28 @@ class CI_DB_sqlite3_result extends CI_DB_result {
*
* Returns the result set as an object
*
+ * @param string
* @return object
*/
- protected function _fetch_object()
+ protected function _fetch_object($class_name = 'stdClass')
{
- // No native support for fetching as an object
- $row = $this->_fetch_assoc();
- return ($row !== FALSE) ? (object) $row : FALSE;
+ // No native support for fetching rows as objects
+ if (($row = $this->result_id->fetchArray(SQLITE3_ASSOC)) === FALSE)
+ {
+ return FALSE;
+ }
+ elseif ($class_name === 'stdClass')
+ {
+ return (object) $row;
+ }
+
+ $class_name = new $class_name();
+ foreach (array_keys($row) as $key)
+ {
+ $class_name->$key = $row[$key];
+ }
+
+ return $class_name;
}
// --------------------------------------------------------------------