消除了报错:MySql.Data.MySqlClient.MySqlException:Fatal error encountered attempting to read the resultset,以便支持较新版本的MySql数据库。
2、完善读取MySql数据库的表列表和字段属性的脚本
SELECT table_name TableName,TABLE_COMMENT TableDescription
FROM INFORMATION_SCHEMA.TABLES WHERE table_type = ‘base table’
ORDER BY table_name
SELECT CASE ORDINAL_POSITION WHEN 1 THEN TABLE_NAME ELSE ” END TableName,
ORDINAL_POSITION 序,COLUMN_NAME ColumnName,
CASE EXTRA WHEN ‘AUTO_INCREMENT’ THEN ‘Y’ ELSE ” END IsIdentity,
case COLUMN_Key when ‘PRI’ then ‘Y’ else ” END PrimaryKey,
DATA_TYPE DataType,
CASE DATA_TYPE
WHEN ‘double’ THEN NUMERIC_PRECISION
WHEN ‘decimal’ THEN NUMERIC_PRECISION
WHEN ‘tinyint’ THEN NUMERIC_PRECISION
WHEN ‘int’ THEN NUMERIC_PRECISION
WHEN ‘bigint’ THEN NUMERIC_PRECISION
ELSE CASE WHEN CHARACTER_MAXIMUM_LENGTH IS NULL THEN 0 ELSE CHARACTER_MAXIMUM_LENGTH END
END ByteLength,
CASE DATA_TYPE
WHEN ‘double’ THEN NUMERIC_PRECISION
WHEN ‘decimal’ THEN NUMERIC_PRECISION
WHEN ‘tinyint’ THEN NUMERIC_PRECISION
WHEN ‘int’ THEN NUMERIC_PRECISION
WHEN ‘bigint’ THEN NUMERIC_PRECISION
ELSE CASE WHEN CHARACTER_MAXIMUM_LENGTH IS NULL THEN 0 ELSE CHARACTER_MAXIMUM_LENGTH END
END Length,
IFNULL(numeric_scale,”) IsNumeric,
CASE is_nullable WHEN ‘YES’ THEN ‘Y’ ELSE ” END AllowNull,
column_default DefaultValue,
COLUMN_COMMENT Description
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = ‘tableName ‘