48 require_once 
'MDB2/Driver/Reverse/Common.php';
 
   77         $result = $db->loadModule(
'Datatype', null, 
true);
 
   81         $table = $db->quoteIdentifier($table, 
true);
 
   82         $query = 
"SHOW COLUMNS FROM $table LIKE ".$db->quote($field_name);
 
   88             $column = array_change_key_case($column, CASE_LOWER);
 
   89             $column[
'name'] = $column[
'field'];
 
   90             unset($column[
'field']);
 
   92                 if ($db->options[
'field_case'] == CASE_LOWER) {
 
   93                     $column[
'name'] = strtolower($column[
'name']);
 
   95                     $column[
'name'] = strtoupper($column[
'name']);
 
   98                 $column = array_change_key_case($column, $db->options[
'field_case']);
 
  100             if ($field_name == $column[
'name']) {
 
  101                 $mapped_datatype = $db->datatype->mapNativeDatatype($column);
 
  102                 if (PEAR::IsError($mapped_datatype)) {
 
  103                     return $mapped_datatype;
 
  105                 list($types, $length, $unsigned, $fixed) = $mapped_datatype;
 
  107                 if (empty($column[
'null']) || $column[
'null'] !== 
'YES') {
 
  111                 if (array_key_exists(
'default', $column)) {
 
  112                     $default = $column[
'default'];
 
  113                     if (is_null($default) && $notnull) {
 
  117                 $autoincrement = 
false;
 
  118                 if (!empty($column[
'extra']) && $column[
'extra'] == 
'auto_increment') {
 
  119                     $autoincrement = 
true;
 
  122                 $definition[0] = array(
 
  123                     'notnull' => $notnull,
 
  124                     'nativetype' => preg_replace(
'/^([a-z]+)[^a-z].*/i', 
'\\1', $column[
'type'])
 
  126                 if (!is_null($length)) {
 
  127                     $definition[0][
'length'] = $length;
 
  129                 if (!is_null($unsigned)) {
 
  130                     $definition[0][
'unsigned'] = $unsigned;
 
  132                 if (!is_null($fixed)) {
 
  133                     $definition[0][
'fixed'] = $fixed;
 
  135                 if ($default !== 
false) {
 
  136                     $definition[0][
'default'] = $default;
 
  138                 if ($autoincrement !== 
false) {
 
  139                     $definition[0][
'autoincrement'] = $autoincrement;
 
  141                 foreach ($types as $key => $type) {
 
  142                     $definition[$key] = $definition[0];
 
  143                     if ($type == 
'clob' || $type == 
'blob') {
 
  144                         unset($definition[$key][
'default']);
 
  146                     $definition[$key][
'type'] = $type;
 
  147                     $definition[$key][
'mdb2type'] = $type;
 
  154             'it was not specified an existing table column', __FUNCTION__);
 
  175         $table = $db->quoteIdentifier($table, 
true);
 
  176         $query = 
"SHOW INDEX FROM $table /*!50002 WHERE Key_name = %s */";
 
  177         $constraint_name_mdb2 = $db->getIndexName($constraint_name);
 
  178         $result = $db->queryRow(sprintf(
$query, $db->quote($constraint_name_mdb2)));
 
  182             $constraint_name = $constraint_name_mdb2;
 
  184         $result = $db->query(sprintf(
$query, $db->quote($constraint_name)));
 
  189         $definition = array();
 
  191             $row = array_change_key_case(
$row, CASE_LOWER);
 
  192             $key_name = 
$row[
'key_name'];
 
  194                 if ($db->options[
'field_case'] == CASE_LOWER) {
 
  195                     $key_name = strtolower($key_name);
 
  197                     $key_name = strtoupper($key_name);
 
  200             if ($constraint_name == $key_name) {
 
  201                 if (!
$row[
'non_unique']) {
 
  203                         $constraint_name . 
' is not an existing table constraint', __FUNCTION__);
 
  205                 $column_name = 
$row[
'column_name'];
 
  207                     if ($db->options[
'field_case'] == CASE_LOWER) {
 
  208                         $column_name = strtolower($column_name);
 
  210                         $column_name = strtoupper($column_name);
 
  213                 $definition[
'fields'][$column_name] = array(
 
  214                     'position' => $colpos++
 
  216                 if (!empty(
$row[
'collation'])) {
 
  217                     $definition[
'fields'][$column_name][
'sorting'] = (
$row[
'collation'] == 
'A' 
  218                         ? 
'ascending' : 
'descending');
 
  223         if (empty($definition[
'fields'])) {
 
  225                 $constraint_name . 
' is not an existing table constraint', __FUNCTION__);
 
  248         $table = $db->quoteIdentifier($table, 
true);
 
  249         $query = 
"SHOW INDEX FROM $table /*!50002 WHERE Key_name = %s */";
 
  250         if (strtolower($index_name) != 
'primary') {
 
  251             $index_name_mdb2 = $db->getIndexName($index_name);
 
  252             $result = $db->queryRow(sprintf(
$query, $db->quote($index_name_mdb2)));
 
  256                 $index_name = $index_name_mdb2;
 
  259         $result = $db->query(sprintf(
$query, $db->quote($index_name)));
 
  264         $definition = array();
 
  266             $row = array_change_key_case(
$row, CASE_LOWER);
 
  267             $key_name = 
$row[
'key_name'];
 
  269                 if ($db->options[
'field_case'] == CASE_LOWER) {
 
  270                     $key_name = strtolower($key_name);
 
  272                     $key_name = strtoupper($key_name);
 
  275             if ($index_name == $key_name) {
 
  276                 if (
$row[
'non_unique']) {
 
  278                         'it was not specified an existing table constraint', __FUNCTION__);
 
  280                 if (
$row[
'key_name'] == 
'PRIMARY') {
 
  281                     $definition[
'primary'] = 
true;
 
  283                     $definition[
'unique'] = 
true;
 
  285                 $column_name = 
$row[
'column_name'];
 
  287                     if ($db->options[
'field_case'] == CASE_LOWER) {
 
  288                         $column_name = strtolower($column_name);
 
  290                         $column_name = strtoupper($column_name);
 
  293                 $definition[
'fields'][$column_name] = array(
 
  294                     'position' => $colpos++
 
  296                 if (!empty(
$row[
'collation'])) {
 
  297                     $definition[
'fields'][$column_name][
'sorting'] = (
$row[
'collation'] == 
'A' 
  298                         ? 
'ascending' : 
'descending');
 
  303         if (empty($definition[
'fields'])) {
 
  305                 'it was not specified an existing table constraint', __FUNCTION__);
 
  332         $query = 
'SELECT trigger_name, 
  333                          event_object_table AS table_name, 
  334                          action_statement AS trigger_body, 
  335                          action_timing AS trigger_type, 
  336                          event_manipulation AS trigger_event 
  337                     FROM information_schema.triggers 
  338                    WHERE trigger_name = '. $db->quote($trigger, 
'text');
 
  340             'trigger_name'    => 
'text',
 
  341             'table_name'      => 
'text',
 
  342             'trigger_body'    => 
'text',
 
  343             'trigger_type'    => 
'text',
 
  344             'trigger_event'   => 
'text',
 
  350         $def[
'trigger_comment'] = 
'';
 
  351         $def[
'trigger_enabled'] = 
true;
 
  385         if (!is_resource($resource)) {
 
  387                 'Could not generate result resource', __FUNCTION__);
 
  391             if ($db->options[
'field_case'] == CASE_LOWER) {
 
  392                 $case_func = 
'strtolower';
 
  394                 $case_func = 
'strtoupper';
 
  397             $case_func = 
'strval';
 
  400         $count = @mysql_num_fields($resource);
 
  404             $res[
'num_fields'] = $count;
 
  407         $db->loadModule(
'Datatype', null, 
true);
 
  408         for ($i = 0; $i < $count; $i++) {
 
  410                 'table' => $case_func(@mysql_field_table($resource, $i)),
 
  411                 'name'  => $case_func(@mysql_field_name($resource, $i)),
 
  412                 'type'  => @mysql_field_type($resource, $i),
 
  413                 'length'   => @mysql_field_len($resource, $i),
 
  414                 'flags' => @mysql_field_flags($resource, $i),
 
  416             if (
$res[$i][
'type'] == 
'string') {
 
  417                 $res[$i][
'type'] = 
'char';
 
  418             } elseif (
$res[$i][
'type'] == 
'unknown') {
 
  419                 $res[$i][
'type'] = 
'decimal';
 
  421             $mdb2type_info = $db->datatype->mapNativeDatatype(
$res[$i]);
 
  423                return $mdb2type_info;
 
  425             $res[$i][
'mdb2type'] = $mdb2type_info[0][0];
 
  427                 $res[
'order'][
$res[$i][
'name']] = $i;
 
  430                 $res[
'ordertable'][
$res[$i][
'table']][
$res[$i][
'name']] = $i;