Skip to content

Commit

Permalink
Merge pull request #14 from guriandoro/master
Browse files Browse the repository at this point in the history
Added support for 5.5 in information_schema.columns table parsing
  • Loading branch information
percona-csalguero authored Apr 20, 2018
2 parents 0eeaa98 + 96ec499 commit 9bf76f4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 34 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ This is an early stage project.
|timestamp|NOW() - 1 year ~ NOW()|
|time|00:00:00 ~ 23:59:59|
|year|Current year - 1 ~ current year|
|tinyblob|up to 100 chars random paragraph|
|tinytext|up to 100 chars random paragraph|
|blob|up to 100 chars random paragraph|
|text|up to 100 chars random paragraph|
|mediumblob|up to 100 chars random paragraph|
Expand Down
8 changes: 5 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ func makeValueFuncs(conn *sql.DB, fields []tableparser.Field) insertValues {
values = append(values, getters.NewRandomDate(field.ColumnName, field.IsNullable))
case "datetime", "timestamp":
values = append(values, getters.NewRandomDateTime(field.ColumnName, field.IsNullable))
case "blob", "text", "mediumtext", "mediumblob", "longblob", "longtext":
case "tinyblob", "tinytext", "blob", "text", "mediumtext", "mediumblob", "longblob", "longtext":
values = append(values, getters.NewRandomString(field.ColumnName,
field.CharacterMaximumLength.Int64, field.IsNullable))
case "time":
Expand Down Expand Up @@ -458,8 +458,8 @@ func getSamples(conn *sql.DB, schema, table, field string, samples int64, dataTy
var v int64
err = rows.Scan(&v)
val = v
case "char", "varchar", "varbinary", "blob", "text", "mediumtext",
"mediumblob", "longblob", "longtext":
case "char", "varchar", "varbinary", "tinyblob", "tinytext", "blob", "text",
"mediumtext", "mediumblob", "longblob", "longtext":
var v string
err = rows.Scan(&v)
val = v
Expand Down Expand Up @@ -508,6 +508,8 @@ func isSupportedType(fieldType string) bool {
"timestamp": true,
"time": true,
"year": true,
"tinyblob": true,
"tinytext": true,
"blob": true,
"text": true,
"mediumblob": true,
Expand Down
60 changes: 29 additions & 31 deletions tableparser/tableparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,37 +211,35 @@ func (t *Table) parse() error {
}

func makeScanRecipients(f *Field, allowNull *string, cols []string) []interface{} {
fields := []interface{}{
&f.TableCatalog,
&f.TableSchema,
&f.TableName,
&f.ColumnName,
&f.OrdinalPosition,
&f.ColumnDefault,
&allowNull,
&f.DataType,
&f.CharacterMaximumLength,
&f.CharacterOctetLength,
&f.NumericPrecision,
&f.NumericScale,
&f.DatetimePrecision,
&f.CharacterSetName,
&f.CollationName,
&f.ColumnType,
&f.ColumnKey,
&f.Extra,
&f.Privileges,
&f.ColumnComment,
}

if len(cols) > 20 && cols[20] == "GENERATION_EXPRESSION" { // MySQL 5.7+ "GENERATION_EXPRESSION" field
fields = append(fields, &f.GenerationExpression)
}
if len(cols) > 21 && cols[21] == "SRS_ID" { // MySQL 8.0+ "SRS ID" field
fields = append(fields, &f.SrsID)
}

return fields
fields := []interface{}{
&f.TableCatalog,
&f.TableSchema,
&f.TableName,
&f.ColumnName,
&f.OrdinalPosition,
&f.ColumnDefault,
&allowNull,
&f.DataType,
&f.CharacterMaximumLength,
&f.CharacterOctetLength,
&f.NumericPrecision,
&f.NumericScale,
}

if len(cols) > 19 { // MySQL 5.5 does not have "DATETIME_PRECISION" field
fields = append(fields, &f.DatetimePrecision)
}

fields = append(fields, &f.CharacterSetName, &f.CollationName, &f.ColumnType, &f.ColumnKey, &f.Extra, &f.Privileges, &f.ColumnComment)

if len(cols) > 20 && cols[20] == "GENERATION_EXPRESSION" { // MySQL 5.7+ "GENERATION_EXPRESSION" field
fields = append(fields, &f.GenerationExpression)
}
if len(cols) > 21 && cols[21] == "SRS_ID" { // MySQL 8.0+ "SRS ID" field
fields = append(fields, &f.SrsID)
}

return fields
}

// FieldNames returns an string array with the table's field names
Expand Down

0 comments on commit 9bf76f4

Please sign in to comment.