MSSQL_DIALECT读取表格字段时,出现重复现象 #787

Closed
opened 2017-12-01 01:40:56 +00:00 by guanfj · 3 comments
guanfj commented 2017-12-01 01:40:56 +00:00 (Migrated from github.com)

在使用该功能的时候,出现字段重复的现象,仔细研究一下,发现好象sql文写的不对,缺少条件,以及判断的条件不正确,下面是我修改的,可能不正确,但出现正确结果。请仔细研究一下。
func (db *mssql) GetColumns(tableName string) ([]string, map[string]*core.Column, error) {
args := []interface{}{}
s := select a.name as name, b.name as ctype,a.max_length,a.precision,a.scale,a.is_nullable as nullable, replace(replace(isnull(c.text,''),'(',''),')','') as vdefault, case when ISNULL( ic.column_id, 0 ) >0 then 1 else 0 end 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 left outer JOIN sys.indexes i ON i.object_id = a.object_id AND i.is_primary_key = 1 left outer join sys.index_columns ic on ic.object_id=a.object_id and ic.column_id=a.column_id and i.index_id=ic.index_id where a.object_id=object_id(' + tableName + ')
db.LogSQL(s, args)
........

在使用该功能的时候,出现字段重复的现象,仔细研究一下,发现好象sql文写的不对,缺少条件,以及判断的条件不正确,下面是我修改的,可能不正确,但出现正确结果。请仔细研究一下。 func (db *mssql) GetColumns(tableName string) ([]string, map[string]*core.Column, error) { args := []interface{}{} s := `select a.name as name, b.name as ctype,a.max_length,a.precision,a.scale,a.is_nullable as nullable, replace(replace(isnull(c.text,''),'(',''),')','') as vdefault, case when ISNULL( ic.column_id, 0 ) >0 then 1 else 0 end 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 left outer JOIN sys.indexes i ON i.object_id = a.object_id AND i.is_primary_key = 1 left outer join sys.index_columns ic on ic.object_id=a.object_id and ic.column_id=a.column_id and i.index_id=ic.index_id where a.object_id=object_id('` + tableName + `')` db.LogSQL(s, args) ........
guanfj commented 2017-12-02 01:06:11 +00:00 (Migrated from github.com)

还有一个问题,是自增列没有进行判断,即没有读取自增列的值,并赋给列结构

还有一个问题,是自增列没有进行判断,即没有读取自增列的值,并赋给列结构

#1203 will implement set auto-increment column 's value to struct field when insert a record.

#1203 will implement set auto-increment column 's value to struct field when insert a record.

Fixed by #1225

Fixed by #1225
lunny closed this issue 2020-03-13 09:03:31 +00:00
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: xorm/xorm#787
No description provided.