@@ -59,7 +59,7 @@ func (x *Db) getDdl() ([]string, error) {
5959 ddls := make ([]string , 0 , len (list ))
6060 for _ , tableName := range list {
6161 result := map [string ]interface {}{}
62- if err := x .db .Raw (fmt .Sprintf ("SHOW CREATE TABLE %s " , tableName )).Scan (& result ).Error ; err != nil {
62+ if err := x .db .Raw (fmt .Sprintf ("SHOW CREATE TABLE `%s` " , tableName )).Scan (& result ).Error ; err != nil {
6363 return nil , fmt .Errorf ("获取表%s的结构失败: %w" , tableName , err )
6464 }
6565
@@ -101,7 +101,7 @@ func (x *Db) CheckSQL(sql string) error {
101101}
102102
103103// DoSQL 执行SQL查询并返回结果
104- func (x * Db ) DoSQL (sql string ) (res map [string ]interface {}, err error ) {
104+ func (x * Db ) DoSQL (sql string ) (res [] map [string ]interface {}, err error ) {
105105 // 创建只读事务
106106 ctx , cancel := context .WithTimeout (context .Background (), 10 * time .Second )
107107 defer cancel ()
@@ -117,7 +117,7 @@ func (x *Db) DoSQL(sql string) (res map[string]interface{}, err error) {
117117 tx .Set ("gorm:query_option" , "FOR READ ONLY" )
118118
119119 // 执行查询
120- res = map [string ]interface {}{}
120+ res = [] map [string ]interface {}{}
121121 if err = tx .Raw (sql ).Scan (& res ).Error ; err != nil {
122122 tx .Rollback ()
123123 return
0 commit comments