How to check a mysql table field type I need to check whether a certain table field is of type 'int' (I am referring to table schema)

e.g. for table field_data_field_myfield 
field_data_field_myfield_value  is of type int(11)

I actually need a generic function that check if a certain field is of type in the schema.

[Edit]

I want to explain better my difficulty:

I have a feature that holds a certain field of type 'datetime'. Now as this type creates performence problems on database sides, I decided to change it to 'datestamp' [= unix format]. I did this editing the file MYFEATURE.features.field.inc that is a database field table mirror.

Now the reports are: 

FieldException: Cannot change an existing field's type. in field_update_field()


This is an exception raised due to the fact I am not supposed to alter schema while data is in. Therefore I create a hook_update_N for data migration.

Now I believe I need to do a hook_update_N for schema migration too.
HERE is the point I need to alter schema in a hook_update_N.
You want something like:

function _mymodule_is_db_column_int11($drupal_field_name) {
  // See example output below.
  $drupal_field_info = field_info_field($drupal_field_name);

  // From this table you can get the table name, which follows a known
  // convention in the Field API (but this lets you get it grammatically)
  // and also value field names from the definition array.
  $sql_details = $drupal_field_info['storage']['details']['sql'];
  $table_name = key($sql_details[FIELD_LOAD_CURRENT]);
  $value_col_name = $sql_details[FIELD_LOAD_CURRENT]['value'];

  // Then in MySQL check the column type. I see no way to do this using
  // the drupal api.
  $raw_table_info = db_query("SHOW COLUMNS FROM :tbl;", array(':tbl' =&gt; $table_name)-&gt;fetchAll();

  $is_int11_field = FALSE;
  foreach ($raw_table_info as $result_id =&gt; $recObject) {
    if ($recObject-&gt;field == $value_col_name &amp;&amp; $recObject-&gt;Type == 'int(11)') {
      $is_int11_field = TRUE;
    }
  }
  return $is_int11_field;
}


An example of output of field_info_fields() for 1 field:

/*
[field_foo_feedback023] =&gt; Array
    (
        [entity_types] =&gt; Array
            (
            )

        [foreign keys] =&gt; Array
            (
                [format] =&gt; Array
                    (
                        [table] =&gt; filter_format
                        [columns] =&gt; Array
                            (
                                [format] =&gt; format
                            )

                    )

            )

        [indexes] =&gt; Array
            (
                [format] =&gt; Array
                    (
                        [0] =&gt; format
                    )

            )

        [settings] =&gt; Array
            (
            )

        [translatable] =&gt; 0
        [storage] =&gt; Array
            (
                [type] =&gt; field_sql_storage
                [settings] =&gt; Array
                    (
                    )

                [module] =&gt; field_sql_storage
                [active] =&gt; 1
                [details] =&gt; Array
                    (
                        [sql] =&gt; Array
                            (
                                [FIELD_LOAD_CURRENT] =&gt; Array
                                    (
                                        [field_data_field_foo_feedback023] =&gt; Array
                                            (
                                                [value] =&gt; field_foo_feedback023_value
                                                [format] =&gt; field_foo_feedback023_format
                                            )

                                    )

                                [FIELD_LOAD_REVISION] =&gt; Array
                                    (
                                        [field_revision_field_foo_feedback023] =&gt; Array
                                            (
                                                [value] =&gt; field_foo_feedback023_value
                                                [format] =&gt; field_foo_feedback023_format
                                            )

                                    )

                            )

                    )

            )

*/


If you're going to try and use this you'd probably want to add caching, probably want to assure your type check is always forced to lower-case etc. Also check your mysql credentials allow for this sql usage of SHOW.

EDIT: A slightly simpler solution

The only problem I see with this solution is for complex or custom fields you will always have to know what the value field you want to check is; and require a custom check -- for default simple value fields this should work without needing custom SQL:

function _mymodule_is_db_column_int11($drupal_field_name) {
  // See example output below.
  $fields = field_read_fields();
  $my_field = &amp;$fields[$field_name];

  $field_uses_sql_storage = $my_field['storage']['type'] = 'field_sql_storage';
  $field_value_uses_int_11 = $my_field['columns']['value']['type'] == 'int' &amp;&amp; $my_field['columns']['value']['length'] == 11;

  return $field_uses_sql_storage &amp;&amp; $field_value_uses_int_11;
}