fraenky8 / tables-to-go

convert your database tables to structs easily
MIT License
233 stars 42 forks source link

MySQL 5.5: run error could not prepare the get-column-statement: Error 1054: Unknown column 'datetime_precision' in 'field list'% #2

Closed suzuken closed 6 years ago

suzuken commented 6 years ago

In MySQL 5.5, tables-to-go run failed because of datetime_precision is not exists.

running for "mysql"...
> number of tables: 513
run error could not prepare the get-column-statement: Error 1054: Unknown column 'datetime_precision' in 'field list'%

datetime_precision option is available from MySQL 5.6.4. https://dev.mysql.com/doc/refman/5.6/en/fractional-seconds.html

In tables-to-go, datetime_precision is not used yet (or, any plan to use it?). For supporting MySQL under 5.6, it can be fixed by removing from PrepareGetColumnsOfTableStmt.

// PrepareGetColumnsOfTableStmt prepares the statement for retrieving the columns of a specific table for a given database
func (mysql *mysql) PrepareGetColumnsOfTableStmt() (err error) {

    mysql.getColumnsOfTableStmt, err = mysql.db.Preparex(`
        SELECT
          ordinal_position,
          column_name,
          data_type,
          column_default,
          is_nullable,
          character_maximum_length,
          numeric_precision,
          datetime_precision,
          column_key,
          extra
        FROM information_schema.columns
        WHERE table_name = ?
        AND table_schema = ?
        ORDER BY ordinal_position
    `)

    return err
}