Gene
Gene

Reputation: 11

drupal schema type int length 3 but get int(10)

want to have a int(3) field. In drupal schema, define as:

'response_code' => array(
      'description' => 'The API response code',
      'type' => 'int',
      'length' => 3,
      'unsigned' => TRUE,
      'not null' => FALSE,
    ),

But it creates int(10) field in mysql database.

 CREATE TABLE `log` (
      `response_code` int(10) unsigned DEFAULT NULL,
    ) 

Upvotes: 1

Views: 393

Answers (1)

Femaref
Femaref

Reputation: 61437

length is for (var)chars, it is ignored for other types. You can use size to change the size of the int.

See https://api.drupal.org/api/drupal/includes%21database.inc/group/schemaapi/6 for more details.

Note: The number in int(3) specifies the size in bits, so you will be able to have a maximum of 2^2 -1 saved in there (int is signed in database). You'd need at least 11 bits to save http status codes.

Upvotes: 2

Related Questions