<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->

<refentry xml:id="function.cubrid-schema" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
 <refnamediv>
  <refname>cubrid_schema</refname>
  <refpurpose>Get the requested schema information</refpurpose>
 </refnamediv>

 <refsect1 role="description">
  &reftitle.description;
  <methodsynopsis>
   <type>array</type><methodname>cubrid_schema</methodname>
   <methodparam><type>resource</type><parameter>conn_identifier</parameter></methodparam>  
   <methodparam><type>int</type><parameter>schema_type</parameter></methodparam>  
   <methodparam choice="opt"><type>string</type><parameter>class_name</parameter></methodparam> 
   <methodparam choice="opt"><type>string</type><parameter>attr_name</parameter></methodparam>  
  </methodsynopsis>
  <para>
   The <function>cubrid_schema</function> function is used to get the
   requested schema information from database. To get information about specific class,
   set the <parameter>class_name</parameter>, to get information about specific attribute
   (can be used only with <constant>CUBRID_SCH_ATTR_PRIVILEGE</constant>),
   set the <parameter>attr_name</parameter>.
  </para>

  <para>
  The result of the <function>cubrid_schema</function> function is returned as a two-dimensional
  array (column (associative array) * row (numeric array)). The following
  tables shows types of schema and the column structure of the result array to
  be returned based on the schema type.
  </para>

  <para>
  <table>
   <title>Result Composition of Each Type</title>
    <tgroup cols="4">
     <thead>
      <row>
       <entry>Schema</entry>
       <entry>Column Number</entry>
       <entry>Column Name</entry>
       <entry>Value</entry>
      </row>
     </thead>
     <tbody>
      <row>
       <entry>CUBRID_SCH_CLASS</entry>
       <entry>1</entry>
       <entry>NAME</entry>
       <entry></entry>
      </row>
      <row>
       <entry></entry>
       <entry>2</entry>
       <entry>TYPE</entry>
       <entry>0:system class 1:vclass 2:class</entry>
      </row>

      <row>
       <entry>CUBRID_SCH_VCLASS</entry>
       <entry>1</entry>
       <entry>NAME</entry>
       <entry></entry>
      </row>
      <row>
       <entry></entry>
       <entry>2</entry>
       <entry>TYPE</entry>
       <entry>1:vclass</entry>
      </row>

      <row>
       <entry>CUBRID_SCH_QUERY_SPEC</entry>
       <entry>1</entry>
       <entry>QUERY_SPEC</entry>
       <entry></entry>
      </row>

      <row>
       <entry>CUBRID_SCH_ATTRIBUTE / CUBRID_SCH_CLASS_ATTRIBUTE</entry>
       <entry>1</entry>
       <entry>ATTR_NAME</entry>
       <entry></entry>
      </row>
      <row>
       <entry></entry>
       <entry>2</entry>
       <entry>DOMAIN</entry>
       <entry></entry>
      </row>
      <row>
       <entry></entry>
       <entry>3</entry>
       <entry>SCALE</entry>
       <entry></entry>
      </row>
      <row>
       <entry></entry>
       <entry>4</entry>
       <entry>PRECISION</entry>
       <entry></entry>
      </row>
      <row>
       <entry></entry>
       <entry>5</entry>
       <entry>INDEXED</entry>
       <entry>1:indexed</entry>
      </row>
      <row>
       <entry></entry>
       <entry>6</entry>
       <entry>NOT NULL</entry>
       <entry>1:not null</entry>
      </row>
      <row>
       <entry></entry>
       <entry>7</entry>
       <entry>SHARED</entry>
       <entry>1:shared</entry>
      </row>
      <row>
       <entry></entry>
       <entry>8</entry>
       <entry>UNIQUE</entry>
       <entry>1:unique</entry>
      </row>
      <row>
       <entry></entry>
       <entry>9</entry>
       <entry>DEFAULT</entry>
       <entry></entry>
      </row>
      <row>
       <entry></entry>
       <entry>10</entry>
       <entry>ATTR_ORDER</entry>
       <entry>base:1</entry>
      </row>
      <row>
       <entry></entry>
       <entry>11</entry>
       <entry>CLASS_NAME</entry>
       <entry></entry>
      </row>
      <row>
       <entry></entry>
       <entry>12</entry>
       <entry>SOURCE_CLASS</entry>
       <entry></entry>
      </row>
      <row>
       <entry></entry>
       <entry>13</entry>
       <entry>IS_KEY</entry>
       <entry>1:key</entry>
      </row>

      <row>
       <entry>CUBRID_SCH_METHOD / CUBRID_SCH_CLASS_METHOD</entry>
       <entry>1</entry>
       <entry>NAME</entry>
       <entry></entry>
      </row>
      <row>
       <entry></entry>
       <entry>2</entry>
       <entry>RET_DOMAIN</entry>
       <entry></entry>
      </row>
      <row>
       <entry></entry>
       <entry>3</entry>
       <entry>ARG_DOMAIN</entry>
       <entry></entry>
      </row>

      <row>
       <entry>CUBRID_SCH_METHOD_FILE</entry>
       <entry>1</entry>
       <entry>METHOD_FILE</entry>
       <entry></entry>
      </row>

      <row>
       <entry>CUBRID_SCH_SUPERCLASS / CUBRID_SCH_DIRECT_SUPER_CLASS / CUBRID_SCH_SUBCLASS</entry>
       <entry>1</entry>
       <entry>CLASS_NAME</entry>
       <entry></entry>
      </row>
      <row>
       <entry></entry>
       <entry>2</entry>
       <entry>TYPE</entry>
       <entry>0:system class 1:vclass 2:class</entry>
      </row>

      <row>
       <entry>CUBRID_SCH_CONSTRAINT</entry>
       <entry>1</entry>
       <entry>TYPE</entry>
       <entry>0:unique 1:index 2:reverse unique 3:reverse index</entry>
      </row>
      <row>
       <entry></entry>
       <entry>2</entry>
       <entry>NAME</entry>
       <entry></entry>
      </row>
      <row>
       <entry></entry>
       <entry>3</entry>
       <entry>ATTR_NAME</entry>
       <entry></entry>
      </row>
      <row>
       <entry></entry>
       <entry>4</entry>
       <entry>NUM_PAGES</entry>
       <entry></entry>
      </row>
      <row>
       <entry></entry>
       <entry>5</entry>
       <entry>NUM_KEYS</entry>
       <entry></entry>
      </row>
      <row>
       <entry></entry>
       <entry>6</entry>
       <entry>PRIMARY_KEY</entry>
       <entry>1:primary key</entry>
      </row>
      <row>
       <entry></entry>
       <entry>7</entry>
       <entry>KEY_ORDER</entry>
       <entry>base:1</entry>
      </row>

      <row>
       <entry>CUBRID_SCH_TRIGGER</entry>
       <entry>1</entry>
       <entry>NAME</entry>
       <entry></entry>
      </row>
      <row>
       <entry></entry>
       <entry>2</entry>
       <entry>STATUS</entry>
       <entry></entry>
      </row>
      <row>
       <entry></entry>
       <entry>3</entry>
       <entry>EVENT</entry>
       <entry></entry>
      </row>
      <row>
       <entry></entry>
       <entry>4</entry>
       <entry>TARGET_CLASS</entry>
       <entry></entry>
      </row>
      <row>
       <entry></entry>
       <entry>5</entry>
       <entry>TARGET_ATTR</entry>
       <entry></entry>
      </row>
      <row>
       <entry></entry>
       <entry>6</entry>
       <entry>ACTION_TIME</entry>
       <entry></entry>
      </row>
      <row>
       <entry></entry>
       <entry>7</entry>
       <entry>ACTION</entry>
       <entry></entry>
      </row>
      <row>
       <entry></entry>
       <entry>8</entry>
       <entry>PRIORITY</entry>
       <entry></entry>
      </row>
      <row>
       <entry></entry>
       <entry>9</entry>
       <entry>CONDITION_TIME</entry>
       <entry></entry>
      </row>
      <row>
       <entry></entry>
       <entry>10</entry>
       <entry>CONDITION</entry>
       <entry></entry>
      </row>

      <row>
       <entry>CUBRID_SCH_CLASS_PRIVILEGE / CUBRID_SCH_ATTR_PRIVILEGE</entry>
       <entry>1</entry>
       <entry>CLASS_NAME / ATTR_NAME</entry>
       <entry></entry>
      </row>
      <row>
       <entry></entry>
       <entry>2</entry>
       <entry>PRIVILEGE</entry>
       <entry></entry>
      </row>
      <row>
       <entry></entry>
       <entry>3</entry>
       <entry>GRANTABLE</entry>
       <entry></entry>
      </row>

      <row>
       <entry>CUBRID_SCH_PRIMARY_KEY</entry>
       <entry>1</entry>
       <entry>CLASS_NAME</entry>
       <entry></entry>
      </row>
      <row>
       <entry></entry>
       <entry>2</entry>
       <entry>ATTR_NAME</entry>
       <entry></entry>
      </row>
      <row>
       <entry></entry>
       <entry>3</entry>
       <entry>KEY_SEQ</entry>
       <entry>base:1</entry>
      </row>
      <row>
       <entry></entry>
       <entry>4</entry>
       <entry>KEY_NAME</entry>
       <entry></entry>
      </row>

      <row>
       <entry>CUBRID_SCH_IMPORTED_KEYS / CUBRID_SCH_EXPORTED_KEYS / CUBRID_SCH_CROSS_REFERENCE</entry>
       <entry>1</entry>
       <entry>PKTABLE_NAME</entry>
       <entry></entry>
      </row>
      <row>
       <entry></entry>
       <entry>2</entry>
       <entry>PKCOLUMN_NAME</entry>
       <entry></entry>
      </row>
      <row>
       <entry></entry>
       <entry>3</entry>
       <entry>FKTABLE_NAME</entry>
       <entry>base:1</entry>
      </row>
      <row>
       <entry></entry>
       <entry>4</entry>
       <entry>FKCOLUMN_NAME</entry>
       <entry></entry>
      </row>
      <row>
       <entry></entry>
       <entry>5</entry>
       <entry>KEY_SEQ</entry>
       <entry>base:1</entry>
      </row>
      <row>
       <entry></entry>
       <entry>6</entry>
       <entry>UPDATE_ACTION</entry>
       <entry>0:cascade 1:restrict 2:no action 3:set null</entry>
      </row>
      <row>
       <entry></entry>
       <entry>7</entry>
       <entry>DELETE_ACTION</entry>
       <entry>0:cascade 1:restrict 2:no action 3:set null</entry>
      </row>
      <row>
       <entry></entry>
       <entry>8</entry>
       <entry>FK_NAME</entry>
       <entry></entry>
      </row>
      <row>
       <entry></entry>
       <entry>9</entry>
       <entry>PK_NAME</entry>
       <entry></entry>
      </row>
     </tbody>
    </tgroup>
   </table>
  </para>

 </refsect1>

