Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

MYSQL #1027

Closed
wants to merge 7 commits into from

3 participants

@andreustimm

Include method _list_index AND modified _list_collumns MYSQL, for more collumns.

Thanks!

@philsturgeon

Hey awesome!

Any new method needs to have documentation attached, and you'll need to add something for other drivers even if it's return FALSE; as they'll fatal error on missing methods at the moment.

@andreustimm

Hi, Phil!
Thank's for see my code, i'll add in documentation and new method drivers.

system/database/drivers/mysql/mysql_driver.php
((6 lines not shown))
}
// --------------------------------------------------------------------
/**
+ * Show index column query
+ *
+ * Generates a platform-specific query string so that the index names can be fetched
+ *
+ * @param string the table name
+ * @return string
+ */
+ public function _list_index($table = '')
@narfbg Owner
narfbg added a note

Should be protected here.

This method I let the public, because the other method was also "_list_columns".
Do you think I should change for the two protected (_list_columns, _list_index) ?

@narfbg Owner
narfbg added a note

Um ... _list_columns() should be protected as well - that's probably my mistake. Change it please. :)
The general rule is that if it's a method that is not intended to be called from outside the database driver classes - it should be protected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@narfbg
Owner

If this is added in the base DB_driver class ... there should be a _list_index() method in all of the drivers. Otherwise it will trigger a fatal error if it's not used with mysql, mysqli or pdo.

@andreustimm

All right, I'll fix this!

@andreustimm

I implemented the support for all drivers and fix other thing's.

@andreustimm andreustimm referenced this pull request
Closed

Fix 1027 #1082

