You are here

function _demo_get_fields in Demonstration site (Sandbox / Snapshot) 8

Same name and namespace in other branches
  1. 5 database_mysql_dump.inc \_demo_get_fields()
  2. 6 database_mysql_dump.inc \_demo_get_fields()
  3. 7 database_mysql_dump.inc \_demo_get_fields()

Return table fields and their properties.

1 call to _demo_get_fields()
_demo_dump_table_data in ./demo.module
Dump table data.

File

./demo.module, line 421

Code

function _demo_get_fields($result) {
  $fields = [];
  switch (db_driver()) {
    case 'mysql':
      $i = 0;
      while ($meta = $result
        ->getColumnMeta($i)) {
        settype($meta, 'object');

        // pdo_mysql does not add a native type for INT fields.
        if (isset($meta->native_type)) {

          // Enhance the field definition for mysql-extension compatibilty.
          $meta->numeric = strtolower($meta->native_type) == 'short';
          $meta->blob = strtolower($meta->native_type) == 'blob';

          // Add custom properties.
          $meta->timestamp = strtolower($meta->native_type) == 'long';
        }
        else {
          $meta->numeric = $meta->blob = $meta->timestamp = FALSE;
        }
        $meta->binary = array_search('not_null', $meta->flags);
        $fields[] = $meta;
        $i++;
      }
      break;
  }
  return $fields;
}