Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for 5.5 in information_schema.columns table parsing #14

Merged
merged 3 commits into from
Apr 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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