From 0ad44c9990f5a5da6eb7ec1a8a8dfd6f36aaad91 Mon Sep 17 00:00:00 2001 From: guriandoro Date: Fri, 30 Mar 2018 17:27:09 -0300 Subject: [PATCH 1/3] Added support for 5.5 in information_schema.columns table parsing In 5.5, there is no DATETIME_PRECISION field in the information_schema.columns table. --- tableparser/tableparser.go | 60 ++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 31 deletions(-) diff --git a/tableparser/tableparser.go b/tableparser/tableparser.go index 568f4b3..031bf6c 100644 --- a/tableparser/tableparser.go +++ b/tableparser/tableparser.go @@ -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 From fac3ae449286317ff2dd7b36cae7e7f2a74d9ed9 Mon Sep 17 00:00:00 2001 From: guriandoro Date: Fri, 30 Mar 2018 18:24:59 -0300 Subject: [PATCH 2/3] Adding support for TINYBLOB and TINYTEXT Fixes issue #15 --- main.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 7d38d4b..acdfc0e 100644 --- a/main.go +++ b/main.go @@ -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": @@ -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 @@ -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, From 96ec499f3e443d9f47ace62f0b58bb407b058bc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=90=E3=82=8A=E3=81=82=E3=82=93=E3=81=A9=E3=82=8D?= Date: Fri, 30 Mar 2018 18:38:48 -0300 Subject: [PATCH 3/3] TINYBLOB and TINYTEXT are now supported --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 16c4fb7..51d5b49 100644 --- a/README.md +++ b/README.md @@ -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|