作者 yangfu

修改starrocks 查询驱动

@@ -475,12 +475,18 @@ func (tableService *TableService) ValidExprSql(ctx *domain.Context, cmd *command @@ -475,12 +475,18 @@ func (tableService *TableService) ValidExprSql(ctx *domain.Context, cmd *command
475 sql += " from " + strings.Join(set.KeysStr(), ",") 475 sql += " from " + strings.Join(set.KeysStr(), ",")
476 sql += " limit 1" 476 sql += " limit 1"
477 } 477 }
478 - err := starrocks.ExecOfficial(sql)  
479 - if err != nil { 478 + tx := starrocks.DB.Exec(sql)
  479 + if tx.Error != nil {
480 return map[string]string{ 480 return map[string]string{
481 - "result": err.Error(), 481 + "result": tx.Error.Error(),
482 }, nil 482 }, nil
483 } 483 }
  484 + //err := starrocks.ExecOfficial(sql)
  485 + //if err != nil {
  486 + // return map[string]string{
  487 + // "result": err.Error(),
  488 + // }, nil
  489 + //}
484 case domain.ExprModeExcelFunction: 490 case domain.ExprModeExcelFunction:
485 _, err := astexpr.NewExprAST(cmd.ExprSql) 491 _, err := astexpr.NewExprAST(cmd.ExprSql)
486 if err != nil { 492 if err != nil {
@@ -29,9 +29,9 @@ func Init() error { @@ -29,9 +29,9 @@ func Init() error {
29 ) 29 )
30 DB, err = gorm.Open(mysql.Open(constant.STARROCKS_MYSQL_DATA_SOURCE), &gorm.Config{Logger: newLogger, PrepareStmt: false}) 30 DB, err = gorm.Open(mysql.Open(constant.STARROCKS_MYSQL_DATA_SOURCE), &gorm.Config{Logger: newLogger, PrepareStmt: false})
31 31
32 - if err = InitDBOfficial(); err != nil {  
33 - return err  
34 - } 32 + //if err = InitDBOfficial(); err != nil {
  33 + // return err
  34 + //}
35 //Test1() 35 //Test1()
36 return err 36 return err
37 } 37 }
1 package starrocks 1 package starrocks
2 2
3 -import (  
4 - "database/sql"  
5 - "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/constant"  
6 - "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/log"  
7 - "time"  
8 -)  
9 -  
10 -var DBOfficial *sql.DB  
11 -  
12 -func InitDBOfficial() error {  
13 - var err error  
14 - //sql.Register("mysql-star", &mysql.MySQLDriver{})  
15 - DBOfficial, err = sql.Open("mysql", constant.STARROCKS_MYSQL_DATA_SOURCE)  
16 - if err != nil {  
17 - return err  
18 - }  
19 - // See "Important settings" section.  
20 - DBOfficial.SetConnMaxLifetime(time.Minute * 3)  
21 - DBOfficial.SetMaxOpenConns(2)  
22 - DBOfficial.SetMaxIdleConns(2)  
23 - return nil  
24 -}  
25 -  
26 -func ExecOfficial(sql string) error {  
27 - log.Logger.Debug(sql)  
28 - result, err := DBOfficial.Exec(sql)  
29 - if err != nil {  
30 - log.Logger.Error("exec error", map[string]interface{}{"err": err.Error()})  
31 - return err  
32 - }  
33 - _, err = result.RowsAffected()  
34 - if err != nil {  
35 - log.Logger.Error("result error", map[string]interface{}{"result": err.Error()})  
36 - return err  
37 - }  
38 - return nil  
39 -} 3 +//import (
  4 +// "database/sql"
  5 +// "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/constant"
  6 +// "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/log"
  7 +// "time"
  8 +//)
  9 +//
  10 +//var DBOfficial *sql.DB
  11 +//
  12 +//func InitDBOfficial() error {
  13 +// var err error
  14 +// //sql.Register("mysql-star", &mysql.MySQLDriver{})
  15 +// DBOfficial, err = sql.Open("mysql", constant.STARROCKS_MYSQL_DATA_SOURCE)
  16 +// if err != nil {
  17 +// return err
  18 +// }
  19 +// // See "Important settings" section.
  20 +// DBOfficial.SetConnMaxLifetime(time.Minute * 3)
  21 +// DBOfficial.SetMaxOpenConns(2)
  22 +// DBOfficial.SetMaxIdleConns(2)
  23 +// return nil
  24 +//}
  25 +//
  26 +//func ExecOfficial(sql string) error {
  27 +// log.Logger.Debug(sql)
  28 +// result, err := DBOfficial.Exec(sql)
  29 +// if err != nil {
  30 +// log.Logger.Error("exec error", map[string]interface{}{"err": err.Error()})
  31 +// return err
  32 +// }
  33 +// _, err = result.RowsAffected()
  34 +// if err != nil {
  35 +// log.Logger.Error("result error", map[string]interface{}{"result": err.Error()})
  36 +// return err
  37 +// }
  38 +// return nil
  39 +//}