Browse Source

refactors

xormplus 8 years ago
parent
commit
546fb389a7
4 changed files with 11 additions and 24 deletions
  1. 3 9
      helpers.go
  2. 1 2
      session.go
  3. 6 12
      session_raw.go
  4. 1 1
      xorm.go

+ 3 - 9
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
 	}

+ 1 - 2
session.go

@@ -28,8 +28,7 @@ type Session struct {
 	IsAutoCommit           bool
 	IsCommitedOrRollbacked bool
 	IsSqlFunc              bool
-
-	IsAutoClose bool
+	IsAutoClose            bool
 
 	// Automatically reset the statement after operations that execute a SQL
 	// query such as Count(), Find(), Get(), ...

+ 6 - 12
session_raw.go

@@ -10,7 +10,7 @@ import (
 	"github.com/xormplus/core"
 )
 
-func (session *Session) query(sqlStr string, paramStr ...interface{}) (resultsSlice []map[string][]byte, err error) {
+func (session *Session) query(sqlStr string, paramStr ...interface{}) ([]map[string][]byte, error) {
 	session.queryPreprocess(&sqlStr, paramStr...)
 
 	if session.IsAutoCommit {
@@ -19,7 +19,7 @@ func (session *Session) query(sqlStr string, paramStr ...interface{}) (resultsSl
 	return session.txQuery(session.Tx, sqlStr, paramStr...)
 }
 
-func (session *Session) txQuery(tx *core.Tx, sqlStr string, params ...interface{}) (resultsSlice []map[string][]byte, err error) {
+func (session *Session) txQuery(tx *core.Tx, sqlStr string, params ...interface{}) ([]map[string][]byte, error) {
 	rows, err := tx.Query(sqlStr, params...)
 	if err != nil {
 		return nil, err
@@ -71,7 +71,7 @@ func (session *Session) innerQuery2(sqlStr string, params ...interface{}) ([]map
 }
 
 // Exec a raw sql and return records as []map[string][]byte
-func (session *Session) query1(sqlStr string, paramStr ...interface{}) (resultsSlice []map[string][]byte, err error) {
+func (session *Session) query1(sqlStr string, paramStr ...interface{}) ([]map[string][]byte, error) {
 	defer session.resetStatement()
 	if session.IsAutoClose {
 		defer session.Close()
@@ -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

+ 1 - 1
xorm.go

@@ -17,7 +17,7 @@ import (
 
 const (
 	// Version show the xorm's version
-	Version string = "0.6.2.0401"
+	Version string = "0.6.2.0412"
 )
 
 func regDrvsNDialects() bool {