mirror of
https://gitee.com/johng/gf
synced 2026-07-08 22:40:30 +08:00
修复gf gen在sqlserver上的异常问题: 1. https://github.com/gogf/gf/issues/1722 2. https://github.com/gogf/gf/issues/1761 ```powershell > gf gen dao fetching tables failed: SELECT NAME FROM SYSOBJECTS WHERE XTYPE='U' AND STATUS >= 0 ORDER BY NAME: mssql: 对象名 'SYSOBJECTS' 无效。 1. SELECT NAME FROM SYSOBJECTS WHERE XTYPE='U' AND STATUS >= 0 ORDER BY NAME 2. mssql: 对象名 'SYSOBJECTS' 无效。 ``` 在SqlServer 2022已测试通过:  --------- Co-authored-by: hailaz <739476267@qq.com>
39 lines
965 B
Go
39 lines
965 B
Go
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
|
//
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
// If a copy of the MIT was not distributed with this file,
|
|
// You can obtain one at https://github.com/gogf/gf.
|
|
|
|
package mssql
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/gogf/gf/v2/database/gdb"
|
|
)
|
|
|
|
const (
|
|
tablesSqlTmp = `SELECT name FROM sys.objects WHERE type='U' AND is_ms_shipped = 0 ORDER BY name`
|
|
)
|
|
|
|
// Tables retrieves and returns the tables of current schema.
|
|
// It's mainly used in cli tool chain for automatically generating the models.
|
|
func (d *Driver) Tables(ctx context.Context, schema ...string) (tables []string, err error) {
|
|
var result gdb.Result
|
|
link, err := d.SlaveLink(schema...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
result, err = d.DoSelect(ctx, link, tablesSqlTmp)
|
|
if err != nil {
|
|
return
|
|
}
|
|
for _, m := range result {
|
|
for _, v := range m {
|
|
tables = append(tables, v.String())
|
|
}
|
|
}
|
|
return
|
|
}
|