<refsect1 role="parameters">
  &reftitle.parameters;
  <para>
  <variablelist>
    <varlistentry>
  <term><parameter>conn_identifier</parameter></term>
  <listitem><para>Connection identifier.</para></listitem>
   </varlistentry>
   <varlistentry>
  <term><parameter>schema_type</parameter></term>
  <listitem><para>Schema data that you want to know.</para></listitem>
   </varlistentry>
   <varlistentry>
  <term><parameter>class_name</parameter></term>
  <listitem><para>Class you want to know the schema of.</para></listitem>
   </varlistentry>
   <varlistentry>
  <term><parameter>attr_name</parameter></term>
  <listitem><para>Attribute you want to know the schema of.</para></listitem>
   </varlistentry>
  </variablelist>
  </para>
 </refsect1>

 <refsect1 role="returnvalues">
  &reftitle.returnvalues;
  <para>
    Array containing the schema information, when process is successful,&return.falseforfailure;.
  </para>
 </refsect1>
 
 <refsect1 role="changelog">
  &reftitle.changelog;
  <para>
   <informaltable>
    <tgroup cols="2">
     <thead>
      <row>
       <entry>&Version;</entry>
       <entry>&Description;</entry>
      </row>
     </thead>
     <tbody>
      <row>
       <entry>8.3.1</entry>
       <entry>
        Change return value: when process is unsuccessful, return false, not -1.
       </entry>
      </row>
     </tbody>
    </tgroup>
   </informaltable>
  </para>
 </refsect1>

 <refsect1 role="examples">
  &reftitle.examples;
  <example>
   <title><function>cubrid_schema</function> example</title>
   <programlisting role="php">
