Browse Source

增加查询关闭驼峰开关

master
loshiqi 5 hours ago
parent
commit
3cd69b0f1d
3 changed files with 23 additions and 10 deletions
  1. +7
    -2
      chain.go
  2. +14
    -6
      db.go
  3. +2
    -2
      db_test.go

+ 7
- 2
chain.go View File

@ -35,6 +35,7 @@ type Query struct {
stmt *sql.Stmt stmt *sql.Stmt
conn *sql.DB conn *sql.DB
debug bool debug bool
close_hump bool
dbtype string dbtype string
with [][]string //[[临时表的sql语句,临时表的名称]] with [][]string //[[临时表的sql语句,临时表的名称]]
} }
@ -201,6 +202,10 @@ func (this *Query) Debug(debug bool) *Query {
this.debug = debug this.debug = debug
return this return this
} }
func (this *Query) CloseHump(close_hump bool) *Query {
this.close_hump = close_hump
return this
}
/* /*
* 清理上次查询 * 清理上次查询
@ -1023,7 +1028,7 @@ func (this *Query) DeleteStmt() error {
func (this *Query) Select() ([]map[string]string, error) { func (this *Query) Select() ([]map[string]string, error) {
_, rows, err := FetchRows(this.dbname, this.table, this.alias, this.title, this.with, this.join, _, rows, err := FetchRows(this.dbname, this.table, this.alias, this.title, this.with, this.join,
this.where, this.where_or, this.value, this.orderby, this.groupby, this.having, this.page, this.page_size, this.debug)
this.where, this.where_or, this.value, this.orderby, this.groupby, this.having, this.page, this.page_size, this.debug, this.close_hump)
return rows, err return rows, err
} }
@ -1054,7 +1059,7 @@ func (this *Query) List() ([]map[string]string, error) {
func (this *Query) Find() (map[string]string, error) { func (this *Query) Find() (map[string]string, error) {
_, row, err := GetRow(this.dbname, this.table, this.alias, this.title, this.with, this.join, _, row, err := GetRow(this.dbname, this.table, this.alias, this.title, this.with, this.join,
this.where, this.where_or, this.value, this.orderby, this.groupby, this.having, this.debug)
this.where, this.where_or, this.value, this.orderby, this.groupby, this.having, this.debug, this.close_hump)
return row, err return row, err
} }


+ 14
- 6
db.go View File

@ -371,7 +371,7 @@ func GetData(dbName, table string, title string, where map[string]string, limit
* @param dbName 数据表名 * @param dbName 数据表名
* @param title 查询字段名 * @param title 查询字段名
*/ */
func GetRow(dbName, table_name, alias string, titles string, with, join [][]string, where, where_or []string, valueList []interface{}, orderby, groupby, having string, debug bool) (int, map[string]string, error) {
func GetRow(dbName, table_name, alias string, titles string, with, join [][]string, where, where_or []string, valueList []interface{}, orderby, groupby, having string, debug, close_hump bool) (int, map[string]string, error) {
var count int = 0 var count int = 0
info := make(map[string]string) info := make(map[string]string)
@ -555,7 +555,9 @@ func GetRow(dbName, table_name, alias string, titles string, with, join [][]stri
if rowerr == nil { if rowerr == nil {
for i, col := range scanArgs { for i, col := range scanArgs {
if col != nil { if col != nil {
index = helper.StrFirstToUpper(strings.ToLower(columns[i]))
if !close_hump {
index = helper.StrFirstToUpper(strings.ToLower(columns[i]))
}
info[index] = DmFormatDecimal(col) info[index] = DmFormatDecimal(col)
} }
} }
@ -576,7 +578,9 @@ func GetRow(dbName, table_name, alias string, titles string, with, join [][]stri
if rowerr == nil { if rowerr == nil {
for i, col := range values { for i, col := range values {
if col != nil { if col != nil {
index = helper.StrFirstToUpper(columns[i])
if !close_hump {
index = helper.StrFirstToUpper(columns[i])
}
info[index] = helper.ToString(col) info[index] = helper.ToString(col)
} }
} }
@ -601,7 +605,7 @@ func GetRow(dbName, table_name, alias string, titles string, with, join [][]stri
* @param dbName 数据表名 * @param dbName 数据表名
* @param title 查询字段名 * @param title 查询字段名
*/ */
func FetchRows(dbName, table_name, alias string, titles string, with, join [][]string, where, where_or []string, valueList []interface{}, orderby, groupby, having string, page int, page_size int, debug bool) (int, []map[string]string, error) {
func FetchRows(dbName, table_name, alias string, titles string, with, join [][]string, where, where_or []string, valueList []interface{}, orderby, groupby, having string, page int, page_size int, debug, close_hump bool) (int, []map[string]string, error) {
var count int = 0 var count int = 0
list := make([]map[string]string, 0) list := make([]map[string]string, 0)
@ -800,7 +804,9 @@ func FetchRows(dbName, table_name, alias string, titles string, with, join [][]s
if rowerr == nil { if rowerr == nil {
for i, col := range scanArgs { for i, col := range scanArgs {
if col != nil { if col != nil {
index = helper.StrFirstToUpper(strings.ToLower(columns[i]))
if !close_hump {
index = helper.StrFirstToUpper(strings.ToLower(columns[i]))
}
info[index] = DmFormatDecimal(col) info[index] = DmFormatDecimal(col)
} }
} }
@ -826,7 +832,9 @@ func FetchRows(dbName, table_name, alias string, titles string, with, join [][]s
if rowerr == nil { if rowerr == nil {
for i, col := range values { for i, col := range values {
if col != nil { if col != nil {
index = helper.StrFirstToUpper(columns[i])
if !close_hump {
index = helper.StrFirstToUpper(columns[i])
}
info[index] = helper.ToString(col) info[index] = helper.ToString(col)
} }
} }


+ 2
- 2
db_test.go View File

@ -36,7 +36,7 @@ func Test_Connet(t *testing.T) {
debug := true debug := true
//count, row, err := GetRow(dbname, table, alias, title, join, where, where_or, valueList, orderby, debug) //count, row, err := GetRow(dbname, table, alias, title, join, where, where_or, valueList, orderby, debug)
count, row, err := FetchRows(dbname, table, alias, title, join, join, where, where_or, valueList, orderby, "", "", 1, 10, debug)
count, row, err := FetchRows(dbname, table, alias, title, join, join, where, where_or, valueList, orderby, "", "", 1, 10, debug, false)
log.Println(count) log.Println(count)
log.Println(row) log.Println(row)
@ -75,7 +75,7 @@ func Test_Query(t *testing.T) {
orderby := "" orderby := ""
debug := true debug := true
count, row, err := GetRow(dbname, table, alias, title, [][]string{}, join, where, where_or, valueList, orderby, "", "", debug)
count, row, err := GetRow(dbname, table, alias, title, [][]string{}, join, where, where_or, valueList, orderby, "", "", debug, false)
//count, row, err := FetchRows(dbname, table, alias, title, join, join, where, where_or, valueList, orderby, "", "", 1, 10, debug) //count, row, err := FetchRows(dbname, table, alias, title, join, join, where, where_or, valueList, orderby, "", "", 1, 10, debug)
log.Println(count) log.Println(count)


Loading…
Cancel
Save