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' => $table_name)->fetchAll();
$is_int11_field = FALSE;
foreach ($raw_table_info as $result_id => $recObject) {
if ($recObject->field == $value_col_name && $recObject->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] => Array
(
[entity_types] => Array
(
)
[foreign keys] => Array
(
[format] => Array
(
[table] => filter_format
[columns] => Array
(
[format] => format
)
)
)
[indexes] => Array
(
[format] => Array
(
[0] => format
)
)
[settings] => Array
(
)
[translatable] => 0
[storage] => Array
(
[type] => field_sql_storage
[settings] => Array
(
)
[module] => field_sql_storage
[active] => 1
[details] => Array
(
[sql] => Array
(
[FIELD_LOAD_CURRENT] => Array
(
[field_data_field_foo_feedback023] => Array
(
[value] => field_foo_feedback023_value
[format] => field_foo_feedback023_format
)
)
[FIELD_LOAD_REVISION] => Array
(
[field_revision_field_foo_feedback023] => Array
(
[value] => field_foo_feedback023_value
[format] => 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 = &$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' && $my_field['columns']['value']['length'] == 11;
return $field_uses_sql_storage && $field_value_uses_int_11;
}
show columns
for mysql returns a column called 'field' dev.mysql.com/doc/refman/5.0/en/show-columns.html ... while the rest of the page talks about "columns" so its all snafu :)