<![CDATA[
<?php
$conn = cubrid_connect("localhost", 33000, "demodb", "dba");

printf("\n--- Primary Key ---\n");
$pk = cubrid_schema($conn, CUBRID_SCH_PRIMARY_KEY, "game");
var_dump($pk);

printf("\n--- Foreign Keys ---\n");
$fk = cubrid_schema($conn, CUBRID_SCH_IMPORTED_KEYS, "game");
var_dump($fk);

printf("\n--- Column Attribute ---\n");
$attr = cubrid_schema($conn, CUBRID_SCH_ATTRIBUTE, "stadium", "area");
var_dump($attr);

cubrid_disconnect($conn);
?>
]]>
   </programlisting>
    &example.outputs;
    <screen>
<![CDATA[

--- Primary Key ---
array(3) {
  [0]=>
  array(4) {
    ["CLASS_NAME"]=>
    string(4) "game"
    ["ATTR_NAME"]=>
    string(12) "athlete_code"
    ["KEY_SEQ"]=>
    string(1) "3"
    ["KEY_NAME"]=>
    string(41) "pk_game_host_year_event_code_athlete_code"
  }
  [1]=>
  array(4) {
    ["CLASS_NAME"]=>
    string(4) "game"
    ["ATTR_NAME"]=>
    string(10) "event_code"
    ["KEY_SEQ"]=>
    string(1) "2"
    ["KEY_NAME"]=>
    string(41) "pk_game_host_year_event_code_athlete_code"
  }
  [2]=>
  array(4) {
    ["CLASS_NAME"]=>
    string(4) "game"
    ["ATTR_NAME"]=>
    string(9) "host_year"
    ["KEY_SEQ"]=>
    string(1) "1"
    ["KEY_NAME"]=>
    string(41) "pk_game_host_year_event_code_athlete_code"
  }
}

--- Foreign Keys ---
array(2) {
  [0]=>
  array(9) {
    ["PKTABLE_NAME"]=>
    string(7) "athlete"
    ["PKCOLUMN_NAME"]=>
    string(4) "code"
    ["FKTABLE_NAME"]=>
    string(4) "game"
    ["FKCOLUMN_NAME"]=>
    string(12) "athlete_code"
    ["KEY_SEQ"]=>
    string(1) "1"
    ["UPDATE_RULE"]=>
    string(1) "1"
    ["DELETE_RULE"]=>
    string(1) "1"
    ["FK_NAME"]=>
    string(20) "fk_game_athlete_code"
    ["PK_NAME"]=>
    string(15) "pk_athlete_code"
  }
  [1]=>
  array(9) {
    ["PKTABLE_NAME"]=>
    string(5) "event"
    ["PKCOLUMN_NAME"]=>
    string(4) "code"
    ["FKTABLE_NAME"]=>
    string(4) "game"
    ["FKCOLUMN_NAME"]=>
    string(10) "event_code"
    ["KEY_SEQ"]=>
    string(1) "1"
    ["UPDATE_RULE"]=>
    string(1) "1"
    ["DELETE_RULE"]=>
    string(1) "1"
    ["FK_NAME"]=>
    string(18) "fk_game_event_code"
    ["PK_NAME"]=>
    string(13) "pk_event_code"
  }
}

--- Column Attribute ---
array(1) {
  [0]=>
  array(13) {
    ["ATTR_NAME"]=>
    string(4) "area"
    ["DOMAIN"]=>
    string(1) "7"
    ["SCALE"]=>
    string(1) "2"
    ["PRECISION"]=>
    string(2) "10"
    ["INDEXED"]=>
    string(1) "0"
    ["NON_NULL"]=>
    string(1) "0"
    ["SHARED"]=>
    string(1) "0"
    ["UNIQUE"]=>
    string(1) "0"
    ["DEFAULT"]=>
    NULL
    ["ATTR_ORDER"]=>
    string(1) "4"
    ["CLASS_NAME"]=>
    string(7) "stadium"
    ["SOURCE_CLASS"]=>
    string(7) "stadium"
    ["IS_KEY"]=>
    string(1) "0"
  }
}
]]>
   </screen>
  </example>
 </refsect1>

</refentry>

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
