resolved #450
This commit is contained in:
parent
5ae5bc982a
commit
4314d0d539
|
@ -330,9 +330,11 @@ func (db *mssql) TableCheckSql(tableName string) (string, []interface{}) {
|
||||||
|
|
||||||
func (db *mssql) GetColumns(tableName string) ([]string, map[string]*core.Column, error) {
|
func (db *mssql) GetColumns(tableName string) ([]string, map[string]*core.Column, error) {
|
||||||
args := []interface{}{}
|
args := []interface{}{}
|
||||||
s := `select a.name as name, b.name as ctype,a.max_length,a.precision,a.scale
|
s := `select a.name as name, b.name as ctype,a.max_length,a.precision,a.scale,a.is_nullable as nullable,
|
||||||
from sys.columns a left join sys.types b on a.user_type_id=b.user_type_id
|
replace(replace(isnull(c.text,''),'(',''),')','') as vdefault
|
||||||
where a.object_id=object_id('` + tableName + `')`
|
from sys.columns a left join sys.types b on a.user_type_id=b.user_type_id
|
||||||
|
left join sys.syscomments c on a.default_object_id=c.id
|
||||||
|
where a.object_id=object_id('` + tableName + `')`
|
||||||
db.LogSQL(s, args)
|
db.LogSQL(s, args)
|
||||||
|
|
||||||
rows, err := db.DB().Query(s, args...)
|
rows, err := db.DB().Query(s, args...)
|
||||||
|
@ -344,19 +346,26 @@ where a.object_id=object_id('` + tableName + `')`
|
||||||
cols := make(map[string]*core.Column)
|
cols := make(map[string]*core.Column)
|
||||||
colSeq := make([]string, 0)
|
colSeq := make([]string, 0)
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var name, ctype, precision, scale string
|
var name, ctype, vdefault string
|
||||||
var maxLen int
|
var maxLen, precision, scale int
|
||||||
err = rows.Scan(&name, &ctype, &maxLen, &precision, &scale)
|
var nullable bool
|
||||||
|
err = rows.Scan(&name, &ctype, &maxLen, &precision, &scale, &nullable, &vdefault)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
col := new(core.Column)
|
col := new(core.Column)
|
||||||
col.Indexes = make(map[string]int)
|
col.Indexes = make(map[string]int)
|
||||||
col.Length = maxLen
|
|
||||||
col.Name = strings.Trim(name, "` ")
|
col.Name = strings.Trim(name, "` ")
|
||||||
|
col.Nullable = nullable
|
||||||
|
col.Default = vdefault
|
||||||
ct := strings.ToUpper(ctype)
|
ct := strings.ToUpper(ctype)
|
||||||
|
if ct == "DECIMAL" {
|
||||||
|
col.Length = precision
|
||||||
|
col.Length2 = scale
|
||||||
|
} else {
|
||||||
|
col.Length = maxLen
|
||||||
|
}
|
||||||
switch ct {
|
switch ct {
|
||||||
case "DATETIMEOFFSET":
|
case "DATETIMEOFFSET":
|
||||||
col.SQLType = core.SQLType{core.TimeStampz, 0, 0}
|
col.SQLType = core.SQLType{core.TimeStampz, 0, 0}
|
||||||
|
@ -458,7 +467,7 @@ WHERE IXS.TYPE_DESC='NONCLUSTERED' and OBJECT_NAME(IXS.OBJECT_ID) =?
|
||||||
colName = strings.Trim(colName, "` ")
|
colName = strings.Trim(colName, "` ")
|
||||||
|
|
||||||
if strings.HasPrefix(indexName, "IDX_"+tableName) || strings.HasPrefix(indexName, "UQE_"+tableName) {
|
if strings.HasPrefix(indexName, "IDX_"+tableName) || strings.HasPrefix(indexName, "UQE_"+tableName) {
|
||||||
indexName = indexName[5+len(tableName) : len(indexName)]
|
indexName = indexName[5+len(tableName):]
|
||||||
}
|
}
|
||||||
|
|
||||||
var index *core.Index
|
var index *core.Index
|
||||||
|
|
Loading…
Reference in New Issue