mirror of
https://gitee.com/johng/gf
synced 2026-06-06 02:25:47 +08:00
Add tables method of MSSQL, Oracle and PgSQL
This commit is contained in:
@ -163,8 +163,22 @@ func (db *dbMssql) parseSql(sql string) string {
|
||||
}
|
||||
|
||||
// Tables retrieves and returns the tables of current schema.
|
||||
// TODO
|
||||
func (db *dbMssql) Tables(schema ...string) (tables []string, err error) {
|
||||
var result Result
|
||||
link, err := db.getSlave(schema...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result, err = db.doGetAll(link, `SELECT NAME FROM SYSOBJECTS WHERE XTYPE='U' AND STATUS >= 0 ORDER BY NAME`)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, m := range result {
|
||||
for _, v := range m {
|
||||
tables = append(tables, strings.ToLower(v.String()))
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@ -123,8 +123,18 @@ func (db *dbOracle) parseSql(sql string) string {
|
||||
}
|
||||
|
||||
// Tables retrieves and returns the tables of current schema.
|
||||
// TODO
|
||||
func (db *dbOracle) Tables(schema ...string) (tables []string, err error) {
|
||||
var result Result
|
||||
|
||||
result, err = db.doGetAll(nil, "SELECT TABLE_NAME FROM USER_TABLES ORDER BY TABLE_NAME")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, m := range result {
|
||||
for _, v := range m {
|
||||
tables = append(tables, strings.ToLower(v.String()))
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@ -62,8 +62,26 @@ func (db *dbPgsql) handleSqlBeforeExec(sql string) string {
|
||||
}
|
||||
|
||||
// Tables retrieves and returns the tables of current schema.
|
||||
// TODO
|
||||
func (db *dbPgsql) Tables(schema ...string) (tables []string, err error) {
|
||||
var result Result
|
||||
link, err := db.getSlave(schema...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
query := "SELECT TABLENAME FROM PG_TABLES WHERE SCHEMANAME = 'public' ORDER BY TABLENAME"
|
||||
if len(schema) > 0 && schema[0] != "" {
|
||||
query = fmt.Sprintf("SELECT TABLENAME FROM PG_TABLES WHERE SCHEMANAME = '%s' ORDER BY TABLENAME", schema[0])
|
||||
}
|
||||
result, err = db.doGetAll(link, query)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, m := range result {
|
||||
for _, v := range m {
|
||||
tables = append(tables, v.String())
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user