2 Commits

6 changed files with 30 additions and 10 deletions
Unified View
  1. +23
    -8
      chain.go
  2. +0
    -0
      conn.go
  3. +0
    -0
      db_test.go
  4. +0
    -0
      prepare.go
  5. +7
    -2
      sqlserver.go
  6. +0
    -0
      transaction.go

+ 23
- 8
chain.go View File

@ -179,7 +179,7 @@ func (this *Query) Clean() *Query {
return this return this
} }
//获取表格信息
// 获取表格信息
func (this *Query) GetTableInfo(table string) (map[string]interface{}, error) { func (this *Query) GetTableInfo(table string) (map[string]interface{}, error) {
field := []string{ field := []string{
"COLUMN_NAME", //字段名 "COLUMN_NAME", //字段名
@ -245,7 +245,7 @@ func (this *Query) GetTableInfo(table string) (map[string]interface{}, error) {
}, nil }, nil
} }
//构造子查询
// 构造子查询
func (this *Query) BuildSelectSql() (map[string]interface{}, error) { func (this *Query) BuildSelectSql() (map[string]interface{}, error) {
if this.dbname == "" && this.table == "" { if this.dbname == "" && this.table == "" {
return nil, errors.New("参数错误,没有数据表") return nil, errors.New("参数错误,没有数据表")
@ -266,12 +266,23 @@ func (this *Query) BuildSelectSql() (map[string]interface{}, error) {
} else { } else {
title = "*" title = "*"
} }
if DB_PROVIDER == "TencentDB" {
sql = helper.StringJoin("/*slave*/ select ", title)
if this.dbtype == "mssql" {
if this.page_size > 0 {
sql = helper.StringJoin("select top ", helper.ToStr(this.page_size), " ")
} else {
sql = "select "
}
} else { } else {
sql = helper.StringJoin("select ", title)
if DB_PROVIDER == "TencentDB" {
sql = "/*slave*/ select "
} else {
sql = "select "
}
} }
sql = helper.StringJoin(sql, title)
if this.alias != "" { if this.alias != "" {
table = helper.StringJoin(table, " as ", this.alias) table = helper.StringJoin(table, " as ", this.alias)
} }
@ -315,7 +326,7 @@ func (this *Query) BuildSelectSql() (map[string]interface{}, error) {
sql = helper.StringJoin(sql, " order by ", this.orderby) sql = helper.StringJoin(sql, " order by ", this.orderby)
} }
if this.page > 0 || this.page_size > 0 {
if this.dbtype == "mysql" && (this.page > 0 || this.page_size > 0) {
if this.page < 1 { if this.page < 1 {
this.page = 1 this.page = 1
@ -358,7 +369,11 @@ func (this *Query) QueryStmt() error {
if SLAVER_DB != nil { if SLAVER_DB != nil {
this.conn = SLAVER_DB this.conn = SLAVER_DB
} else {
}
// else {
// this.conn = DB
// }
if this.conn == nil {
this.conn = DB this.conn = DB
} }
@ -798,7 +813,7 @@ func (this *Query) Update() (int64, error) {
return StmtForUpdateExec(this.stmt, this.value) return StmtForUpdateExec(this.stmt, this.value)
} }
//批量更新
// 批量更新
func (this *Query) UpdateAll() (int64, error) { func (this *Query) UpdateAll() (int64, error) {
err := this.UpdateAllStmt() err := this.UpdateAllStmt()


+ 0
- 0
conn.go View File


+ 0
- 0
db_test.go View File


+ 0
- 0
prepare.go View File


+ 7
- 2
sqlserver.go View File

@ -15,7 +15,7 @@ import (
var MSDB_CONN *sql.DB var MSDB_CONN *sql.DB
func MSConnect(DBHOST, DBUSER, DBPWD, DBNAME, DBPORT string, conns ...int) error {
func MSConnect(DBHOST, DBUSER, DBPWD, DBNAME, DBPORT, encrypt string, conns ...int) error {
log.Println("msdb connectting...") log.Println("msdb connectting...")
@ -29,7 +29,12 @@ func MSConnect(DBHOST, DBUSER, DBPWD, DBNAME, DBPORT string, conns ...int) error
db_port, _ := strconv.Atoi(DBPORT) db_port, _ := strconv.Atoi(DBPORT)
connString := fmt.Sprintf("server=%s;port=%d;database=%s;user id=%s;password=%s", DBHOST, db_port, DBNAME, DBUSER, DBPWD)
params := "server=%s;port=%d;database=%s;user id=%s;password=%s"
if encrypt != "" {
params = params + ";encrypt=" + encrypt
}
connString := fmt.Sprintf(params, DBHOST, db_port, DBNAME, DBUSER, DBPWD)
log.Println(connString) log.Println(connString)


+ 0
- 0
transaction.go View File


Loading…
Cancel
Save