summaryrefslogtreecommitdiffstats
path: root/system/database
diff options
context:
space:
mode:
Diffstat (limited to 'system/database')
-rw-r--r--system/database/DB_forge.php6
-rw-r--r--system/database/DB_result.php85
-rw-r--r--system/database/drivers/mysql/mysql_forge.php23
3 files changed, 99 insertions, 15 deletions
diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php
index e6a64f3b8..27f2c372d 100644
--- a/system/database/DB_forge.php
+++ b/system/database/DB_forge.php
@@ -333,6 +333,12 @@ class CI_DB_forge {
foreach ($field as $k => $v)
{
+ // If no name provided, use the current name
+ if ( ! isset($field[$k]['name']))
+ {
+ $field[$k]['name'] = $k;
+ }
+
$this->add_field(array($k => $field[$k]));
if (count($this->fields) == 0)
diff --git a/system/database/DB_result.php b/system/database/DB_result.php
index fb791cf30..fb4268c21 100644
--- a/system/database/DB_result.php
+++ b/system/database/DB_result.php
@@ -28,13 +28,14 @@
*/
class CI_DB_result {
- var $conn_id = NULL;
- var $result_id = NULL;
- var $result_array = array();
- var $result_object = array();
- var $current_row = 0;
- var $num_rows = 0;
- var $row_data = NULL;
+ var $conn_id = NULL;
+ var $result_id = NULL;
+ var $result_array = array();
+ var $result_object = array();
+ var $custom_result_object = array();
+ var $current_row = 0;
+ var $num_rows = 0;
+ var $row_data = NULL;
/**
@@ -46,11 +47,48 @@ class CI_DB_result {
*/
function result($type = 'object')
{
- return ($type == 'object') ? $this->result_object() : $this->result_array();
+ if ($type == 'array') return $this->result_array();
+ else if ($type == 'object') return $this->result_object();
+ else return $this->custom_result_object($type);
}
// --------------------------------------------------------------------
+ /**
+ * Custom query result.
+ *
+ * @param class_name A string that represents the type of object you want back
+ * @return array of objects
+ */
+ function custom_result_object($class_name)
+ {
+ if (array_key_exists($class_name, $this->custom_result_object))
+ {
+ return $this->custom_result_object[$class_name];
+ }
+
+ if ($this->result_id === FALSE OR $this->num_rows() == 0)
+ {
+ return array();
+ }
+
+ // add the data to the object
+ $this->_data_seek(0);
+ $result_object = array();
+ while ($row = $this->_fetch_object())
+ {
+ $object = new $class_name();
+ foreach($row as $key => $value)
+ {
+ $object->$key = $value;
+ }
+ $result_object[] = $object;
+ }
+
+ // return the array
+ return $this->custom_result_object[$class_name] = $result_object;
+ }
+
/**
* Query result. "object" version.
*
@@ -142,7 +180,9 @@ class CI_DB_result {
$n = 0;
}
- return ($type == 'object') ? $this->row_object($n) : $this->row_array($n);
+ if ($type == 'object') return $this->row_object($n);
+ else if ($type == 'array') return $this->row_array($n);
+ else return $this->custom_row_object($n, $type);
}
// --------------------------------------------------------------------
@@ -179,7 +219,30 @@ class CI_DB_result {
// --------------------------------------------------------------------
- /**
+ /**
+ * Returns a single result row - custom object version
+ *
+ * @access public
+ * @return object
+ */
+ function custom_row_object($n, $type)
+ {
+ $result = $this->custom_result_object($type);
+
+ if (count($result) == 0)
+ {
+ return $result;
+ }
+
+ if ($n != $this->current_row AND isset($result[$n]))
+ {
+ $this->current_row = $n;
+ }
+
+ return $result[$this->current_row];
+ }
+
+ /**
* Returns a single result row - object version
*
* @access public
@@ -339,4 +402,4 @@ class CI_DB_result {
// END DB_result class
/* End of file DB_result.php */
-/* Location: ./system/database/DB_result.php */ \ No newline at end of file
+/* Location: ./system/database/DB_result.php */
diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php
index c02b8cb3a..529ec980d 100644
--- a/system/database/drivers/mysql/mysql_forge.php
+++ b/system/database/drivers/mysql/mysql_forge.php
@@ -87,11 +87,26 @@ class CI_DB_mysql_forge extends CI_DB_forge {
if (array_key_exists('TYPE', $attributes))
{
$sql .= ' '.$attributes['TYPE'];
- }
- if (array_key_exists('CONSTRAINT', $attributes))
- {
- $sql .= '('.$attributes['CONSTRAINT'].')';
+ if (array_key_exists('CONSTRAINT', $attributes))
+ {
+ switch ($attributes['TYPE'])
+ {
+ case 'decimal':
+ case 'float':
+ case 'numeric':
+ $sql .= '('.implode(',', $attributes['CONSTRAINT']).')';
+ break;
+
+ case 'enum':
+ case 'set':
+ $sql .= '("'.implode('","', $attributes['CONSTRAINT']).'")';
+ break;
+
+ default:
+ $sql .= '('.$attributes['CONSTRAINT'].')';
+ }
+ }
}
if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE)