Fork me on GitHub

Creating an ENUM field using ADOdb->CreateTableSQL  Bottom

  • Has anyone out there tried to create an ENUM field in the database for his module? I'm running into problems with ADOdb not picking up my ENUM values when I run CreateTableSQL(). For instance:

    "pn_status enum ('active','inactive') NOTNULL DEFAULT 'active'"

    ...when fed to CreateTableSQL(), becomes...

    "pn_status ENUM NOT NULL DEFAULT 'active'"

    As you can see, it didn't correctly interpret the enum values. I'm fairly sure this is an issue with ADOdb 4.991 (included with Zikula 1.1.1); has anyone found a workaround? I suppose I could just create them as varchar fields and manually convert them to enum fields post-install, but that seems very kludgy.

    Thanks,

    Ben B.

    --
    --
    Ben Birney
    http://www.tilsontech.com/
    http://www.sophiasfall.com/
  • I am having the same problem with enum values. Any fix?
  • I never found one, AKA. I ended up altering my schema to use a regular VARCHAR type instead of ENUM, and restricting the values programmatically.

    --
    --
    Ben Birney
    http://www.tilsontech.com/
    http://www.sophiasfall.com/
  • I filed a bug for it here:

    http://code.zikula.org/core/ticket/1794

    In the meantime, you can try this tmp fix I have:

    in pntables.php, code as usual.

    in pninit.php, instead of using:

    DBUtil::createTable('Example');

    Use this:

    $SQL = "CREATE TABLE IF NOT EXISTS `zk_Example` (
    `pn_id` int(11) NOT NULL auto_increment,
    `pn_illustration_alignment` enum('yes','no') collate utf8_unicode_ci NOT NULL default 'yes',
    `pn_cr_date` datetime NOT NULL default '1970-01-01 00:00:00',
    `pn_cr_uid` int(11) NOT NULL default '0',
    `pn_lu_date` datetime NOT NULL default '1970-01-01 00:00:00',
    `pn_lu_uid` int(11) NOT NULL default '0',
    PRIMARY KEY (`pn_id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ";

    DBUtil::executeSQL($SQL);
  • Hey, there you go. Good workaround.

    --
    --
    Ben Birney
    http://www.tilsontech.com/
    http://www.sophiasfall.com/
  • IIRC ANSI SQL has no support for the 'ENUM' datatype. So this script would make your module MYSQL only (or at least SQL-dialect specific). In this case, if possible for your application of course, I would choose to store as boolean, and define constants in your module where 0 = INACTIVE and 1 = ACTIVE.

    --
    -- Teb
    -- Dutch Zikula Community


    Support questions in a Personal Message will be ignored. Use the forums at all times!
  • Yes, I am already aware that ENUM is proprietary to MySQL. For my purposes, this type suffices.

    Nevertheless, thanks Teb for pointing that out, in case anyone else might be interested in using ENUM.

This list is based on users active over the last 60 minutes.