system/database/drivers/cubrid/cubrid_result.php
@@ -145,6 +145,32 @@ function field_data()
// --------------------------------------------------------------------
/**
+ * Index data
+ *
+ * Generates an array of objects containing index meta-data
+ *
+ * @return array
+ */
+ public function index_data()
+ {
+ $retval = array();
+ while ($field = cubrid_fetch_field($this->result_id))
@narfbg Owner
narfbg added a note

Needs another tab here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
system/database/drivers/mssql/mssql_result.php
@@ -114,6 +114,24 @@ function field_data()
// --------------------------------------------------------------------
/**
+ * Index data
+ *
+ * Generates an array of objects containing index meta-data
+ *
+ * @return array
+ */
+ public function index_data()
+ {
+ if ($this->db->db_debug)
@narfbg Owner
narfbg added a note

... and here + next 3 lines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
system/database/drivers/oci8/oci8_result.php
@@ -138,6 +138,24 @@ public function field_data()
// --------------------------------------------------------------------
/**
+ * Index data
+ *
+ * Generates an array of objects containing index meta-data
+ *
+ * @return array
+ */
+ public function index_data()
+ {
+ if ($this->db->db_debug)
@narfbg Owner
narfbg added a note

Tabs here as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
system/database/drivers/odbc/odbc_result.php
@@ -114,6 +114,24 @@ function field_data()
// --------------------------------------------------------------------
/**
+ * Index data
+ *
+ * Generates an array of objects containing index meta-data
+ *
+ * @return array
+ */
+ public function index_data()
+ {
+ if ($this->db->db_debug)
@narfbg Owner
narfbg added a note

Tabs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
system/database/drivers/pdo/pdo_result.php
@@ -181,6 +181,24 @@ function field_data()
// --------------------------------------------------------------------
/**
+ * Index data
+ *
+ * Generates an array of objects containing index meta-data
+ *
+ * @return array
+ */
+ public function index_data()
+ {
+ if ($this->db->db_debug)
@narfbg Owner
narfbg added a note

Tabs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
system/database/drivers/postgre/postgre_result.php
@@ -114,6 +114,24 @@ function field_data()
// --------------------------------------------------------------------
/**
+ * Index data
+ *
+ * Generates an array of objects containing index meta-data
+ *
+ * @return array
+ */
+ public function index_data()
+ {
+ if ($this->db->db_debug)
@narfbg Owner
narfbg added a note

Tabs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
system/database/drivers/sqlite/sqlite_result.php
@@ -114,6 +114,24 @@ function field_data()
// --------------------------------------------------------------------
/**
+ * Index data
+ *
+ * Generates an array of objects containing index meta-data
+ *
+ * @return array
+ */
+ public function index_data()
+ {
+ if ($this->db->db_debug)
@narfbg Owner
narfbg added a note

Tabs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
system/database/drivers/sqlsrv/sqlsrv_result.php
@@ -114,6 +114,24 @@ function field_data()
// --------------------------------------------------------------------
/**
+ * Index data
+ *
+ * Generates an array of objects containing index meta-data
+ *
+ * @return array
+ */
+ public function index_data()
+ {
+ if ($this->db->db_debug)
@narfbg Owner
narfbg added a note

Tabs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@andreustimm

Ok I fix this. ;)

@andreustimm

Do you're using PHP CodeSniffer, for validation?

@narfbg
Owner

No, I'm just looking at your code. OK, so far so good, but ... it really bugs me that you need to have a method both in the driver AND the result class. The latter should only have methods related to (almost) all result sets, not such a generic feature. Here's a prototype of how I think it should be done:

  • DB_driver.php:

    public function index_data($table = '')
    {
        if ( ! method_exists($this, '_index_data'))
        {
            return ($this->db_debug) ? $this->display_error('db_unsupported_feature') : FALSE;
        }
        elseif ($table == '' OR ($sql = $this->_index_data($table)) === FALSE)
        {
            return ($this->db_debug) ? $this->display_error('db_table_name_required') : FALSE;
        }
    
        $result = $this->query($sql);
        $result = $result->result();
        for ($i = 0, $c = count($query); $i < $c; $i++)
        {
            $index_data[$i]         = new stdClass();
            $index_data[$i]->INDEX_NAME = $result[$i]->KEY_NAME;
            $index_data[$i]->COLUMN_NAME    = $result[$i]->COLUMN_NAME;
            $index_data[$i]->INDEX_TYPE = $result[$i]->INDEX_TYPE;
        }
    
        return $index_data;
    }
    
  • mysql_driver.php:

    protected function _index_data($table)
    {
        return 'SHOW INDEX FROM '.$this->_protect_identifiers($table, TRUE, NULL, FALSE);
    }
    

... and we can simply not add the _index_data() method to drivers that don't support it.

Also, the documentation is incorrect - you're implementing index_data() but documenting list_index().

And another thing - do we need that comment field listed? Not all databases will support it and I doubt that many people would find it useful.

@narfbg narfbg closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 10, 2012
  1. @andreustimm
Commits on Feb 14, 2012
  1. Suport the cubrid and protected method

    = authored
Commits on Feb 20, 2012
  1. Implemented list_index in active record

    = authored
Commits on Feb 27, 2012
  1. @andreustimm

    Change spaces por tabs

    andreustimm authored
  2. @andreustimm

    Change spaces por tabs

    andreustimm authored
  3. @andreustimm

    Change spaces por tabs

    andreustimm authored
This page is out of date. Refresh to see the latest.
Showing with 460 additions and 38 deletions.
  1. +24 −0 system/database/DB_driver.php
  2. +1 −0  system/database/DB_result.php
  3. +18 −2 system/database/drivers/cubrid/cubrid_driver.php
  4. +27 −1 system/database/drivers/cubrid/cubrid_result.php
  5. +17 −1 system/database/drivers/mssql/mssql_driver.php
  6. +19 −1 system/database/drivers/mssql/mssql_result.php
  7. +33 −3 system/database/drivers/mysql/mysql_driver.php
  8. +31 −4 system/database/drivers/mysql/mysql_result.php
  9. +17 −2 system/database/drivers/mysqli/mysqli_driver.php
  10. +31 −4 system/database/drivers/mysqli/mysqli_result.php
  11. +15 −0 system/database/drivers/oci8/oci8_driver.php
  12. +20 −2 system/database/drivers/oci8/oci8_result.php
  13. +18 −3 system/database/drivers/odbc/odbc_driver.php
  14. +19 −1 system/database/drivers/odbc/odbc_result.php
  15. +16 −1 system/database/drivers/pdo/pdo_driver.php
  16. +19 −1 system/database/drivers/pdo/pdo_result.php
  17. +18 −3 system/database/drivers/postgre/postgre_driver.php
  18. +19 −1 system/database/drivers/postgre/postgre_result.php
  19. +19 −3 system/database/drivers/sqlite/sqlite_driver.php
  20. +19 −1 system/database/drivers/sqlite/sqlite_result.php
  21. +18 −3 system/database/drivers/sqlsrv/sqlsrv_driver.php
  22. +19 −1 system/database/drivers/sqlsrv/sqlsrv_result.php
  23. +23 −0 user_guide_src/source/database/indexes.rst
View
24 system/database/DB_driver.php
@@ -941,6 +941,30 @@ function field_data($table = '')
// --------------------------------------------------------------------
/**
+ * Returns an object with index data
+ *
+ * @access public
+ * @param string the table name
+ * @return object
+ */
+ function index_data($table = '')
+ {
+ if ($table == '')
+ {
+ if ($this->db_debug)
+ {
+ return $this->display_error('db_field_param_missing');
+ }
+ return FALSE;
+ }
+
+ $query = $this->query($this->_list_index($this->_protect_identifiers($table, TRUE, NULL, FALSE)));
+
+ return $query->index_data();
+ }
+
+ // --------------------------------------------------------------------
+ /**
* Generate an insert string
*
* @access public
View
1  system/database/DB_result.php
@@ -378,6 +378,7 @@ public function num_rows() { return $this->num_rows; }
public function num_fields() { return 0; }
public function list_fields() { return array(); }
public function field_data() { return array(); }
+ public function index_data() { return array(); }
public function free_result() { return TRUE; }
protected function _data_seek() { return TRUE; }
protected function _fetch_assoc() { return array(); }
View
20 system/database/drivers/cubrid/cubrid_driver.php
@@ -450,7 +450,23 @@ function _list_tables($prefix_limit = FALSE)
*/
function _list_columns($table = '')
{
- return "SHOW COLUMNS FROM ".$this->_protect_identifiers($table, TRUE, NULL, FALSE);
+ return "SHOW FULL COLUMNS FROM ".$this->_protect_identifiers($table, TRUE, NULL, FALSE);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Show index column query
+ *
+ * Generates a platform-specific query string so that the index names can be fetched
+ *
+ * @access public
+ * @param string the table name
+ * @return string
+ */
+ function _list_index($table = '')
+ {
+ return "SHOW INDEX FROM ".$this->_protect_identifiers($table, TRUE, NULL, FALSE);
}
// --------------------------------------------------------------------
@@ -801,4 +817,4 @@ function _close($conn_id)
/* End of file cubrid_driver.php */
-/* Location: ./system/database/drivers/cubrid/cubrid_driver.php */
+/* Location: ./system/database/drivers/cubrid/cubrid_driver.php */
View
28 system/database/drivers/cubrid/cubrid_result.php
@@ -145,6 +145,32 @@ function field_data()
// --------------------------------------------------------------------
/**
+ * Index data
+ *
+ * Generates an array of objects containing index meta-data
+ *
+ * @return array
+ */
+ public function index_data()
+ {
+ $retval = array();
+ while ($field = cubrid_fetch_field($this->result_id))
+ {
+ $F = new stdClass();
+ $F->name = $field->Key_name;
+ $F->column = $field->Column_name;
+ $F->type = $field->Index_type;
+ $F->comment = '';
+
+ $retval[] = $F;
+ }
+
+ return $retval;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Free the result
*
* @return null
@@ -211,4 +237,4 @@ function _fetch_object()
/* End of file cubrid_result.php */
-/* Location: ./system/database/drivers/cubrid/cubrid_result.php */
+/* Location: ./system/database/drivers/cubrid/cubrid_result.php */
View
18 system/database/drivers/mssql/mssql_driver.php
@@ -427,6 +427,22 @@ function _list_columns($table = '')
// --------------------------------------------------------------------
/**
+ * Show index column query
+ *
+ * Generates a platform-specific query string so that the index names can be fetched
+ *
+ * @param string the table name
+ * @return string
+ */
+ protected function _list_index($table = '')
+ {
+ return FALSE;
+ //return "SELECT * FROM INFORMATION_SCHEMA.INDEXES WHERE TABLE_NAME = '".$table."'";//TODO - To Test
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Field data query
*
* Generates a platform-specific query so that the column data can be retrieved
@@ -676,4 +692,4 @@ function _close($conn_id)
/* End of file mssql_driver.php */
-/* Location: ./system/database/drivers/mssql/mssql_driver.php */
+/* Location: ./system/database/drivers/mssql/mssql_driver.php */
View
20 system/database/drivers/mssql/mssql_result.php
@@ -114,6 +114,24 @@ function field_data()
// --------------------------------------------------------------------
/**
+ * Index data
+ *
+ * Generates an array of objects containing index meta-data
+ *
+ * @return array
+ */
+ public function index_data()
+ {
+ if ($this->db->db_debug)
+ {
+ return $this->db->display_error('db_unsuported_feature');
+ }
+ return FALSE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Free the result
*
* @return null
@@ -178,4 +196,4 @@ function _fetch_object()
/* End of file mssql_result.php */
-/* Location: ./system/database/drivers/mssql/mssql_result.php */
+/* Location: ./system/database/drivers/mssql/mssql_result.php */
View
36 system/database/drivers/mysql/mysql_driver.php
@@ -382,9 +382,24 @@ protected function _list_tables($prefix_limit = FALSE)
* @param string the table name
* @return string
*/
- public function _list_columns($table = '')
+ protected function _list_columns($table = '')
{
- return 'SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE);
+ return 'SHOW FULL COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Show index column query
+ *
+ * Generates a platform-specific query string so that the index names can be fetched
+ *
+ * @param string the table name
+ * @return string
+ */
+ protected function _list_index($table = '')
+ {
+ return 'SHOW INDEX FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE);
}
// --------------------------------------------------------------------
@@ -399,7 +414,22 @@ public function _list_columns($table = '')
*/
public function _field_data($table)
{
- return 'DESCRIBE '.$table;
+ return $this->_list_columns($table);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Field data query
+ *
+ * Generates a platform-specific query so that the index data can be retrieved
+ *
+ * @param string the table name
+ * @return string
+ */
+ public function _index_data($table)
+ {
+ return $this->_list_index($table);
}
// --------------------------------------------------------------------
View
35 system/database/drivers/mysql/mysql_result.php
@@ -94,12 +94,13 @@ public function field_data()
{
preg_match('/([a-zA-Z]+)(\(\d+\))?/', $field->Type, $matches);
- $F = new stdClass();
- $F->name = $field->Field;
- $F->type = ( ! empty($matches[1])) ? $matches[1] : NULL;
- $F->default = $field->Default;
+ $F = new stdClass();
+ $F->name = $field->Field;
+ $F->type = ( ! empty($matches[1])) ? $matches[1] : NULL;
+ $F->default = $field->Default;
$F->max_length = ( ! empty($matches[2])) ? preg_replace('/[^\d]/', '', $matches[2]) : NULL;
$F->primary_key = (int) ($field->Key === 'PRI');
+ $F->comment = $field->Comment;
$retval[] = $F;
}
@@ -110,6 +111,32 @@ public function field_data()
// --------------------------------------------------------------------
/**
+ * Field data
+ *
+ * Generates an array of objects containing field meta-data
+ *
+ * @return array
+ */
+ public function index_data()
+ {
+ $retval = array();
+ while ($field = mysql_fetch_object($this->result_id))
+ {
+ $F = new stdClass();
+ $F->name = $field->Key_name;
+ $F->column = $field->Column_name;
+ $F->type = $field->Index_type;
+ $F->comment = $field->Comment;
+
+ $retval[] = $F;
+ }
+
+ return $retval;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Free the result
*
* @return void
View
19 system/database/drivers/mysqli/mysqli_driver.php
@@ -385,7 +385,22 @@ protected function _list_tables($prefix_limit = FALSE)
*/
protected function _list_columns($table = '')
{
- return 'SHOW COLUMNS FROM '.$this->_protect_identifiers($table, TRUE, NULL, FALSE);
+ return 'SHOW FULL COLUMNS FROM '.$this->_protect_identifiers($table, TRUE, NULL, FALSE);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Show index column query
+ *
+ * Generates a platform-specific query string so that the index names can be fetched
+ *
+ * @param string the table name
+ * @return string
+ */
+ protected function _list_index($table = '')
+ {
+ return 'SHOW INDEX FROM '.$this->_protect_identifiers($table, TRUE, NULL, FALSE);
}
// --------------------------------------------------------------------
@@ -400,7 +415,7 @@ protected function _list_columns($table = '')
*/
protected function _field_data($table)
{
- return 'DESCRIBE '.$table;
+ return $this->_list_columns($table);
}
// --------------------------------------------------------------------
View
35 system/database/drivers/mysqli/mysqli_result.php
@@ -94,12 +94,39 @@ public function field_data()
{
preg_match('/([a-zA-Z]+)(\(\d+\))?/', $field->Type, $matches);
- $F = new stdClass();
- $F->name = $field->Field;
- $F->type = ( ! empty($matches[1])) ? $matches[1] : NULL;
- $F->default = $field->Default;
+ $F = new stdClass();
+ $F->name = $field->Field;
+ $F->type = ( ! empty($matches[1])) ? $matches[1] : NULL;
+ $F->default = $field->Default;
$F->max_length = ( ! empty($matches[2])) ? preg_replace('/[^\d]/', '', $matches[2]) : NULL;
$F->primary_key = (int) ($field->Key === 'PRI');
+ $F->comment = $field->Comment;
+
+ $retval[] = $F;
+ }
+
+ return $retval;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Index data
+ *
+ * Generates an array of objects containing index meta-data
+ *
+ * @return array
+ */
+ public function index_data()
+ {
+ $retval = array();
+ while ($field = mysqli_fetch_object($this->result_id))
+ {
+ $F = new stdClass();
+ $F->name = $field->Key_name;
+ $F->column = $field->Column_name;
+ $F->type = $field->Index_type;
+ $F->comment = $field->Comment;
$retval[] = $F;
}
View
15 system/database/drivers/oci8/oci8_driver.php
@@ -529,6 +529,21 @@ protected function _list_columns($table = '')
// --------------------------------------------------------------------
/**
+ * Show index column query
+ *
+ * Generates a platform-specific query string so that the index names can be fetched
+ *
+ * @param string the table name
+ * @return string
+ */
+ protected function _list_index($table = '')
+ {
+ return FALSE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Field data query
*
* Generates a platform-specific query so that the column data can be retrieved
View
22 system/database/drivers/oci8/oci8_result.php
@@ -124,10 +124,10 @@ public function field_data()
$retval = array();
for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++)
{
- $F = new stdClass();
+ $F = new stdClass();
$F->name = oci_field_name($this->stmt_id, $c);
$F->type = oci_field_type($this->stmt_id, $c);
- $F->max_length = oci_field_size($this->stmt_id, $c);
+ $F->max_length = oci_field_size($this->stmt_id, $c);
$retval[] = $F;
}
@@ -138,6 +138,24 @@ public function field_data()
// --------------------------------------------------------------------
/**
+ * Index data
+ *
+ * Generates an array of objects containing index meta-data
+ *
+ * @return array
+ */
+ public function index_data()
+ {
+ if ($this->db->db_debug)
+ {
+ return $this->db->display_error('db_unsuported_feature');
+ }
+ return FALSE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Free the result
*
* @return null
View
21 system/database/drivers/odbc/odbc_driver.php
@@ -390,7 +390,7 @@ function _list_tables($prefix_limit = FALSE)
* @param string the table name
* @return string
*/
- function _list_columns($table = '')
+ protected function _list_columns($table = '')
{
return "SHOW COLUMNS FROM ".$table;
}
@@ -398,6 +398,21 @@ function _list_columns($table = '')
// --------------------------------------------------------------------
/**
+ * Show index column query
+ *
+ * Generates a platform-specific query string so that the index names can be fetched
+ *
+ * @param string the table name
+ * @return string
+ */
+ protected function _list_index($table = '')
+ {
+ return FALSE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Field data query
*
* Generates a platform-specific query so that the column data can be retrieved
@@ -406,7 +421,7 @@ function _list_columns($table = '')
* @param string the table name
* @return object
*/
- function _field_data($table)
+ protected function _field_data($table)
{
return "SELECT TOP 1 FROM ".$table;
}
@@ -646,4 +661,4 @@ function _close($conn_id)
/* End of file odbc_driver.php */
-/* Location: ./system/database/drivers/odbc/odbc_driver.php */
+/* Location: ./system/database/drivers/odbc/odbc_driver.php */
View
20 system/database/drivers/odbc/odbc_result.php
@@ -114,6 +114,24 @@ function field_data()
// --------------------------------------------------------------------
/**
+ * Index data
+ *
+ * Generates an array of objects containing index meta-data
+ *
+ * @return array
+ */
+ public function index_data()
+ {
+ if ($this->db->db_debug)
+ {
+ return $this->db->display_error('db_unsuported_feature');
+ }
+ return FALSE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Free the result
*
* @return null
@@ -237,4 +255,4 @@ function _odbc_fetch_array(& $odbc_result) {
/* End of file odbc_result.php */
-/* Location: ./system/database/drivers/odbc/odbc_result.php */
+/* Location: ./system/database/drivers/odbc/odbc_result.php */
View
17 system/database/drivers/pdo/pdo_driver.php
@@ -623,6 +623,21 @@ function _list_columns($table = '')
// --------------------------------------------------------------------
/**
+ * Show index column query
+ *
+ * Generates a platform-specific query string so that the index names can be fetched
+ *
+ * @access public
+ * @param string the table name
+ * @return string
+ */
+ function _list_index($table = '')
+ {
+ return "SHOW INDEX FROM ".$table;
+ }
+ // --------------------------------------------------------------------
+
+ /**
* Field data query
*
* Generates a platform-specific query so that the column data can be retrieved
@@ -950,4 +965,4 @@ function _close($conn_id)
}
/* End of file pdo_driver.php */
-/* Location: ./system/database/drivers/pdo/pdo_driver.php */
+/* Location: ./system/database/drivers/pdo/pdo_driver.php */
View
20 system/database/drivers/pdo/pdo_result.php
@@ -181,6 +181,24 @@ function field_data()
// --------------------------------------------------------------------
/**
+ * Index data
+ *
+ * Generates an array of objects containing index meta-data
+ *
+ * @return array
+ */
+ public function index_data()
+ {
+ if ($this->db->db_debug)
+ {
+ return $this->db->display_error('db_unsuported_feature');
+ }
+ return FALSE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Free the result
*
* @return null
@@ -243,4 +261,4 @@ function _fetch_object()
}
/* End of file pdo_result.php */
-/* Location: ./system/database/drivers/pdo/pdo_result.php */
+/* Location: ./system/database/drivers/pdo/pdo_result.php */
View
21 system/database/drivers/postgre/postgre_driver.php
@@ -435,7 +435,7 @@ function _list_tables($prefix_limit = FALSE)
* @param string the table name
* @return string
*/
- function _list_columns($table = '')
+ protected function _list_columns($table = '')
{
return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$table."'";
}
@@ -443,6 +443,21 @@ function _list_columns($table = '')
// --------------------------------------------------------------------
/**
+ * Show index column query
+ *
+ * Generates a platform-specific query string so that the index names can be fetched
+ *
+ * @param string the table name
+ * @return string
+ */
+ protected function _list_index($table = '')
+ {
+ return FALSE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Field data query
*
* Generates a platform-specific query so that the column data can be retrieved
@@ -451,7 +466,7 @@ function _list_columns($table = '')
* @param string the table name
* @return object
*/
- function _field_data($table)
+ protected function _field_data($table)
{
return "SELECT * FROM ".$table." LIMIT 1";
}
@@ -712,4 +727,4 @@ function _close($conn_id)
/* End of file postgre_driver.php */
-/* Location: ./system/database/drivers/postgre/postgre_driver.php */
+/* Location: ./system/database/drivers/postgre/postgre_driver.php */
View
20 system/database/drivers/postgre/postgre_result.php
@@ -114,6 +114,24 @@ function field_data()
// --------------------------------------------------------------------
/**
+ * Index data
+ *
+ * Generates an array of objects containing index meta-data
+ *
+ * @return array
+ */
+ public function index_data()
+ {
+ if ($this->db->db_debug)
+ {
+ return $this->db->display_error('db_unsuported_feature');
+ }
+ return FALSE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Free the result
*
* @return null
@@ -178,4 +196,4 @@ function _fetch_object()
/* End of file postgre_result.php */
-/* Location: ./system/database/drivers/postgre/postgre_result.php */
+/* Location: ./system/database/drivers/postgre/postgre_result.php */
View
22 system/database/drivers/sqlite/sqlite_driver.php
@@ -403,7 +403,23 @@ function _list_tables($prefix_limit = FALSE)
* @param string the table name
* @return string
*/
- function _list_columns($table = '')
+ protected function _list_columns($table = '')
+ {
+ // Not supported
+ return FALSE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Show index column query
+ *
+ * Generates a platform-specific query string so that the index names can be fetched
+ *
+ * @param string the table name
+ * @return string
+ */
+ protected function _list_index($table = '')
{
// Not supported
return FALSE;
@@ -420,7 +436,7 @@ function _list_columns($table = '')
* @param string the table name
* @return object
*/
- function _field_data($table)
+ protected function _field_data($table)
{
return "SELECT * FROM ".$table." LIMIT 1";
}
@@ -667,4 +683,4 @@ function _close($conn_id)
/* End of file sqlite_driver.php */
-/* Location: ./system/database/drivers/sqlite/sqlite_driver.php */
+/* Location: ./system/database/drivers/sqlite/sqlite_driver.php */
View
20 system/database/drivers/sqlite/sqlite_result.php
@@ -114,6 +114,24 @@ function field_data()
// --------------------------------------------------------------------
/**
+ * Index data
+ *
+ * Generates an array of objects containing index meta-data
+ *
+ * @return array
+ */
+ public function index_data()
+ {
+ if ($this->db->db_debug)
+ {
+ return $this->db->display_error('db_unsuported_feature');
+ }
+ return FALSE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Free the result
*
* @return null
@@ -188,4 +206,4 @@ function _fetch_object()
/* End of file sqlite_result.php */
-/* Location: ./system/database/drivers/sqlite/sqlite_result.php */
+/* Location: ./system/database/drivers/sqlite/sqlite_result.php */
View
21 system/database/drivers/sqlsrv/sqlsrv_driver.php
@@ -387,7 +387,7 @@ function _list_tables($prefix_limit = FALSE)
* @param string the table name
* @return string
*/
- function _list_columns($table = '')
+ protected function _list_columns($table = '')
{
return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$this->_escape_table($table)."'";
}
@@ -395,6 +395,21 @@ function _list_columns($table = '')
// --------------------------------------------------------------------
/**
+ * Show index column query
+ *
+ * Generates a platform-specific query string so that the index names can be fetched
+ *
+ * @param string the table name
+ * @return string
+ */
+ protected function _list_index($table = '')
+ {
+ return FALSE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Field data query
*
* Generates a platform-specific query so that the column data can be retrieved
@@ -403,7 +418,7 @@ function _list_columns($table = '')
* @param string the table name
* @return object
*/
- function _field_data($table)
+ protected function _field_data($table)
{
return "SELECT TOP 1 * FROM " . $this->_escape_table($table);
}
@@ -608,4 +623,4 @@ function _close($conn_id)
/* End of file mssql_driver.php */
-/* Location: ./system/database/drivers/mssql/mssql_driver.php */
+/* Location: ./system/database/drivers/mssql/mssql_driver.php */
View
20 system/database/drivers/sqlsrv/sqlsrv_result.php
@@ -114,6 +114,24 @@ function field_data()
// --------------------------------------------------------------------
/**
+ * Index data
+ *
+ * Generates an array of objects containing index meta-data
+ *
+ * @return array
+ */
+ public function index_data()
+ {
+ if ($this->db->db_debug)
+ {
+ return $this->db->display_error('db_unsuported_feature');
+ }
+ return FALSE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Free the result
*
* @return null
@@ -178,4 +196,4 @@ function _fetch_object()
/* End of file mssql_result.php */
-/* Location: ./system/database/drivers/mssql/mssql_result.php */
+/* Location: ./system/database/drivers/mssql/mssql_result.php */
View
23 user_guide_src/source/database/indexes.rst
@@ -0,0 +1,23 @@
+##########
+Index Data
+##########
+
+$this->db->list_index()
+=========================
+
+Returns an array of objects containing index information.
+
+.. note:: Not all databases provide meta-data.
+
+Usage example::
+
+ $indexes = $this->db->list_index('table_name');
+
+ foreach ($indexes as $index)
+ {
+ echo $index->name;
+ echo $index->column;
+ echo $index->type;
+ echo $index->comment;
+ }
+
Something went wrong with that request. Please try again.