Skip to content

Commit 9bf76f4

Browse files
Merge pull request #14 from guriandoro/master
Added support for 5.5 in information_schema.columns table parsing
2 parents 0eeaa98 + 96ec499 commit 9bf76f4

File tree

3 files changed

+36
-34
lines changed

3 files changed

+36
-34
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ This is an early stage project.
2727
|timestamp|NOW() - 1 year ~ NOW()|
2828
|time|00:00:00 ~ 23:59:59|
2929
|year|Current year - 1 ~ current year|
30+
|tinyblob|up to 100 chars random paragraph|
31+
|tinytext|up to 100 chars random paragraph|
3032
|blob|up to 100 chars random paragraph|
3133
|text|up to 100 chars random paragraph|
3234
|mediumblob|up to 100 chars random paragraph|

main.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ func makeValueFuncs(conn *sql.DB, fields []tableparser.Field) insertValues {
392392
values = append(values, getters.NewRandomDate(field.ColumnName, field.IsNullable))
393393
case "datetime", "timestamp":
394394
values = append(values, getters.NewRandomDateTime(field.ColumnName, field.IsNullable))
395-
case "blob", "text", "mediumtext", "mediumblob", "longblob", "longtext":
395+
case "tinyblob", "tinytext", "blob", "text", "mediumtext", "mediumblob", "longblob", "longtext":
396396
values = append(values, getters.NewRandomString(field.ColumnName,
397397
field.CharacterMaximumLength.Int64, field.IsNullable))
398398
case "time":
@@ -458,8 +458,8 @@ func getSamples(conn *sql.DB, schema, table, field string, samples int64, dataTy
458458
var v int64
459459
err = rows.Scan(&v)
460460
val = v
461-
case "char", "varchar", "varbinary", "blob", "text", "mediumtext",
462-
"mediumblob", "longblob", "longtext":
461+
case "char", "varchar", "varbinary", "tinyblob", "tinytext", "blob", "text",
462+
"mediumtext", "mediumblob", "longblob", "longtext":
463463
var v string
464464
err = rows.Scan(&v)
465465
val = v
@@ -508,6 +508,8 @@ func isSupportedType(fieldType string) bool {
508508
"timestamp": true,
509509
"time": true,
510510
"year": true,
511+
"tinyblob": true,
512+
"tinytext": true,
511513
"blob": true,
512514
"text": true,
513515
"mediumblob": true,

tableparser/tableparser.go

+29-31
Original file line numberDiff line numberDiff line change
@@ -211,37 +211,35 @@ func (t *Table) parse() error {
211211
}
212212

213213
func makeScanRecipients(f *Field, allowNull *string, cols []string) []interface{} {
214-
fields := []interface{}{
215-
&f.TableCatalog,
216-
&f.TableSchema,
217-
&f.TableName,
218-
&f.ColumnName,
219-
&f.OrdinalPosition,
220-
&f.ColumnDefault,
221-
&allowNull,
222-
&f.DataType,
223-
&f.CharacterMaximumLength,
224-
&f.CharacterOctetLength,
225-
&f.NumericPrecision,
226-
&f.NumericScale,
227-
&f.DatetimePrecision,
228-
&f.CharacterSetName,
229-
&f.CollationName,
230-
&f.ColumnType,
231-
&f.ColumnKey,
232-
&f.Extra,
233-
&f.Privileges,
234-
&f.ColumnComment,
235-
}
236-
237-
if len(cols) > 20 && cols[20] == "GENERATION_EXPRESSION" { // MySQL 5.7+ "GENERATION_EXPRESSION" field
238-
fields = append(fields, &f.GenerationExpression)
239-
}
240-
if len(cols) > 21 && cols[21] == "SRS_ID" { // MySQL 8.0+ "SRS ID" field
241-
fields = append(fields, &f.SrsID)
242-
}
243-
244-
return fields
214+
fields := []interface{}{
215+
&f.TableCatalog,
216+
&f.TableSchema,
217+
&f.TableName,
218+
&f.ColumnName,
219+
&f.OrdinalPosition,
220+
&f.ColumnDefault,
221+
&allowNull,
222+
&f.DataType,
223+
&f.CharacterMaximumLength,
224+
&f.CharacterOctetLength,
225+
&f.NumericPrecision,
226+
&f.NumericScale,
227+
}
228+
229+
if len(cols) > 19 { // MySQL 5.5 does not have "DATETIME_PRECISION" field
230+
fields = append(fields, &f.DatetimePrecision)
231+
}
232+
233+
fields = append(fields, &f.CharacterSetName, &f.CollationName, &f.ColumnType, &f.ColumnKey, &f.Extra, &f.Privileges, &f.ColumnComment)
234+
235+
if len(cols) > 20 && cols[20] == "GENERATION_EXPRESSION" { // MySQL 5.7+ "GENERATION_EXPRESSION" field
236+
fields = append(fields, &f.GenerationExpression)
237+
}
238+
if len(cols) > 21 && cols[21] == "SRS_ID" { // MySQL 8.0+ "SRS ID" field
239+
fields = append(fields, &f.SrsID)
240+
}
241+
242+
return fields
245243
}
246244

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

0 commit comments

Comments
 (0)