From 3cd69b0f1dc2432a54f318e51823a77e9faa8b8f Mon Sep 17 00:00:00 2001 From: loshiqi <553578653@qq.com> Date: Mon, 22 Dec 2025 16:53:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=9F=A5=E8=AF=A2=E5=85=B3?= =?UTF-8?q?=E9=97=AD=E9=A9=BC=E5=B3=B0=E5=BC=80=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chain.go | 9 +++++++-- db.go | 20 ++++++++++++++------ db_test.go | 4 ++-- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/chain.go b/chain.go index 1b7c415..456614e 100644 --- a/chain.go +++ b/chain.go @@ -35,6 +35,7 @@ type Query struct { stmt *sql.Stmt conn *sql.DB debug bool + close_hump bool dbtype string with [][]string //[[临时表的sql语句,临时表的名称]] } @@ -201,6 +202,10 @@ func (this *Query) Debug(debug bool) *Query { this.debug = debug 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) { _, 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 } @@ -1054,7 +1059,7 @@ func (this *Query) List() ([]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, - 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 } diff --git a/db.go b/db.go index d05144d..67e44c1 100644 --- a/db.go +++ b/db.go @@ -371,7 +371,7 @@ func GetData(dbName, table string, title string, where map[string]string, limit * @param dbName 数据表名 * @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 info := make(map[string]string) @@ -555,7 +555,9 @@ func GetRow(dbName, table_name, alias string, titles string, with, join [][]stri if rowerr == nil { for i, col := range scanArgs { if col != nil { - index = helper.StrFirstToUpper(strings.ToLower(columns[i])) + if !close_hump { + index = helper.StrFirstToUpper(strings.ToLower(columns[i])) + } info[index] = DmFormatDecimal(col) } } @@ -576,7 +578,9 @@ func GetRow(dbName, table_name, alias string, titles string, with, join [][]stri if rowerr == nil { for i, col := range values { if col != nil { - index = helper.StrFirstToUpper(columns[i]) + if !close_hump { + index = helper.StrFirstToUpper(columns[i]) + } info[index] = helper.ToString(col) } } @@ -601,7 +605,7 @@ func GetRow(dbName, table_name, alias string, titles string, with, join [][]stri * @param dbName 数据表名 * @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 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 { for i, col := range scanArgs { if col != nil { - index = helper.StrFirstToUpper(strings.ToLower(columns[i])) + if !close_hump { + index = helper.StrFirstToUpper(strings.ToLower(columns[i])) + } info[index] = DmFormatDecimal(col) } } @@ -826,7 +832,9 @@ func FetchRows(dbName, table_name, alias string, titles string, with, join [][]s if rowerr == nil { for i, col := range values { if col != nil { - index = helper.StrFirstToUpper(columns[i]) + if !close_hump { + index = helper.StrFirstToUpper(columns[i]) + } info[index] = helper.ToString(col) } } diff --git a/db_test.go b/db_test.go index 876f0d2..f99f62f 100644 --- a/db_test.go +++ b/db_test.go @@ -36,7 +36,7 @@ func Test_Connet(t *testing.T) { debug := true //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(row) @@ -75,7 +75,7 @@ func Test_Query(t *testing.T) { orderby := "" 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) log.Println(count)