正在显示
4 个修改的文件
包含
48 行增加
和
3 行删除
| @@ -33,6 +33,7 @@ require ( | @@ -33,6 +33,7 @@ require ( | ||
| 33 | github.com/ajg/form v1.5.1 // indirect | 33 | github.com/ajg/form v1.5.1 // indirect |
| 34 | github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072 // indirect | 34 | github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072 // indirect |
| 35 | github.com/fatih/structs v1.1.0 // indirect | 35 | github.com/fatih/structs v1.1.0 // indirect |
| 36 | + github.com/go-sql-driver/mysql v1.7.1 // indirect | ||
| 36 | github.com/google/go-querystring v1.1.0 // indirect | 37 | github.com/google/go-querystring v1.1.0 // indirect |
| 37 | github.com/imkira/go-interpol v1.1.0 // indirect | 38 | github.com/imkira/go-interpol v1.1.0 // indirect |
| 38 | github.com/moul/http2curl v1.0.0 // indirect | 39 | github.com/moul/http2curl v1.0.0 // indirect |
| @@ -475,10 +475,16 @@ func (tableService *TableService) ValidExprSql(ctx *domain.Context, cmd *command | @@ -475,10 +475,16 @@ 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 | - tx := starrocks.DB.Exec(sql) | ||
| 479 | - if tx.Error != nil { | 478 | + //tx := starrocks.DB.Exec(sql) |
| 479 | + //if tx.Error != nil { | ||
| 480 | + // return map[string]string{ | ||
| 481 | + // "result": tx.Error.Error(), | ||
| 482 | + // }, nil | ||
| 483 | + //} | ||
| 484 | + err := starrocks.ExecOfficial(sql) | ||
| 485 | + if err != nil { | ||
| 480 | return map[string]string{ | 486 | return map[string]string{ |
| 481 | - "result": tx.Error.Error(), | 487 | + "result": err.Error(), |
| 482 | }, nil | 488 | }, nil |
| 483 | } | 489 | } |
| 484 | case domain.ExprModeExcelFunction: | 490 | case domain.ExprModeExcelFunction: |
| @@ -29,6 +29,9 @@ func Init() error { | @@ -29,6 +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 | //Test1() | 35 | //Test1() |
| 33 | return err | 36 | return err |
| 34 | } | 37 | } |
| 1 | +package starrocks | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "database/sql" | ||
| 5 | + _ "github.com/go-sql-driver/mysql" | ||
| 6 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/constant" | ||
| 7 | + "time" | ||
| 8 | +) | ||
| 9 | + | ||
| 10 | +var DBOfficial *sql.DB | ||
| 11 | + | ||
| 12 | +func InitDBOfficial() error { | ||
| 13 | + var err error | ||
| 14 | + DBOfficial, err = sql.Open("mysql", constant.STARROCKS_MYSQL_DATA_SOURCE) | ||
| 15 | + if err != nil { | ||
| 16 | + return err | ||
| 17 | + } | ||
| 18 | + // See "Important settings" section. | ||
| 19 | + DBOfficial.SetConnMaxLifetime(time.Minute * 3) | ||
| 20 | + DBOfficial.SetMaxOpenConns(2) | ||
| 21 | + DBOfficial.SetMaxIdleConns(2) | ||
| 22 | + return nil | ||
| 23 | +} | ||
| 24 | + | ||
| 25 | +func ExecOfficial(sql string) error { | ||
| 26 | + result, err := DBOfficial.Exec(sql) | ||
| 27 | + if err != nil { | ||
| 28 | + return err | ||
| 29 | + } | ||
| 30 | + _, err = result.RowsAffected() | ||
| 31 | + if err != nil { | ||
| 32 | + return err | ||
| 33 | + } | ||
| 34 | + return nil | ||
| 35 | +} |
-
请 注册 或 登录 后发表评论