tags:

views:

38

answers:

3

Hi,

I need to find all smallint (specifically smallint(5)) columns in a MySQL 4.1 database. It seems that INFORMATION_SCHEMA is only available in MySQL 5+. Is there an alternative?

Thanks

+1  A: 

Use the SHOW COLUMNS syntax to return the data you need.

Jim H.
There doesn't seem to be a way of filtering the result eg. WHERE Type = 'x'
JKJKJK
You can filter the results by the field name, but not by the type. However, since you can pull the results of SHOW COLUMNS out as if it were a SELECT query, you can just filter out the results in your code.
Rob Van Dam
A: 

I think it should work
SHOW TABLES; # Get list of all tables
DESC [EACH TABLE]; # and then check "Type" column

a1ex07
A: 

If you are using PHP you could use the following functions to gain information about specific fields in your tables.

mysql_field_type
mysql_fetch_field
mysql_field_len
mysql_field_flags

mysql_fetch_field gives you the most info.

To give you an example of how you might use it:

$SQLquery = 'SELECT * FROM '.$tableName;
$arr;
$field_array = array();
$res = mysql_query($SQLquery);

$numOfCols = mysql_num_fields($res);

for($y=0;$y<=($numOfCols-1);$y++)
{
    $fieldName1 =  mysql_field_name($res, $y);
    $field = mysql_fetch_field($res, $y);
    if($field->max_length < 6 && $field->numeric = true)
    {
      $field_array[] = $fieldName1;
    }
}

I realize this is not a MySql answer but I hope it helps if there is no way to get the info you need via MySql in 4.1

mmundiff