Uploaded image for project: 'Torque'
  1. Torque
  2. TORQUE-368

MySQL/MariaDb Column Default not set in generated sql for empty string

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 5.1, 6.0
    • 7.0
    • Generator, Templates
    • None

    Description

      Example XML:

      <table name="feiertag" javaName="Holiday">
          <column name="id"           primaryKey="true"       type="INTEGER"                           required="true"/>
          <column name="datum"        javaName="Date"         type="BIGINT"                default="0"  required="true"/>
          <column name="name"         javaName="Name"         type="VARCHAR"   size="150"  default=""   required="true"/>
          <column name="zuschlag"     javaName="Bonus"        type="CHAR"      size="1"    default="N"  required="true"/>
          <column name="bundesland"   javaName="State"        type="VARCHAR"   size="2"    default=""   required="true"/>
      
          <unique name="dateunique"><unique-column name="datum"/></unique>
      </table> 

      Generates SQL:

      CREATE TABLE feiertag(    
          id INTEGER NOT NULL AUTO_INCREMENT,
          datum BIGINT default 0 NOT NULL,
          name VARCHAR(150) NOT NULL,
          zuschlag CHAR(1) default 'N' NOT NULL,
          bundesland VARCHAR(2) NOT NULL,
          PRIMARY KEY(id),
          UNIQUE dateunique (datum)
      ); 

      As you can see, the VARCHAR name and the VARCHAR bundesland are correctly defined a "NOT NULL". The 

      default=""

      is ignored.

      This wasn't a problem until NO_ENGINE_SUBSTITUTION was set as default in MySQL 5.6  & MariaDb 10.1.7 

      I wasn't able to find the corresponding generation for the DEFAULT value inside the template or the generator.

      Also: should we make this switchable, i.e. if default tag is present, always generate a DEFAULT or if default tag is present but empty, leave it out completely?

      Attachments

        Activity

          People

            mwriedt Max Philipp Wriedt
            mwriedt Max Philipp Wriedt
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: