From 8fd0fd9c7b90409ffb79c2903468ce67e2008815 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 12 Apr 2017 23:36:46 +0800 Subject: [PATCH] refactors --- helpers.go | 12 +++--------- session_raw.go | 12 +++--------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/helpers.go b/helpers.go index 398ec679..324c5bea 100644 --- a/helpers.go +++ b/helpers.go @@ -452,7 +452,7 @@ func row2mapStr(rows *core.Rows, fields []string) (resultsMap map[string]string, return result, nil } -func txQuery2(tx *core.Tx, sqlStr string, params ...interface{}) (resultsSlice []map[string]string, err error) { +func txQuery2(tx *core.Tx, sqlStr string, params ...interface{}) ([]map[string]string, error) { rows, err := tx.Query(sqlStr, params...) if err != nil { return nil, err @@ -462,13 +462,8 @@ func txQuery2(tx *core.Tx, sqlStr string, params ...interface{}) (resultsSlice [ return rows2Strings(rows) } -func query2(db *core.DB, sqlStr string, params ...interface{}) (resultsSlice []map[string]string, err error) { - s, err := db.Prepare(sqlStr) - if err != nil { - return nil, err - } - defer s.Close() - rows, err := s.Query(params...) +func query2(db *core.DB, sqlStr string, params ...interface{}) ([]map[string]string, error) { + rows, err := db.Query(sqlStr, params...) if err != nil { return nil, err } @@ -602,7 +597,6 @@ func indexName(tableName, idxName string) string { } func getFlagForColumn(m map[string]bool, col *core.Column) (val bool, has bool) { - if len(m) == 0 { return false, false } diff --git a/session_raw.go b/session_raw.go index 587addef..44d2ba6d 100644 --- a/session_raw.go +++ b/session_raw.go @@ -86,19 +86,13 @@ func (session *Session) QueryString(sqlStr string, args ...interface{}) ([]map[s if session.IsAutoClose { defer session.Close() } - return session.query2(sqlStr, args...) -} -// ============================= -// for string -// ============================= -func (session *Session) query2(sqlStr string, paramStr ...interface{}) (resultsSlice []map[string]string, err error) { - session.queryPreprocess(&sqlStr, paramStr...) + session.queryPreprocess(&sqlStr, args...) if session.IsAutoCommit { - return query2(session.DB(), sqlStr, paramStr...) + return query2(session.DB(), sqlStr, args...) } - return txQuery2(session.Tx, sqlStr, paramStr...) + return txQuery2(session.Tx, sqlStr, args...) } // Execute sql