Imports System.Text Namespace Database.Mysql Public Class DataParam Enum DataTypeEnum '###############################数值类型############################# ''' ''' 1 byte,小整数值 ''' Tinyint ''' ''' 2 bytes,大整数值 ''' Smallint ''' ''' 3 bytes,大整数值 ''' Mediumint ''' ''' 4 bytes,大整数值 ''' Int ''' ''' 4 bytes,大整数值 ''' [Integer] ''' ''' 8 bytes,极大整数值 ''' Bigint ''' ''' 4 bytes,单精度浮点数值 ''' Float ''' ''' 8 bytes,双精度浮点数值 ''' [Double] '####################日期类型############################### ''' ''' 对DECIMAL(M,D) ,如果M>D,为M+2否则为D+2.小数值 ''' [Decimal] ''' ''' 3 bytes,日期值,YYYY-MM-DD ''' [Date] ''' ''' 3 bytes,时间值或持续时间,HH:MM:SS ''' Time ''' ''' 1 bytes,年份值,YYYY ''' Year ''' ''' 8 bytes,混合日期和时间值,YYYY-MM-DD HH:MM:SS ''' Datetime ''' ''' 4 bytes,混合日期和时间值,时间戳,YYYYMMDD HHMMSS ''' Timestamp '####################字符类型############################### ''' ''' 0-255 bytes,定长字符串 ''' [Char] ''' ''' 0-65535 bytes,变长字符串 ''' Varchar ''' ''' 0-255 bytes,不超过 255 个字符的二进制字符串 ''' Tinyblob ''' ''' 0-255 bytes,短文本字符串 ''' Tinytext ''' ''' 0-65 535 bytes,二进制形式的长文本数据 ''' Blob ''' ''' 0-65 535 bytes,长文本数据 ''' Text ''' ''' 0-16 777 215 bytes,二进制形式的中等长度文本数据 ''' Mediumblob ''' ''' 0-16 777 215 bytes,中等长度文本数据 ''' Mediumtext ''' ''' 0-4 294 967 295 bytes,二进制形式的极大文本数据 ''' Longblob ''' ''' 0-4 294 967 295 bytes,极大文本数据 ''' Longtext End Enum ''' ''' 列名 ''' ''' Public Property ColumnName() As String ''' ''' 当前值 ''' ''' Public Property Value() As String ''' ''' 默认值 ''' ''' Public Property DefaultValue() As String ''' ''' 数据类型 ''' ''' Public Property DataType() As DataTypeEnum ''' ''' 数据类型长度 ''' ''' Public Property DataTypeLength() As Integer ''' ''' 数据类型是否带符号 ''' ''' Public Property IsUnsigned() As Boolean ''' ''' 是否允许为空 ''' ''' Public Property IsNull() As Boolean = True ''' ''' 是否自动增长 ''' ''' Public Property IsAutoIncrement() As Boolean ''' ''' 是否为主键 ''' ''' Public Property IsPrimaryKey() As Boolean Public Function ToAddColString() As String Dim sb As New StringBuilder sb.Append($"`{ColumnName}`") Select Case DataType Case DataTypeEnum.Varchar,DataTypeEnum.[Char] sb.Append($" {DataType}({DataTypeLength}) ") Case DataTypeEnum.Int sb.Append($" {DataType}") if IsUnsigned Then sb.Append($" Unsigned") If IsAutoIncrement Then sb.Append($" AUTO_INCREMENT") Case Else sb.Append($" {DataType}") End Select sb.Append(IIf(IsNull, " Default Null", " Not Null")) If IsPrimaryKey Then sb.Append($" PRIMARY KEY") End If Return sb.ToString() End Function End Class End Namespace