From 6ebceb439ceddd02925a8424e3ccb6d368b9a92d Mon Sep 17 00:00:00 2001 From: James L Parry Date: Thu, 4 Dec 2014 06:23:14 -0800 Subject: User Guide - consolidate table & field metadata pages Signed-off-by:James L Parry --- user_guide_src/source/database/fields.rst | 80 ---------------- user_guide_src/source/database/index.rst | 3 +- user_guide_src/source/database/metadata.rst | 130 ++++++++++++++++++++++++++ user_guide_src/source/database/table_data.rst | 31 ------ 4 files changed, 131 insertions(+), 113 deletions(-) delete mode 100644 user_guide_src/source/database/fields.rst create mode 100644 user_guide_src/source/database/metadata.rst delete mode 100644 user_guide_src/source/database/table_data.rst (limited to 'user_guide_src') diff --git a/user_guide_src/source/database/fields.rst b/user_guide_src/source/database/fields.rst deleted file mode 100644 index b706ace7d..000000000 --- a/user_guide_src/source/database/fields.rst +++ /dev/null @@ -1,80 +0,0 @@ -########## -Field Data -########## - -$this->db->list_fields() -========================= - -Returns an array containing the field names. This query can be called -two ways: - -1. You can supply the table name and call it from the $this->db-> -object:: - - $fields = $this->db->list_fields('table_name'); - - foreach ($fields as $field) - { - echo $field; - } - -2. You can gather the field names associated with any query you run by -calling the function from your query result object:: - - $query = $this->db->query('SELECT * FROM some_table'); - - foreach ($query->list_fields() as $field) - { - echo $field; - } - -$this->db->field_exists() -========================== - -Sometimes it's helpful to know whether a particular field exists before -performing an action. Returns a boolean TRUE/FALSE. Usage example:: - - if ($this->db->field_exists('field_name', 'table_name')) - { - // some code... - } - -.. note:: Replace *field_name* with the name of the column you are looking - for, and replace *table_name* with the name of the table you are - looking for. - -$this->db->field_data() -======================== - -Returns an array of objects containing field information. - -Sometimes it's helpful to gather the field names or other metadata, like -the column type, max length, etc. - -.. note:: Not all databases provide meta-data. - -Usage example:: - - $fields = $this->db->field_data('table_name'); - - foreach ($fields as $field) - { - echo $field->name; - echo $field->type; - echo $field->max_length; - echo $field->primary_key; - } - -If you have run a query already you can use the result object instead of -supplying the table name:: - - $query = $this->db->query("YOUR QUERY"); - $fields = $query->field_data(); - -The following data is available from this function if supported by your -database: - -- name - column name -- max_length - maximum length of the column -- primary_key - 1 if the column is a primary key -- type - the type of the column \ No newline at end of file diff --git a/user_guide_src/source/database/index.rst b/user_guide_src/source/database/index.rst index cfd624238..4612daf9d 100644 --- a/user_guide_src/source/database/index.rst +++ b/user_guide_src/source/database/index.rst @@ -17,8 +17,7 @@ patterns. The database functions offer clear, simple syntax. Query Helper Functions Query Builder Class Transactions - Table MetaData - Field MetaData + Getting MetaData Custom Function Calls Query Caching Database Manipulation with Database Forge diff --git a/user_guide_src/source/database/metadata.rst b/user_guide_src/source/database/metadata.rst new file mode 100644 index 000000000..b8be809b6 --- /dev/null +++ b/user_guide_src/source/database/metadata.rst @@ -0,0 +1,130 @@ +################# +Database Metadata +################# + +************** +Table MetaData +************** + +These functions let you fetch table information. + +List the Tables in Your Database +================================ + +**$this->db->list_tables();** + +Returns an array containing the names of all the tables in the database +you are currently connected to. Example:: + + $tables = $this->db->list_tables(); + + foreach ($tables as $table) + { + echo $table; + } + + +Determine If a Table Exists +=========================== + +**$this->db->table_exists();** + +Sometimes it's helpful to know whether a particular table exists before +running an operation on it. Returns a boolean TRUE/FALSE. Usage example:: + + if ($this->db->table_exists('table_name')) + { + // some code... + } + +.. note:: Replace *table_name* with the name of the table you are looking for. + + +************** +Field MetaData +************** + +List the Fields in a Table +========================== + +**$this->db->list_fields()** + +Returns an array containing the field names. This query can be called +two ways: + +1. You can supply the table name and call it from the $this->db-> +object:: + + $fields = $this->db->list_fields('table_name'); + + foreach ($fields as $field) + { + echo $field; + } + +2. You can gather the field names associated with any query you run by +calling the function from your query result object:: + + $query = $this->db->query('SELECT * FROM some_table'); + + foreach ($query->list_fields() as $field) + { + echo $field; + } + + +Determine If a Field is Present in a Table +========================================== + +**$this->db->field_exists()** + +Sometimes it's helpful to know whether a particular field exists before +performing an action. Returns a boolean TRUE/FALSE. Usage example:: + + if ($this->db->field_exists('field_name', 'table_name')) + { + // some code... + } + +.. note:: Replace *field_name* with the name of the column you are looking + for, and replace *table_name* with the name of the table you are + looking for. + + +Retrieve Field Metadata +======================= + +**$this->db->field_data()** + +Returns an array of objects containing field information. + +Sometimes it's helpful to gather the field names or other metadata, like +the column type, max length, etc. + +.. note:: Not all databases provide meta-data. + +Usage example:: + + $fields = $this->db->field_data('table_name'); + + foreach ($fields as $field) + { + echo $field->name; + echo $field->type; + echo $field->max_length; + echo $field->primary_key; + } + +If you have run a query already you can use the result object instead of +supplying the table name:: + + $query = $this->db->query("YOUR QUERY"); + $fields = $query->field_data(); + +The following data is available from this function if supported by your +database: + +- name - column name +- max_length - maximum length of the column +- primary_key - 1 if the column is a primary key +- type - the type of the column diff --git a/user_guide_src/source/database/table_data.rst b/user_guide_src/source/database/table_data.rst deleted file mode 100644 index 744a05154..000000000 --- a/user_guide_src/source/database/table_data.rst +++ /dev/null @@ -1,31 +0,0 @@ -########## -Table Data -########## - -These functions let you fetch table information. - -$this->db->list_tables(); -========================== - -Returns an array containing the names of all the tables in the database -you are currently connected to. Example:: - - $tables = $this->db->list_tables(); - - foreach ($tables as $table) - { - echo $table; - } - -$this->db->table_exists(); -=========================== - -Sometimes it's helpful to know whether a particular table exists before -running an operation on it. Returns a boolean TRUE/FALSE. Usage example:: - - if ($this->db->table_exists('table_name')) - { - // some code... - } - -.. note:: Replace *table_name* with the name of the table you are looking for. -- cgit v1.2.3-24-g4f1b