Check the database schemas for common issues to improve portability

Created on 11 May 2012, over 12 years ago
Updated 26 June 2023, over 1 year ago

The SQLite driver doesn't respond well to compound primary keys, if one of the columns is a serial. Example from a module:

    'fields' => array(
      'id'  => array(
        'type' => 'serial',
        'not null' => TRUE,
        'description' => 'Entity id',
      ),
      'path'  => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'description' => 'The path of the page to apply meta tags to',
      ),
      'lang'  => array(
        'type' => 'varchar',
        'length' => 8,
        'not null' => TRUE,
        'description' => 'Language code',
      ),
    ),
  'primary key' => array('id', 'path', 'lang'),

While the usefulness of the above primary key is up for discussion, it is valid, and will work fine in MySOL. However, when SQLite generates the CREATE TABLE, it adds PRIMARY KEY to the field definition in createFieldSql, and removes it from the set. After that, if the primary key set is not empty, it adds a PRIMARY KEY definition to the CREATE TABLE, using the left over columns, causing SQLite to complain 'PDOException: SQLSTATE[HY000]: General error: 1 table "metatags_quick_path_based" has more than one primary key'.

While it's possible to work around, it does break the consistency of the Database API.

I discovered this problem with metatags_quick 2.4, but a quick search tells me that other modules have run into the same bug.

✨ Feature request
Status

Postponed: needs info

Version

9.5

Component
DatabaseΒ  β†’

Last updated 2 days ago

  • Maintained by
  • πŸ‡³πŸ‡±Netherlands @daffie
Created by

πŸ‡©πŸ‡°Denmark xen

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024