Browse Source

Use created & updated instead BeforeInsert & BeforeUpdate (#2482)

* use created & updated instead BeforeInsert & BeforeUpdate

* fix vendor checksum

* only show generated SQL when development mode

* remove extra update column updated_unix

* remove trace config
Lunny Xiao 2 years ago
parent
commit
005900baea
48 changed files with 481 additions and 679 deletions
  1. 1 7
      models/action.go
  2. 1 6
      models/admin.go
  3. 1 6
      models/attachment.go
  4. 2 13
      models/branches.go
  5. 2 10
      models/issue.go
  6. 2 14
      models/issue_comment.go
  7. 3 7
      models/lfs.go
  8. 2 13
      models/login_source.go
  9. 1 0
      models/models.go
  10. 2 13
      models/repo.go
  11. 12 4
      models/repo_mirror.go
  12. 8 28
      models/ssh_key.go
  13. 2 13
      models/status.go
  14. 2 12
      models/token.go
  15. 2 12
      models/twofactor.go
  16. 1 0
      models/unit_tests.go
  17. 2 10
      models/user.go
  18. 2 15
      models/webhook.go
  19. 3 2
      vendor/github.com/go-xorm/core/type.go
  20. 1 1
      vendor/github.com/go-xorm/xorm/README.md
  21. 12 22
      vendor/github.com/go-xorm/xorm/cache_lru.go
  22. 10 1
      vendor/github.com/go-xorm/xorm/circle.yml
  23. 12 0
      vendor/github.com/go-xorm/xorm/convert.go
  24. 3 0
      vendor/github.com/go-xorm/xorm/dialect_postgres.go
  25. 1 1
      vendor/github.com/go-xorm/xorm/doc.go
  26. 7 30
      vendor/github.com/go-xorm/xorm/engine.go
  27. 5 36
      vendor/github.com/go-xorm/xorm/rows.go
  28. 2 12
      vendor/github.com/go-xorm/xorm/session.go
  29. 3 8
      vendor/github.com/go-xorm/xorm/session_convert.go
  30. 16 18
      vendor/github.com/go-xorm/xorm/session_delete.go
  31. 3 13
      vendor/github.com/go-xorm/xorm/session_exist.go
  32. 18 28
      vendor/github.com/go-xorm/xorm/session_find.go
  33. 25 32
      vendor/github.com/go-xorm/xorm/session_get.go
  34. 16 19
      vendor/github.com/go-xorm/xorm/session_insert.go
  35. 4 0
      vendor/github.com/go-xorm/xorm/session_iterate.go
  36. 177 0
      vendor/github.com/go-xorm/xorm/session_query.go
  37. 80 204
      vendor/github.com/go-xorm/xorm/session_raw.go
  38. 3 22
      vendor/github.com/go-xorm/xorm/session_schema.go
  39. 3 23
      vendor/github.com/go-xorm/xorm/session_stats.go
  40. 15 16
      vendor/github.com/go-xorm/xorm/session_update.go
  41. 2 1
      vendor/github.com/go-xorm/xorm/statement.go
  42. 1 0
      vendor/github.com/go-xorm/xorm/test_mssql_cache.sh
  43. 1 0
      vendor/github.com/go-xorm/xorm/test_mymysql_cache.sh
  44. 1 0
      vendor/github.com/go-xorm/xorm/test_mysql_cache.sh
  45. 1 0
      vendor/github.com/go-xorm/xorm/test_postgres_cache.sh
  46. 1 0
      vendor/github.com/go-xorm/xorm/test_sqlite_cache.sh
  47. 1 1
      vendor/github.com/go-xorm/xorm/xorm.go
  48. 6 6
      vendor/vendor.json

+ 1 - 7
models/action.go

@@ -86,13 +86,7 @@ type Action struct {
86 86
 	IsPrivate   bool      `xorm:"INDEX NOT NULL DEFAULT false"`
87 87
 	Content     string    `xorm:"TEXT"`
88 88
 	Created     time.Time `xorm:"-"`
89
-	CreatedUnix int64     `xorm:"INDEX"`
90
-}
91
-
92
-// BeforeInsert will be invoked by XORM before inserting a record
93
-// representing this object.
94
-func (a *Action) BeforeInsert() {
95
-	a.CreatedUnix = time.Now().Unix()
89
+	CreatedUnix int64     `xorm:"INDEX created"`
96 90
 }
97 91
 
98 92
 // AfterSet updates the webhook object upon setting a column.

+ 1 - 6
models/admin.go

@@ -29,12 +29,7 @@ type Notice struct {
29 29
 	Type        NoticeType
30 30
 	Description string    `xorm:"TEXT"`
31 31
 	Created     time.Time `xorm:"-"`
32
-	CreatedUnix int64     `xorm:"INDEX"`
33
-}
34
-
35
-// BeforeInsert is invoked from XORM before inserting an object of this type.
36
-func (n *Notice) BeforeInsert() {
37
-	n.CreatedUnix = time.Now().Unix()
32
+	CreatedUnix int64     `xorm:"INDEX created"`
38 33
 }
39 34
 
40 35
 // AfterSet is invoked from XORM after setting the value of a field of this object.

+ 1 - 6
models/attachment.go

@@ -28,12 +28,7 @@ type Attachment struct {
28 28
 	Name          string
29 29
 	DownloadCount int64     `xorm:"DEFAULT 0"`
30 30
 	Created       time.Time `xorm:"-"`
31
-	CreatedUnix   int64
32
-}
33
-
34
-// BeforeInsert is invoked from XORM before inserting an object of this type.
35
-func (a *Attachment) BeforeInsert() {
36
-	a.CreatedUnix = time.Now().Unix()
31
+	CreatedUnix   int64     `xorm:"created"`
37 32
 }
38 33
 
39 34
 // AfterSet is invoked from XORM after setting the value of a field of

+ 2 - 13
models/branches.go

@@ -22,20 +22,9 @@ type ProtectedBranch struct {
22 22
 	BranchName  string `xorm:"UNIQUE(s)"`
23 23
 	CanPush     bool
24 24
 	Created     time.Time `xorm:"-"`
25
-	CreatedUnix int64
25
+	CreatedUnix int64     `xorm:"created"`
26 26
 	Updated     time.Time `xorm:"-"`
27
-	UpdatedUnix int64
28
-}
29
-
30
-// BeforeInsert before protected branch insert create and update time
31
-func (protectBranch *ProtectedBranch) BeforeInsert() {
32
-	protectBranch.CreatedUnix = time.Now().Unix()
33
-	protectBranch.UpdatedUnix = protectBranch.CreatedUnix
34
-}
35
-
36
-// BeforeUpdate before protected branch update time
37
-func (protectBranch *ProtectedBranch) BeforeUpdate() {
38
-	protectBranch.UpdatedUnix = time.Now().Unix()
27
+	UpdatedUnix int64     `xorm:"updated"`
39 28
 }
40 29
 
41 30
 // GetProtectedBranchByRepoID getting protected branch by repo ID

+ 2 - 10
models/issue.go

@@ -54,23 +54,16 @@ type Issue struct {
54 54
 	Deadline     time.Time `xorm:"-"`
55 55
 	DeadlineUnix int64     `xorm:"INDEX"`
56 56
 	Created      time.Time `xorm:"-"`
57
-	CreatedUnix  int64     `xorm:"INDEX"`
57
+	CreatedUnix  int64     `xorm:"INDEX created"`
58 58
 	Updated      time.Time `xorm:"-"`
59
-	UpdatedUnix  int64     `xorm:"INDEX"`
59
+	UpdatedUnix  int64     `xorm:"INDEX updated"`
60 60
 
61 61
 	Attachments []*Attachment `xorm:"-"`
62 62
 	Comments    []*Comment    `xorm:"-"`
63 63
 }
64 64
 
65
-// BeforeInsert is invoked from XORM before inserting an object of this type.
66
-func (issue *Issue) BeforeInsert() {
67
-	issue.CreatedUnix = time.Now().Unix()
68
-	issue.UpdatedUnix = issue.CreatedUnix
69
-}
70
-
71 65
 // BeforeUpdate is invoked from XORM before updating this object.
72 66
 func (issue *Issue) BeforeUpdate() {
73
-	issue.UpdatedUnix = time.Now().Unix()
74 67
 	issue.DeadlineUnix = issue.Deadline.Unix()
75 68
 }
76 69
 
@@ -581,7 +574,6 @@ func (issue *Issue) ReadBy(userID int64) error {
581 574
 }
582 575
 
583 576
 func updateIssueCols(e Engine, issue *Issue, cols ...string) error {
584
-	cols = append(cols, "updated_unix")
585 577
 	if _, err := e.Id(issue.ID).Cols(cols...).Update(issue); err != nil {
586 578
 		return err
587 579
 	}

+ 2 - 14
models/issue_comment.go

@@ -99,9 +99,9 @@ type Comment struct {
99 99
 	RenderedContent string `xorm:"-"`
100 100
 
101 101
 	Created     time.Time `xorm:"-"`
102
-	CreatedUnix int64     `xorm:"INDEX"`
102
+	CreatedUnix int64     `xorm:"INDEX created"`
103 103
 	Updated     time.Time `xorm:"-"`
104
-	UpdatedUnix int64     `xorm:"INDEX"`
104
+	UpdatedUnix int64     `xorm:"INDEX updated"`
105 105
 
106 106
 	// Reference issue in commit message
107 107
 	CommitSHA string `xorm:"VARCHAR(40)"`
@@ -112,18 +112,6 @@ type Comment struct {
112 112
 	ShowTag CommentTag `xorm:"-"`
113 113
 }
114 114
 
115
-// BeforeInsert will be invoked by XORM before inserting a record
116
-// representing this object.
117
-func (c *Comment) BeforeInsert() {
118
-	c.CreatedUnix = time.Now().Unix()
119
-	c.UpdatedUnix = c.CreatedUnix
120
-}
121
-
122
-// BeforeUpdate is invoked from XORM before updating this object.
123
-func (c *Comment) BeforeUpdate() {
124
-	c.UpdatedUnix = time.Now().Unix()
125
-}
126
-
127 115
 // AfterSet is invoked from XORM after setting the value of a field of this object.
128 116
 func (c *Comment) AfterSet(colName string, _ xorm.Cell) {
129 117
 	var err error

+ 3 - 7
models/lfs.go

@@ -2,8 +2,9 @@ package models
2 2
 
3 3
 import (
4 4
 	"errors"
5
-	"github.com/go-xorm/xorm"
6 5
 	"time"
6
+
7
+	"github.com/go-xorm/xorm"
7 8
 )
8 9
 
9 10
 // LFSMetaObject stores metadata for LFS tracked files.
@@ -14,7 +15,7 @@ type LFSMetaObject struct {
14 15
 	RepositoryID int64     `xorm:"UNIQUE(s) INDEX NOT NULL"`
15 16
 	Existing     bool      `xorm:"-"`
16 17
 	Created      time.Time `xorm:"-"`
17
-	CreatedUnix  int64
18
+	CreatedUnix  int64     `xorm:"created"`
18 19
 }
19 20
 
20 21
 // LFSTokenResponse defines the JSON structure in which the JWT token is stored.
@@ -108,11 +109,6 @@ func RemoveLFSMetaObjectByOid(oid string) error {
108 109
 	return sess.Commit()
109 110
 }
110 111
 
111
-// BeforeInsert sets the time at which the LFSMetaObject was created.
112
-func (m *LFSMetaObject) BeforeInsert() {
113
-	m.CreatedUnix = time.Now().Unix()
114
-}
115
-
116 112
 // AfterSet stores the LFSMetaObject creation time in the database as local time.
117 113
 func (m *LFSMetaObject) AfterSet(colName string, _ xorm.Cell) {
118 114
 	switch colName {

+ 2 - 13
models/login_source.go

@@ -148,20 +148,9 @@ type LoginSource struct {
148 148
 	Cfg           core.Conversion `xorm:"TEXT"`
149 149
 
150 150
 	Created     time.Time `xorm:"-"`
151
-	CreatedUnix int64     `xorm:"INDEX"`
151
+	CreatedUnix int64     `xorm:"INDEX created"`
152 152
 	Updated     time.Time `xorm:"-"`
153
-	UpdatedUnix int64     `xorm:"INDEX"`
154
-}
155
-
156
-// BeforeInsert is invoked from XORM before inserting an object of this type.
157
-func (source *LoginSource) BeforeInsert() {
158
-	source.CreatedUnix = time.Now().Unix()
159
-	source.UpdatedUnix = source.CreatedUnix
160
-}
161
-
162
-// BeforeUpdate is invoked from XORM before updating this object.
163
-func (source *LoginSource) BeforeUpdate() {
164
-	source.UpdatedUnix = time.Now().Unix()
153
+	UpdatedUnix int64     `xorm:"INDEX updated"`
165 154
 }
166 155
 
167 156
 // Cell2Int64 converts a xorm.Cell type to int64,

+ 1 - 0
models/models.go

@@ -241,6 +241,7 @@ func NewTestEngine(x *xorm.Engine) (err error) {
241 241
 
242 242
 	x.SetMapper(core.GonicMapper{})
243 243
 	x.SetLogger(log.XORMLogger)
244
+	x.ShowSQL(!setting.ProdMode)
244 245
 	return x.StoreEngine("InnoDB").Sync2(tables...)
245 246
 }
246 247
 

+ 2 - 13
models/repo.go

@@ -211,20 +211,9 @@ type Repository struct {
211 211
 	Size     int64       `xorm:"NOT NULL DEFAULT 0"`
212 212
 
213 213
 	Created     time.Time `xorm:"-"`
214
-	CreatedUnix int64     `xorm:"INDEX"`
214
+	CreatedUnix int64     `xorm:"INDEX created"`
215 215
 	Updated     time.Time `xorm:"-"`
216
-	UpdatedUnix int64     `xorm:"INDEX"`
217
-}
218
-
219
-// BeforeInsert is invoked from XORM before inserting an object of this type.
220
-func (repo *Repository) BeforeInsert() {
221
-	repo.CreatedUnix = time.Now().Unix()
222
-	repo.UpdatedUnix = repo.CreatedUnix
223
-}
224
-
225
-// BeforeUpdate is invoked from XORM before updating this object.
226
-func (repo *Repository) BeforeUpdate() {
227
-	repo.UpdatedUnix = time.Now().Unix()
216
+	UpdatedUnix int64     `xorm:"INDEX updated"`
228 217
 }
229 218
 
230 219
 // AfterSet is invoked from XORM after setting the value of a field of this object.

+ 12 - 4
models/repo_mirror.go

@@ -40,18 +40,26 @@ type Mirror struct {
40 40
 
41 41
 // BeforeInsert will be invoked by XORM before inserting a record
42 42
 func (m *Mirror) BeforeInsert() {
43
-	m.UpdatedUnix = time.Now().Unix()
44
-	m.NextUpdateUnix = m.NextUpdate.Unix()
43
+	if m != nil {
44
+		m.UpdatedUnix = time.Now().Unix()
45
+		m.NextUpdateUnix = m.NextUpdate.Unix()
46
+	}
45 47
 }
46 48
 
47 49
 // BeforeUpdate is invoked from XORM before updating this object.
48 50
 func (m *Mirror) BeforeUpdate() {
49
-	m.UpdatedUnix = time.Now().Unix()
50
-	m.NextUpdateUnix = m.NextUpdate.Unix()
51
+	if m != nil {
52
+		m.UpdatedUnix = time.Now().Unix()
53
+		m.NextUpdateUnix = m.NextUpdate.Unix()
54
+	}
51 55
 }
52 56
 
53 57
 // AfterSet is invoked from XORM after setting the value of a field of this object.
54 58
 func (m *Mirror) AfterSet(colName string, _ xorm.Cell) {
59
+	if m == nil {
60
+		return
61
+	}
62
+
55 63
 	var err error
56 64
 	switch colName {
57 65
 	case "repo_id":

+ 8 - 28
models/ssh_key.go

@@ -55,21 +55,11 @@ type PublicKey struct {
55 55
 	Type        KeyType    `xorm:"NOT NULL DEFAULT 1"`
56 56
 
57 57
 	Created           time.Time `xorm:"-"`
58
-	CreatedUnix       int64
58
+	CreatedUnix       int64     `xorm:"created"`
59 59
 	Updated           time.Time `xorm:"-"` // Note: Updated must below Created for AfterSet.
60
-	UpdatedUnix       int64
61
-	HasRecentActivity bool `xorm:"-"`
62
-	HasUsed           bool `xorm:"-"`
63
-}
64
-
65
-// BeforeInsert will be invoked by XORM before inserting a record
66
-func (key *PublicKey) BeforeInsert() {
67
-	key.CreatedUnix = time.Now().Unix()
68
-}
69
-
70
-// BeforeUpdate is invoked from XORM before updating this object.
71
-func (key *PublicKey) BeforeUpdate() {
72
-	key.UpdatedUnix = time.Now().Unix()
60
+	UpdatedUnix       int64     `xorm:"updated"`
61
+	HasRecentActivity bool      `xorm:"-"`
62
+	HasUsed           bool      `xorm:"-"`
73 63
 }
74 64
 
75 65
 // AfterSet is invoked from XORM after setting the value of a field of this object.
@@ -633,21 +623,11 @@ type DeployKey struct {
633 623
 	Content     string `xorm:"-"`
634 624
 
635 625
 	Created           time.Time `xorm:"-"`
636
-	CreatedUnix       int64
626
+	CreatedUnix       int64     `xorm:"created"`
637 627
 	Updated           time.Time `xorm:"-"` // Note: Updated must below Created for AfterSet.
638
-	UpdatedUnix       int64
639
-	HasRecentActivity bool `xorm:"-"`
640
-	HasUsed           bool `xorm:"-"`
641
-}
642
-
643
-// BeforeInsert will be invoked by XORM before inserting a record
644
-func (key *DeployKey) BeforeInsert() {
645
-	key.CreatedUnix = time.Now().Unix()
646
-}
647
-
648
-// BeforeUpdate is invoked from XORM before updating this object.
649
-func (key *DeployKey) BeforeUpdate() {
650
-	key.UpdatedUnix = time.Now().Unix()
628
+	UpdatedUnix       int64     `xorm:"updated"`
629
+	HasRecentActivity bool      `xorm:"-"`
630
+	HasUsed           bool      `xorm:"-"`
651 631
 }
652 632
 
653 633
 // AfterSet is invoked from XORM after setting the value of a field of this object.

+ 2 - 13
models/status.go

@@ -66,20 +66,9 @@ type CommitStatus struct {
66 66
 	CreatorID   int64
67 67
 
68 68
 	Created     time.Time `xorm:"-"`
69
-	CreatedUnix int64     `xorm:"INDEX"`
69
+	CreatedUnix int64     `xorm:"INDEX created"`
70 70
 	Updated     time.Time `xorm:"-"`
71
-	UpdatedUnix int64     `xorm:"INDEX"`
72
-}
73
-
74
-// BeforeInsert is invoked from XORM before inserting an object of this type.
75
-func (status *CommitStatus) BeforeInsert() {
76
-	status.CreatedUnix = time.Now().Unix()
77
-	status.UpdatedUnix = status.CreatedUnix
78
-}
79
-
80
-// BeforeUpdate is invoked from XORM before updating this object.
81
-func (status *CommitStatus) BeforeUpdate() {
82
-	status.UpdatedUnix = time.Now().Unix()
71
+	UpdatedUnix int64     `xorm:"INDEX updated"`
83 72
 }
84 73
 
85 74
 // AfterSet is invoked from XORM after setting the value of a field of

+ 2 - 12
models/token.go

@@ -21,23 +21,13 @@ type AccessToken struct {
21 21
 	Sha1 string `xorm:"UNIQUE VARCHAR(40)"`
22 22
 
23 23
 	Created           time.Time `xorm:"-"`
24
-	CreatedUnix       int64     `xorm:"INDEX"`
24
+	CreatedUnix       int64     `xorm:"INDEX created"`
25 25
 	Updated           time.Time `xorm:"-"` // Note: Updated must below Created for AfterSet.
26
-	UpdatedUnix       int64     `xorm:"INDEX"`
26
+	UpdatedUnix       int64     `xorm:"INDEX updated"`
27 27
 	HasRecentActivity bool      `xorm:"-"`
28 28
 	HasUsed           bool      `xorm:"-"`
29 29
 }
30 30
 
31
-// BeforeInsert will be invoked by XORM before inserting a record representing this object.
32
-func (t *AccessToken) BeforeInsert() {
33
-	t.CreatedUnix = time.Now().Unix()
34
-}
35
-
36
-// BeforeUpdate is invoked from XORM before updating this object.
37
-func (t *AccessToken) BeforeUpdate() {
38
-	t.UpdatedUnix = time.Now().Unix()
39
-}
40
-
41 31
 // AfterSet is invoked from XORM after setting the value of a field of this object.
42 32
 func (t *AccessToken) AfterSet(colName string, _ xorm.Cell) {
43 33
 	switch colName {

+ 2 - 12
models/twofactor.go

@@ -26,19 +26,9 @@ type TwoFactor struct {
26 26
 	ScratchToken string
27 27
 
28 28
 	Created     time.Time `xorm:"-"`
29
-	CreatedUnix int64     `xorm:"INDEX"`
29
+	CreatedUnix int64     `xorm:"INDEX created"`
30 30
 	Updated     time.Time `xorm:"-"` // Note: Updated must below Created for AfterSet.
31
-	UpdatedUnix int64     `xorm:"INDEX"`
32
-}
33
-
34
-// BeforeInsert will be invoked by XORM before inserting a record representing this object.
35
-func (t *TwoFactor) BeforeInsert() {
36
-	t.CreatedUnix = time.Now().Unix()
37
-}
38
-
39
-// BeforeUpdate is invoked from XORM before updating this object.
40
-func (t *TwoFactor) BeforeUpdate() {
41
-	t.UpdatedUnix = time.Now().Unix()
31
+	UpdatedUnix int64     `xorm:"INDEX updated"`
42 32
 }
43 33
 
44 34
 // AfterSet is invoked from XORM after setting the value of a field of this object.

+ 1 - 0
models/unit_tests.go

@@ -28,6 +28,7 @@ func CreateTestEngine(fixturesDir string) error {
28 28
 	if err = x.StoreEngine("InnoDB").Sync2(tables...); err != nil {
29 29
 		return err
30 30
 	}
31
+	x.ShowSQL(true)
31 32
 
32 33
 	return InitFixtures(&testfixtures.SQLite{}, fixturesDir)
33 34
 }

+ 2 - 10
models/user.go

@@ -94,9 +94,9 @@ type User struct {
94 94
 	Salt             string `xorm:"VARCHAR(10)"`
95 95
 
96 96
 	Created       time.Time `xorm:"-"`
97
-	CreatedUnix   int64     `xorm:"INDEX"`
97
+	CreatedUnix   int64     `xorm:"INDEX created"`
98 98
 	Updated       time.Time `xorm:"-"`
99
-	UpdatedUnix   int64     `xorm:"INDEX"`
99
+	UpdatedUnix   int64     `xorm:"INDEX updated"`
100 100
 	LastLogin     time.Time `xorm:"-"`
101 101
 	LastLoginUnix int64     `xorm:"INDEX"`
102 102
 
@@ -135,18 +135,11 @@ type User struct {
135 135
 	DiffViewStyle string `xorm:"NOT NULL DEFAULT ''"`
136 136
 }
137 137
 
138
-// BeforeInsert is invoked from XORM before inserting an object of this type.
139
-func (u *User) BeforeInsert() {
140
-	u.CreatedUnix = time.Now().Unix()
141
-	u.UpdatedUnix = u.CreatedUnix
142
-}
143
-
144 138
 // BeforeUpdate is invoked from XORM before updating this object.
145 139
 func (u *User) BeforeUpdate() {
146 140
 	if u.MaxRepoCreation < -1 {
147 141
 		u.MaxRepoCreation = -1
148 142
 	}
149
-	u.UpdatedUnix = time.Now().Unix()
150 143
 }
151 144
 
152 145
 // SetLastLogin set time to last login
@@ -897,7 +890,6 @@ func UpdateUserCols(u *User, cols ...string) error {
897 890
 	u.Website = base.TruncateString(u.Website, 255)
898 891
 	u.Description = base.TruncateString(u.Description, 255)
899 892
 
900
-	cols = append(cols, "updated_unix")
901 893
 	_, err := x.Id(u.ID).Cols(cols...).Update(u)
902 894
 	return err
903 895
 }

+ 2 - 15
models/webhook.go

@@ -107,22 +107,9 @@ type Webhook struct {
107 107
 	LastStatus   HookStatus // Last delivery status
108 108
 
109 109
 	Created     time.Time `xorm:"-"`
110
-	CreatedUnix int64     `xorm:"INDEX"`
110
+	CreatedUnix int64     `xorm:"INDEX created"`
111 111
 	Updated     time.Time `xorm:"-"`
112
-	UpdatedUnix int64     `xorm:"INDEX"`
113
-}
114
-
115
-// BeforeInsert will be invoked by XORM before inserting a record
116
-// representing this object
117
-func (w *Webhook) BeforeInsert() {
118
-	w.CreatedUnix = time.Now().Unix()
119
-	w.UpdatedUnix = w.CreatedUnix
120
-}
121
-
122
-// BeforeUpdate will be invoked by XORM before updating a record
123
-// representing this object
124
-func (w *Webhook) BeforeUpdate() {
125
-	w.UpdatedUnix = time.Now().Unix()
112
+	UpdatedUnix int64     `xorm:"INDEX updated"`
126 113
 }
127 114
 
128 115
 // AfterSet updates the webhook object upon setting a column

+ 3 - 2
vendor/github.com/go-xorm/core/type.go

@@ -100,7 +100,8 @@ var (
100 100
 	LongBlob   = "LONGBLOB"
101 101
 	Bytea      = "BYTEA"
102 102
 
103
-	Bool = "BOOL"
103
+	Bool    = "BOOL"
104
+	Boolean = "BOOLEAN"
104 105
 
105 106
 	Serial    = "SERIAL"
106 107
 	BigSerial = "BIGSERIAL"
@@ -163,7 +164,7 @@ var (
163 164
 	uintTypes = sort.StringSlice{"*uint", "*uint16", "*uint32", "*uint8"}
164 165
 )
165 166
 
166
-// !nashtsai! treat following var as interal const values, these are used for reflect.TypeOf comparision
167
+// !nashtsai! treat following var as interal const values, these are used for reflect.TypeOf comparison
167 168
 var (
168 169
 	c_EMPTY_STRING       string
169 170
 	c_BOOL_DEFAULT       bool

+ 1 - 1
vendor/github.com/go-xorm/xorm/README.md

@@ -34,7 +34,7 @@ Drivers for Go's sql package which currently support database/sql includes:
34 34
 
35 35
 * Mysql: [github.com/go-sql-driver/mysql](https://github.com/go-sql-driver/mysql)
36 36
 
37
-* MyMysql: [github.com/ziutek/mymysql/godrv](https://github.com/ziutek/mymysql/godrv)
37
+* MyMysql: [github.com/ziutek/mymysql/godrv](https://github.com/ziutek/mymysql/tree/master/godrv)
38 38
 
39 39
 * Postgres: [github.com/lib/pq](https://github.com/lib/pq)
40 40
 

+ 12 - 22
vendor/github.com/go-xorm/xorm/cache_lru.go

@@ -15,13 +15,12 @@ import (
15 15
 
16 16
 // LRUCacher implments cache object facilities
17 17
 type LRUCacher struct {
18
-	idList   *list.List
19
-	sqlList  *list.List
20
-	idIndex  map[string]map[string]*list.Element
21
-	sqlIndex map[string]map[string]*list.Element
22
-	store    core.CacheStore
23
-	mutex    sync.Mutex
24
-	// maxSize    int
18
+	idList         *list.List
19
+	sqlList        *list.List
20
+	idIndex        map[string]map[string]*list.Element
21
+	sqlIndex       map[string]map[string]*list.Element
22
+	store          core.CacheStore
23
+	mutex          sync.Mutex
25 24
 	MaxElementSize int
26 25
 	Expired        time.Duration
27 26
 	GcInterval     time.Duration
@@ -54,8 +53,6 @@ func (m *LRUCacher) RunGC() {
54 53
 
55 54
 // GC check ids lit and sql list to remove all element expired
56 55
 func (m *LRUCacher) GC() {
57
-	//fmt.Println("begin gc ...")
58
-	//defer fmt.Println("end gc ...")
59 56
 	m.mutex.Lock()
60 57
 	defer m.mutex.Unlock()
61 58
 	var removedNum int
@@ -64,12 +61,10 @@ func (m *LRUCacher) GC() {
64 61
 			time.Now().Sub(e.Value.(*idNode).lastVisit) > m.Expired {
65 62
 			removedNum++
66 63
 			next := e.Next()
67
-			//fmt.Println("removing ...", e.Value)
68 64
 			node := e.Value.(*idNode)
69 65
 			m.delBean(node.tbName, node.id)
70 66
 			e = next
71 67
 		} else {
72
-			//fmt.Printf("removing %d cache nodes ..., left %d\n", removedNum, m.idList.Len())
73 68
 			break
74 69
 		}
75 70
 	}
@@ -80,12 +75,10 @@ func (m *LRUCacher) GC() {
80 75
 			time.Now().Sub(e.Value.(*sqlNode).lastVisit) > m.Expired {
81 76
 			removedNum++
82 77
 			next := e.Next()
83
-			//fmt.Println("removing ...", e.Value)
84 78
 			node := e.Value.(*sqlNode)
85 79
 			m.delIds(node.tbName, node.sql)
86 80
 			e = next
87 81
 		} else {
88
-			//fmt.Printf("removing %d cache nodes ..., left %d\n", removedNum, m.sqlList.Len())
89 82
 			break
90 83
 		}
91 84
 	}
@@ -116,7 +109,6 @@ func (m *LRUCacher) GetIds(tableName, sql string) interface{} {
116 109
 	}
117 110
 
118 111
 	m.delIds(tableName, sql)
119
-
120 112
 	return nil
121 113
 }
122 114
 
@@ -134,7 +126,6 @@ func (m *LRUCacher) GetBean(tableName string, id string) interface{} {
134 126
 			// if expired, remove the node and return nil
135 127
 			if time.Now().Sub(lastTime) > m.Expired {
136 128
 				m.delBean(tableName, id)
137
-				//m.clearIds(tableName)
138 129
 				return nil
139 130
 			}
140 131
 			m.idList.MoveToBack(el)
@@ -148,7 +139,6 @@ func (m *LRUCacher) GetBean(tableName string, id string) interface{} {
148 139
 
149 140
 	// store bean is not exist, then remove memory's index
150 141
 	m.delBean(tableName, id)
151
-	//m.clearIds(tableName)
152 142
 	return nil
153 143
 }
154 144
 
@@ -166,8 +156,8 @@ func (m *LRUCacher) clearIds(tableName string) {
166 156
 // ClearIds clears all sql-ids mapping on table tableName from cache
167 157
 func (m *LRUCacher) ClearIds(tableName string) {
168 158
 	m.mutex.Lock()
169
-	defer m.mutex.Unlock()
170 159
 	m.clearIds(tableName)
160
+	m.mutex.Unlock()
171 161
 }
172 162
 
173 163
 func (m *LRUCacher) clearBeans(tableName string) {
@@ -184,14 +174,13 @@ func (m *LRUCacher) clearBeans(tableName string) {
184 174
 // ClearBeans clears all beans in some table
185 175
 func (m *LRUCacher) ClearBeans(tableName string) {
186 176
 	m.mutex.Lock()
187
-	defer m.mutex.Unlock()
188 177
 	m.clearBeans(tableName)
178
+	m.mutex.Unlock()
189 179
 }
190 180
 
191 181
 // PutIds pus ids into table
192 182
 func (m *LRUCacher) PutIds(tableName, sql string, ids interface{}) {
193 183
 	m.mutex.Lock()
194
-	defer m.mutex.Unlock()
195 184
 	if _, ok := m.sqlIndex[tableName]; !ok {
196 185
 		m.sqlIndex[tableName] = make(map[string]*list.Element)
197 186
 	}
@@ -207,12 +196,12 @@ func (m *LRUCacher) PutIds(tableName, sql string, ids interface{}) {
207 196
 		node := e.Value.(*sqlNode)
208 197
 		m.delIds(node.tbName, node.sql)
209 198
 	}
199
+	m.mutex.Unlock()
210 200
 }
211 201
 
212 202
 // PutBean puts beans into table
213 203
 func (m *LRUCacher) PutBean(tableName string, id string, obj interface{}) {
214 204
 	m.mutex.Lock()
215
-	defer m.mutex.Unlock()
216 205
 	var el *list.Element
217 206
 	var ok bool
218 207
 
@@ -229,6 +218,7 @@ func (m *LRUCacher) PutBean(tableName string, id string, obj interface{}) {
229 218
 		node := e.Value.(*idNode)
230 219
 		m.delBean(node.tbName, node.id)
231 220
 	}
221
+	m.mutex.Unlock()
232 222
 }
233 223
 
234 224
 func (m *LRUCacher) delIds(tableName, sql string) {
@@ -244,8 +234,8 @@ func (m *LRUCacher) delIds(tableName, sql string) {
244 234
 // DelIds deletes ids
245 235
 func (m *LRUCacher) DelIds(tableName, sql string) {
246 236
 	m.mutex.Lock()
247
-	defer m.mutex.Unlock()
248 237
 	m.delIds(tableName, sql)
238
+	m.mutex.Unlock()
249 239
 }
250 240
 
251 241
 func (m *LRUCacher) delBean(tableName string, id string) {
@@ -261,8 +251,8 @@ func (m *LRUCacher) delBean(tableName string, id string) {
261 251
 // DelBean deletes beans in some table
262 252
 func (m *LRUCacher) DelBean(tableName string, id string) {
263 253
 	m.mutex.Lock()
264
-	defer m.mutex.Unlock()
265 254
 	m.delBean(tableName, id)
255
+	m.mutex.Unlock()
266 256
 }
267 257
 
268 258
 type idNode struct {

+ 10 - 1
vendor/github.com/go-xorm/xorm/circle.yml

@@ -21,7 +21,16 @@ database:
21 21
 test:
22 22
   override:
23 23
     # './...' is a relative pattern which means all subdirectories
24
-    - go test -v -race -db="sqlite3::mysql::mymysql::postgres" -conn_str="./test.db::root:@/xorm_test::xorm_test/root/::dbname=xorm_test sslmode=disable" -coverprofile=coverage.txt -covermode=atomic
24
+    - go get -u github.com/wadey/gocovmerge;
25
+    - go test -v -race -db="sqlite3" -conn_str="./test.db" -coverprofile=coverage1-1.txt -covermode=atomic
26
+    - go test -v -race -db="sqlite3" -conn_str="./test.db" -cache=true -coverprofile=coverage1-2.txt -covermode=atomic
27
+    - go test -v -race -db="mysql" -conn_str="root:@/xorm_test" -coverprofile=coverage2-1.txt -covermode=atomic
28
+    - go test -v -race -db="mysql" -conn_str="root:@/xorm_test" -cache=true -coverprofile=coverage2-2.txt -covermode=atomic
29
+    - go test -v -race -db="mymysql" -conn_str="xorm_test/root/" -coverprofile=coverage3-1.txt -covermode=atomic
30
+    - go test -v -race -db="mymysql" -conn_str="xorm_test/root/" -cache=true -coverprofile=coverage3-2.txt -covermode=atomic
31
+    - go test -v -race -db="postgres" -conn_str="dbname=xorm_test sslmode=disable" -coverprofile=coverage4-1.txt -covermode=atomic
32
+    - go test -v -race -db="postgres" -conn_str="dbname=xorm_test sslmode=disable" -cache=true -coverprofile=coverage4-2.txt -covermode=atomic
33
+    - gocovmerge coverage1-1.txt coverage1-2.txt coverage2-1.txt coverage2-2.txt coverage3-1.txt coverage3-2.txt coverage4-1.txt coverage4-2.txt > coverage.txt
25 34
     - cd /home/ubuntu/.go_workspace/src/github.com/go-xorm/tests && ./sqlite3.sh
26 35
     - cd /home/ubuntu/.go_workspace/src/github.com/go-xorm/tests && ./mysql.sh
27 36
     - cd /home/ubuntu/.go_workspace/src/github.com/go-xorm/tests && ./postgres.sh

+ 12 - 0
vendor/github.com/go-xorm/xorm/convert.go

@@ -334,3 +334,15 @@ func convertInt(v interface{}) (int64, error) {
334 334
 	}
335 335
 	return 0, fmt.Errorf("unsupported type: %v", v)
336 336
 }
337
+
338
+func asBool(bs []byte) (bool, error) {
339
+	if len(bs) == 0 {
340
+		return false, nil
341
+	}
342
+	if bs[0] == 0x00 {
343
+		return false, nil
344
+	} else if bs[0] == 0x01 {
345
+		return true, nil
346
+	}
347
+	return strconv.ParseBool(string(bs))
348
+}

+ 3 - 0
vendor/github.com/go-xorm/xorm/dialect_postgres.go

@@ -781,6 +781,9 @@ func (db *postgres) SqlType(c *core.Column) string {
781 781
 	case core.TinyInt:
782 782
 		res = core.SmallInt
783 783
 		return res
784
+	case core.Bit:
785
+		res = core.Boolean
786
+		return res
784 787
 	case core.MediumInt, core.Int, core.Integer:
785 788
 		if c.IsAutoIncrement {
786 789
 			return core.Serial

+ 1 - 1
vendor/github.com/go-xorm/xorm/doc.go

@@ -90,7 +90,7 @@ another is Rows
90 90
 
91 91
 5. Update one or more records
92 92
 
93
-    affected, err := engine.Id(...).Update(&user)
93
+    affected, err := engine.ID(...).Update(&user)
94 94
     // UPDATE user SET ...
95 95
 
96 96
 6. Delete one or more records, Delete MUST has condition

+ 7 - 30
vendor/github.com/go-xorm/xorm/engine.go

@@ -273,36 +273,6 @@ func (engine *Engine) logSQL(sqlStr string, sqlArgs ...interface{}) {
273 273
 	}
274 274
 }
275 275
 
276
-func (engine *Engine) logSQLQueryTime(sqlStr string, args []interface{}, executionBlock func() (*core.Stmt, *core.Rows, error)) (*core.Stmt, *core.Rows, error) {
277
-	if engine.showSQL && engine.showExecTime {
278
-		b4ExecTime := time.Now()
279
-		stmt, res, err := executionBlock()
280
-		execDuration := time.Since(b4ExecTime)
281
-		if len(args) > 0 {
282
-			engine.logger.Infof("[SQL] %s %v - took: %v", sqlStr, args, execDuration)
283
-		} else {
284
-			engine.logger.Infof("[SQL] %s - took: %v", sqlStr, execDuration)
285
-		}
286
-		return stmt, res, err
287
-	}
288
-	return executionBlock()
289
-}
290
-
291
-func (engine *Engine) logSQLExecutionTime(sqlStr string, args []interface{}, executionBlock func() (sql.Result, error)) (sql.Result, error) {
292
-	if engine.showSQL && engine.showExecTime {
293
-		b4ExecTime := time.Now()
294
-		res, err := executionBlock()
295
-		execDuration := time.Since(b4ExecTime)
296
-		if len(args) > 0 {
297
-			engine.logger.Infof("[sql] %s [args] %v - took: %v", sqlStr, args, execDuration)
298
-		} else {
299
-			engine.logger.Infof("[sql] %s - took: %v", sqlStr, execDuration)
300
-		}
301
-		return res, err
302
-	}
303
-	return executionBlock()
304
-}
305
-
306 276
 // Sql provides raw sql input parameter. When you have a complex SQL statement
307 277
 // and cannot use Where, Id, In and etc. Methods to describe, you can use SQL.
308 278
 //
@@ -1384,6 +1354,13 @@ func (engine *Engine) QueryString(sqlStr string, args ...interface{}) ([]map[str
1384 1354
 	return session.QueryString(sqlStr, args...)
1385 1355
 }
1386 1356
 
1357
+// QueryInterface runs a raw sql and return records as []map[string]interface{}
1358
+func (engine *Engine) QueryInterface(sqlStr string, args ...interface{}) ([]map[string]interface{}, error) {
1359
+	session := engine.NewSession()
1360
+	defer session.Close()
1361
+	return session.QueryInterface(sqlStr, args...)
1362
+}
1363
+
1387 1364
 // Insert one or more records
1388 1365
 func (engine *Engine) Insert(beans ...interface{}) (int64, error) {
1389 1366
 	session := engine.NewSession()

+ 5 - 36
vendor/github.com/go-xorm/xorm/rows.go

@@ -17,7 +17,6 @@ type Rows struct {
17 17
 	NoTypeCheck bool
18 18
 
19 19
 	session   *Session
20
-	stmt      *core.Stmt
21 20
 	rows      *core.Rows
22 21
 	fields    []string
23 22
 	beanType  reflect.Type
@@ -29,8 +28,6 @@ func newRows(session *Session, bean interface{}) (*Rows, error) {
29 28
 	rows.session = session
30 29
 	rows.beanType = reflect.Indirect(reflect.ValueOf(bean)).Type()
31 30
 
32
-	defer rows.session.resetStatement()
33
-
34 31
 	var sqlStr string
35 32
 	var args []interface{}
36 33
 	var err error
@@ -53,32 +50,11 @@ func newRows(session *Session, bean interface{}) (*Rows, error) {
53 50
 		args = rows.session.statement.RawParams
54 51
 	}
55 52
 
56
-	for _, filter := range rows.session.engine.dialect.Filters() {
57
-		sqlStr = filter.Do(sqlStr, session.engine.dialect, rows.session.statement.RefTable)
58
-	}
59
-
60
-	rows.session.saveLastSQL(sqlStr, args...)
61
-	if rows.session.prepareStmt {
62
-		rows.stmt, err = rows.session.DB().Prepare(sqlStr)
63
-		if err != nil {
64
-			rows.lastError = err
65
-			rows.Close()
66
-			return nil, err
67
-		}
68
-
69
-		rows.rows, err = rows.stmt.Query(args...)
70
-		if err != nil {
71
-			rows.lastError = err
72
-			rows.Close()
73
-			return nil, err
74
-		}
75
-	} else {
76
-		rows.rows, err = rows.session.DB().Query(sqlStr, args...)
77
-		if err != nil {
78
-			rows.lastError = err
79
-			rows.Close()
80
-			return nil, err
81
-		}
53
+	rows.rows, err = rows.session.queryRows(sqlStr, args...)
54
+	if err != nil {
55
+		rows.lastError = err
56
+		rows.Close()
57
+		return nil, err
82 58
 	}
83 59
 
84 60
 	rows.fields, err = rows.rows.Columns()
@@ -142,17 +118,10 @@ func (rows *Rows) Close() error {
142 118
 		if rows.rows != nil {
143 119
 			rows.lastError = rows.rows.Close()
144 120
 			if rows.lastError != nil {
145
-				defer rows.stmt.Close()
146 121
 				return rows.lastError
147 122
 			}
148 123
 		}
149
-		if rows.stmt != nil {
150
-			rows.lastError = rows.stmt.Close()
151
-		}
152 124
 	} else {
153
-		if rows.stmt != nil {
154
-			defer rows.stmt.Close()
155
-		}
156 125
 		if rows.rows != nil {
157 126
 			defer rows.rows.Close()
158 127
 		}

+ 2 - 12
vendor/github.com/go-xorm/xorm/session.go

@@ -303,6 +303,7 @@ func (session *Session) rows2Beans(rows *core.Rows, fields []string, fieldsCount
303 303
 		var newValue = newElemFunc(fields)
304 304
 		bean := newValue.Interface()
305 305
 		dataStruct := rValue(bean)
306
+
306 307
 		// handle beforeClosures
307 308
 		scanResults, err := session.row2Slice(rows, fields, fieldsCount, bean)
308 309
 		if err != nil {
@@ -312,7 +313,6 @@ func (session *Session) rows2Beans(rows *core.Rows, fields []string, fieldsCount
312 313
 		if err != nil {
313 314
 			return err
314 315
 		}
315
-
316 316
 		err = sliceValueSetFunc(&newValue, pk)
317 317
 		if err != nil {
318 318
 			return err
@@ -631,9 +631,7 @@ func (session *Session) slice2Bean(scanResults []interface{}, fields []string, f
631 631
 						// however, also need to consider adding a 'lazy' attribute to xorm tag which allow hasOne
632 632
 						// property to be fetched lazily
633 633
 						structInter := reflect.New(fieldValue.Type())
634
-						newsession := session.engine.NewSession()
635
-						defer newsession.Close()
636
-						has, err := newsession.ID(pk).NoCascade().Get(structInter.Interface())
634
+						has, err := session.ID(pk).NoCascade().get(structInter.Interface())
637 635
 						if err != nil {
638 636
 							return nil, err
639 637
 						}
@@ -777,14 +775,6 @@ func (session *Session) slice2Bean(scanResults []interface{}, fields []string, f
777 775
 	return pk, nil
778 776
 }
779 777
 
780
-func (session *Session) queryPreprocess(sqlStr *string, paramStr ...interface{}) {
781
-	for _, filter := range session.engine.dialect.Filters() {
782
-		*sqlStr = filter.Do(*sqlStr, session.engine.dialect, session.statement.RefTable)
783
-	}
784
-
785
-	session.saveLastSQL(*sqlStr, paramStr...)
786
-}
787
-
788 778
 // saveLastSQL stores executed query information
789 779
 func (session *Session) saveLastSQL(sql string, args ...interface{}) {
790 780
 	session.lastSQL = sql

+ 3 - 8
vendor/github.com/go-xorm/xorm/session_convert.go

@@ -144,8 +144,7 @@ func (session *Session) bytes2Value(col *core.Column, fieldValue *reflect.Value,
144 144
 	case reflect.String:
145 145
 		fieldValue.SetString(string(data))
146 146
 	case reflect.Bool:
147
-		d := string(data)
148
-		v, err := strconv.ParseBool(d)
147
+		v, err := asBool(data)
149 148
 		if err != nil {
150 149
 			return fmt.Errorf("arg %v as bool: %s", key, err.Error())
151 150
 		}
@@ -227,9 +226,7 @@ func (session *Session) bytes2Value(col *core.Column, fieldValue *reflect.Value,
227 226
 					// however, also need to consider adding a 'lazy' attribute to xorm tag which allow hasOne
228 227
 					// property to be fetched lazily
229 228
 					structInter := reflect.New(fieldValue.Type())
230
-					newsession := session.engine.NewSession()
231
-					defer newsession.Close()
232
-					has, err := newsession.Id(pk).NoCascade().Get(structInter.Interface())
229
+					has, err := session.ID(pk).NoCascade().get(structInter.Interface())
233 230
 					if err != nil {
234 231
 						return err
235 232
 					}
@@ -510,9 +507,7 @@ func (session *Session) bytes2Value(col *core.Column, fieldValue *reflect.Value,
510 507
 						// !nashtsai! TODO for hasOne relationship, it's preferred to use join query for eager fetch
511 508
 						// however, also need to consider adding a 'lazy' attribute to xorm tag which allow hasOne
512 509
 						// property to be fetched lazily
513
-						newsession := session.engine.NewSession()
514
-						defer newsession.Close()
515
-						has, err := newsession.Id(pk).NoCascade().Get(structInter.Interface())
510
+						has, err := session.ID(pk).NoCascade().get(structInter.Interface())
516 511
 						if err != nil {
517 512
 							return err
518 513
 						}

+ 16 - 18
vendor/github.com/go-xorm/xorm/session_delete.go

@@ -12,14 +12,14 @@ import (
12 12
 	"github.com/go-xorm/core"
13 13
 )
14 14
 
15
-func (session *Session) cacheDelete(sqlStr string, args ...interface{}) error {
16
-	if session.statement.RefTable == nil ||
15
+func (session *Session) cacheDelete(table *core.Table, tableName, sqlStr string, args ...interface{}) error {
16
+	if table == nil ||
17 17
 		session.tx != nil {
18 18
 		return ErrCacheFailed
19 19
 	}
20 20
 
21 21
 	for _, filter := range session.engine.dialect.Filters() {
22
-		sqlStr = filter.Do(sqlStr, session.engine.dialect, session.statement.RefTable)
22
+		sqlStr = filter.Do(sqlStr, session.engine.dialect, table)
23 23
 	}
24 24
 
25 25
 	newsql := session.statement.convertIDSQL(sqlStr)
@@ -27,11 +27,11 @@ func (session *Session) cacheDelete(sqlStr string, args ...interface{}) error {
27 27
 		return ErrCacheFailed
28 28
 	}
29 29
 
30
-	cacher := session.engine.getCacher2(session.statement.RefTable)
31
-	tableName := session.statement.TableName()
30
+	cacher := session.engine.getCacher2(table)
31
+	pkColumns := table.PKColumns()
32 32
 	ids, err := core.GetCacheSql(cacher, tableName, newsql, args)
33 33
 	if err != nil {
34
-		resultsSlice, err := session.query(newsql, args...)
34
+		resultsSlice, err := session.queryBytes(newsql, args...)
35 35
 		if err != nil {
36 36
 			return err
37 37
 		}
@@ -40,7 +40,7 @@ func (session *Session) cacheDelete(sqlStr string, args ...interface{}) error {
40 40
 			for _, data := range resultsSlice {
41 41
 				var id int64
42 42
 				var pk core.PK = make([]interface{}, 0)
43
-				for _, col := range session.statement.RefTable.PKColumns() {
43
+				for _, col := range pkColumns {
44 44
 					if v, ok := data[col.Name]; !ok {
45 45
 						return errors.New("no id")
46 46
 					} else if col.SQLType.IsText() {
@@ -58,27 +58,23 @@ func (session *Session) cacheDelete(sqlStr string, args ...interface{}) error {
58 58
 				ids = append(ids, pk)
59 59
 			}
60 60
 		}
61
-	} /*else {
62
-	    session.engine.LogDebug("delete cache sql %v", newsql)
63
-	    cacher.DelIds(tableName, genSqlKey(newsql, args))
64
-	}*/
61
+	}
65 62
 
66 63
 	for _, id := range ids {
67
-		session.engine.logger.Debug("[cacheDelete] delete cache obj", tableName, id)
64
+		session.engine.logger.Debug("[cacheDelete] delete cache obj:", tableName, id)
68 65
 		sid, err := id.ToString()
69 66
 		if err != nil {
70 67
 			return err
71 68
 		}
72 69
 		cacher.DelBean(tableName, sid)
73 70
 	}
74
-	session.engine.logger.Debug("[cacheDelete] clear cache sql", tableName)
71
+	session.engine.logger.Debug("[cacheDelete] clear cache table:", tableName)
75 72
 	cacher.ClearIds(tableName)
76 73
 	return nil
77 74
 }
78 75
 
79 76
 // Delete records, bean's non-empty fields are conditions
80 77
 func (session *Session) Delete(bean interface{}) (int64, error) {
81
-	defer session.resetStatement()
82 78
 	if session.isAutoClose {
83 79
 		defer session.Close()
84 80
 	}
@@ -86,7 +82,6 @@ func (session *Session) Delete(bean interface{}) (int64, error) {
86 82
 	if err := session.statement.setRefValue(rValue(bean)); err != nil {
87 83
 		return 0, err
88 84
 	}
89
-	var table = session.statement.RefTable
90 85
 
91 86
 	// handle before delete processors
92 87
 	for _, closure := range session.beforeClosures {
@@ -106,7 +101,9 @@ func (session *Session) Delete(bean interface{}) (int64, error) {
106 101
 		return 0, ErrNeedDeletedCond
107 102
 	}
108 103
 
109
-	var tableName = session.engine.Quote(session.statement.TableName())
104
+	var tableNameNoQuote = session.statement.TableName()
105
+	var tableName = session.engine.Quote(tableNameNoQuote)
106
+	var table = session.statement.RefTable
110 107
 	var deleteSQL string
111 108
 	if len(condSQL) > 0 {
112 109
 		deleteSQL = fmt.Sprintf("DELETE FROM %v WHERE %v", tableName, condSQL)
@@ -202,10 +199,11 @@ func (session *Session) Delete(bean interface{}) (int64, error) {
202 199
 		})
203 200
 	}
204 201
 
205
-	if cacher := session.engine.getCacher2(session.statement.RefTable); cacher != nil && session.statement.UseCache {
206
-		session.cacheDelete(deleteSQL, argsForCache...)
202
+	if cacher := session.engine.getCacher2(table); cacher != nil && session.statement.UseCache {
203
+		session.cacheDelete(table, tableNameNoQuote, deleteSQL, argsForCache...)
207 204
 	}
208 205
 
206
+	session.statement.RefTable = table
209 207
 	res, err := session.exec(realSQL, condArgs...)
210 208
 	if err != nil {
211 209
 		return 0, err

+ 3 - 13
vendor/github.com/go-xorm/xorm/session_exist.go

@@ -10,12 +10,10 @@ import (
10 10
 	"reflect"
11 11
 
12 12
 	"github.com/go-xorm/builder"
13
-	"github.com/go-xorm/core"
14 13
 )
15 14
 
16 15
 // Exist returns true if the record exist otherwise return false
17 16
 func (session *Session) Exist(bean ...interface{}) (bool, error) {
18
-	defer session.resetStatement()
19 17
 	if session.isAutoClose {
20 18
 		defer session.Close()
21 19
 	}
@@ -69,19 +67,11 @@ func (session *Session) Exist(bean ...interface{}) (bool, error) {
69 67
 		args = session.statement.RawParams
70 68
 	}
71 69
 
72
-	session.queryPreprocess(&sqlStr, args...)
73
-
74
-	var rawRows *core.Rows
75
-	if session.isAutoCommit {
76
-		_, rawRows, err = session.innerQuery(sqlStr, args...)
77
-	} else {
78
-		rawRows, err = session.tx.Query(sqlStr, args...)
79
-	}
70
+	rows, err := session.queryRows(sqlStr, args...)
80 71
 	if err != nil {
81 72
 		return false, err
82 73
 	}
74
+	defer rows.Close()
83 75
 
84
-	defer rawRows.Close()
85
-
86
-	return rawRows.Next(), nil
76
+	return rows.Next(), nil
87 77
 }

+ 18 - 28
vendor/github.com/go-xorm/xorm/session_find.go

@@ -23,11 +23,13 @@ const (
23 23
 // are conditions. beans could be []Struct, []*Struct, map[int64]Struct
24 24
 // map[int64]*Struct
25 25
 func (session *Session) Find(rowsSlicePtr interface{}, condiBean ...interface{}) error {
26
-	defer session.resetStatement()
27 26
 	if session.isAutoClose {
28 27
 		defer session.Close()
29 28
 	}
29
+	return session.find(rowsSlicePtr, condiBean...)
30
+}
30 31
 
32
+func (session *Session) find(rowsSlicePtr interface{}, condiBean ...interface{}) error {
31 33
 	sliceValue := reflect.Indirect(reflect.ValueOf(rowsSlicePtr))
32 34
 	if sliceValue.Kind() != reflect.Slice && sliceValue.Kind() != reflect.Map {
33 35
 		return errors.New("needs a pointer to a slice or a map")
@@ -157,21 +159,13 @@ func (session *Session) Find(rowsSlicePtr interface{}, condiBean ...interface{})
157 159
 }
158 160
 
159 161
 func (session *Session) noCacheFind(table *core.Table, containerValue reflect.Value, sqlStr string, args ...interface{}) error {
160
-	var rawRows *core.Rows
161
-	var err error
162
-
163
-	session.queryPreprocess(&sqlStr, args...)
164
-	if session.isAutoCommit {
165
-		_, rawRows, err = session.innerQuery(sqlStr, args...)
166
-	} else {
167
-		rawRows, err = session.tx.Query(sqlStr, args...)
168
-	}
162
+	rows, err := session.queryRows(sqlStr, args...)
169 163
 	if err != nil {
170 164
 		return err
171 165
 	}
172
-	defer rawRows.Close()
166
+	defer rows.Close()
173 167
 
174
-	fields, err := rawRows.Columns()
168
+	fields, err := rows.Columns()
175 169
 	if err != nil {
176 170
 		return err
177 171
 	}
@@ -245,20 +239,20 @@ func (session *Session) noCacheFind(table *core.Table, containerValue reflect.Va
245 239
 		if err != nil {
246 240
 			return err
247 241
 		}
248
-		return session.rows2Beans(rawRows, fields, len(fields), tb, newElemFunc, containerValueSetFunc)
242
+		return session.rows2Beans(rows, fields, len(fields), tb, newElemFunc, containerValueSetFunc)
249 243
 	}
250 244
 
251
-	for rawRows.Next() {
245
+	for rows.Next() {
252 246
 		var newValue = newElemFunc(fields)
253 247
 		bean := newValue.Interface()
254 248
 
255 249
 		switch elemType.Kind() {
256 250
 		case reflect.Slice:
257
-			err = rawRows.ScanSlice(bean)
251
+			err = rows.ScanSlice(bean)
258 252
 		case reflect.Map:
259
-			err = rawRows.ScanMap(bean)
253
+			err = rows.ScanMap(bean)
260 254
 		default:
261
-			err = rawRows.Scan(bean)
255
+			err = rows.Scan(bean)
262 256
 		}
263 257
 
264 258
 		if err != nil {
@@ -299,12 +293,11 @@ func (session *Session) cacheFind(t reflect.Type, sqlStr string, rowsSlicePtr in
299 293
 	}
300 294
 
301 295
 	tableName := session.statement.TableName()
302
-
303 296
 	table := session.statement.RefTable
304 297
 	cacher := session.engine.getCacher2(table)
305 298
 	ids, err := core.GetCacheSql(cacher, tableName, newsql, args)
306 299
 	if err != nil {
307
-		rows, err := session.DB().Query(newsql, args...)
300
+		rows, err := session.queryRows(newsql, args...)
308 301
 		if err != nil {
309 302
 			return err
310 303
 		}
@@ -334,13 +327,13 @@ func (session *Session) cacheFind(t reflect.Type, sqlStr string, rowsSlicePtr in
334 327
 			ids = append(ids, pk)
335 328
 		}
336 329
 
337
-		session.engine.logger.Debug("[cacheFind] cache sql:", ids, tableName, newsql, args)
330
+		session.engine.logger.Debug("[cacheFind] cache sql:", ids, tableName, sqlStr, newsql, args)
338 331
 		err = core.PutCacheSql(cacher, ids, tableName, newsql, args)
339 332
 		if err != nil {
340 333
 			return err
341 334
 		}
342 335
 	} else {
343
-		session.engine.logger.Debug("[cacheFind] cache hit sql:", newsql, args)
336
+		session.engine.logger.Debug("[cacheFind] cache hit sql:", tableName, sqlStr, newsql, args)
344 337
 	}
345 338
 
346 339
 	sliceValue := reflect.Indirect(reflect.ValueOf(rowsSlicePtr))
@@ -355,7 +348,7 @@ func (session *Session) cacheFind(t reflect.Type, sqlStr string, rowsSlicePtr in
355 348
 			return err
356 349
 		}
357 350
 		bean := cacher.GetBean(tableName, sid)
358
-		if bean == nil {
351
+		if bean == nil || reflect.ValueOf(bean).Elem().Type() != t {
359 352
 			ides = append(ides, id)
360 353
 			ididxes[sid] = idx
361 354
 		} else {
@@ -376,9 +369,6 @@ func (session *Session) cacheFind(t reflect.Type, sqlStr string, rowsSlicePtr in
376 369
 	}
377 370
 
378 371
 	if len(ides) > 0 {
379
-		newSession := session.engine.NewSession()
380
-		defer newSession.Close()
381
-
382 372
 		slices := reflect.New(reflect.SliceOf(t))
383 373
 		beans := slices.Interface()
384 374
 
@@ -388,18 +378,18 @@ func (session *Session) cacheFind(t reflect.Type, sqlStr string, rowsSlicePtr in
388 378
 				ff = append(ff, ie[0])
389 379
 			}
390 380
 
391
-			newSession.In("`"+table.PrimaryKeys[0]+"`", ff...)
381
+			session.In("`"+table.PrimaryKeys[0]+"`", ff...)
392 382
 		} else {
393 383
 			for _, ie := range ides {
394 384
 				cond := builder.NewCond()
395 385
 				for i, name := range table.PrimaryKeys {
396 386
 					cond = cond.And(builder.Eq{"`" + name + "`": ie[i]})
397 387
 				}
398
-				newSession.Or(cond)
388
+				session.Or(cond)
399 389
 			}
400 390
 		}
401 391
 
402
-		err = newSession.NoCache().Find(beans)
392
+		err = session.NoCache().Table(tableName).find(beans)
403 393
 		if err != nil {
404 394
 			return err
405 395
 		}

+ 25 - 32
vendor/github.com/go-xorm/xorm/session_get.go

@@ -15,11 +15,13 @@ import (
15 15
 // Get retrieve one record from database, bean's non-empty fields
16 16
 // will be as conditions
17 17
 func (session *Session) Get(bean interface{}) (bool, error) {
18
-	defer session.resetStatement()
19 18
 	if session.isAutoClose {
20 19
 		defer session.Close()
21 20
 	}
21
+	return session.get(bean)
22
+}
22 23
 
24
+func (session *Session) get(bean interface{}) (bool, error) {
23 25
 	beanValue := reflect.ValueOf(bean)
24 26
 	if beanValue.Kind() != reflect.Ptr {
25 27
 		return false, errors.New("needs a pointer to a value")
@@ -51,8 +53,10 @@ func (session *Session) Get(bean interface{}) (bool, error) {
51 53
 		args = session.statement.RawParams
52 54
 	}
53 55
 
56
+	table := session.statement.RefTable
57
+
54 58
 	if session.canCache() && beanValue.Elem().Kind() == reflect.Struct {
55
-		if cacher := session.engine.getCacher2(session.statement.RefTable); cacher != nil &&
59
+		if cacher := session.engine.getCacher2(table); cacher != nil &&
56 60
 			!session.statement.unscoped {
57 61
 			has, err := session.cacheGet(bean, sqlStr, args...)
58 62
 			if err != ErrCacheFailed {
@@ -61,54 +65,43 @@ func (session *Session) Get(bean interface{}) (bool, error) {
61 65
 		}
62 66
 	}
63 67
 
64
-	return session.nocacheGet(beanValue.Elem().Kind(), bean, sqlStr, args...)
68
+	return session.nocacheGet(beanValue.Elem().Kind(), table, bean, sqlStr, args...)
65 69
 }
66 70
 
67
-func (session *Session) nocacheGet(beanKind reflect.Kind, bean interface{}, sqlStr string, args ...interface{}) (bool, error) {
68
-	session.queryPreprocess(&sqlStr, args...)
69
-
70
-	var rawRows *core.Rows
71
-	var err error
72
-	if session.isAutoCommit {
73
-		_, rawRows, err = session.innerQuery(sqlStr, args...)
74
-	} else {
75
-		rawRows, err = session.tx.Query(sqlStr, args...)
76
-	}
71
+func (session *Session) nocacheGet(beanKind reflect.Kind, table *core.Table, bean interface{}, sqlStr string, args ...interface{}) (bool, error) {
72
+	rows, err := session.queryRows(sqlStr, args...)
77 73
 	if err != nil {
78 74
 		return false, err
79 75
 	}
76
+	defer rows.Close()
80 77
 
81
-	defer rawRows.Close()
82
-
83
-	if !rawRows.Next() {
78
+	if !rows.Next() {
84 79
 		return false, nil
85 80
 	}
86 81
 
87 82
 	switch beanKind {
88 83
 	case reflect.Struct:
89
-		fields, err := rawRows.Columns()
84
+		fields, err := rows.Columns()
90 85
 		if err != nil {
91
-			// WARN: Alougth rawRows return true, but get fields failed
86
+			// WARN: Alougth rows return true, but get fields failed
92 87
 			return true, err
93 88
 		}
94
-		dataStruct := rValue(bean)
95
-		if err := session.statement.setRefValue(dataStruct); err != nil {
96
-			return false, err
97
-		}
98 89
 
99
-		scanResults, err := session.row2Slice(rawRows, fields, len(fields), bean)
90
+		scanResults, err := session.row2Slice(rows, fields, len(fields), bean)
100 91
 		if err != nil {
101 92
 			return false, err
102 93
 		}
103
-		rawRows.Close()
94
+		// close it before covert data
95
+		rows.Close()
104 96
 
105
-		_, err = session.slice2Bean(scanResults, fields, len(fields), bean, &dataStruct, session.statement.RefTable)
97
+		dataStruct := rValue(bean)
98
+		_, err = session.slice2Bean(scanResults, fields, len(fields), bean, &dataStruct, table)
106 99
 	case reflect.Slice:
107
-		err = rawRows.ScanSlice(bean)
100
+		err = rows.ScanSlice(bean)
108 101
 	case reflect.Map:
109
-		err = rawRows.ScanMap(bean)
102
+		err = rows.ScanMap(bean)
110 103
 	default:
111
-		err = rawRows.Scan(bean)
104
+		err = rows.Scan(bean)
112 105
 	}
113 106
 
114 107
 	return true, err
@@ -131,11 +124,11 @@ func (session *Session) cacheGet(bean interface{}, sqlStr string, args ...interf
131 124
 	cacher := session.engine.getCacher2(session.statement.RefTable)
132 125
 	tableName := session.statement.TableName()
133 126
 	session.engine.logger.Debug("[cacheGet] find sql:", newsql, args)
134
-	ids, err := core.GetCacheSql(cacher, tableName, newsql, args)
135 127
 	table := session.statement.RefTable
128
+	ids, err := core.GetCacheSql(cacher, tableName, newsql, args)
136 129
 	if err != nil {
137 130
 		var res = make([]string, len(table.PrimaryKeys))
138
-		rows, err := session.DB().Query(newsql, args...)
131
+		rows, err := session.NoCache().queryRows(newsql, args...)
139 132
 		if err != nil {
140 133
 			return false, err
141 134
 		}
@@ -172,7 +165,7 @@ func (session *Session) cacheGet(bean interface{}, sqlStr string, args ...interf
172 165
 			return false, err
173 166
 		}
174 167
 	} else {
175
-		session.engine.logger.Debug("[cacheGet] cache hit sql:", newsql)
168
+		session.engine.logger.Debug("[cacheGet] cache hit sql:", newsql, ids)
176 169
 	}
177 170
 
178 171
 	if len(ids) > 0 {
@@ -186,7 +179,7 @@ func (session *Session) cacheGet(bean interface{}, sqlStr string, args ...interf
186 179
 		cacheBean := cacher.GetBean(tableName, sid)
187 180
 		if cacheBean == nil {
188 181
 			cacheBean = bean
189
-			has, err = session.nocacheGet(reflect.Struct, cacheBean, sqlStr, args...)
182
+			has, err = session.nocacheGet(reflect.Struct, table, cacheBean, sqlStr, args...)
190 183
 			if err != nil || !has {
191 184
 				return has, err
192 185
 			}

+ 16 - 19
vendor/github.com/go-xorm/xorm/session_insert.go

@@ -22,7 +22,6 @@ func (session *Session) Insert(beans ...interface{}) (int64, error) {
22 22
 	if session.isAutoClose {
23 23
 		defer session.Close()
24 24
 	}
25
-	defer session.resetStatement()
26 25
 
27 26
 	for _, bean := range beans {
28 27
 		sliceValue := reflect.Indirect(reflect.ValueOf(bean))
@@ -214,22 +213,23 @@ func (session *Session) innerInsertMulti(rowsSlicePtr interface{}) (int64, error
214 213
 
215 214
 	var sql = "INSERT INTO %s (%v%v%v) VALUES (%v)"
216 215
 	var statement string
216
+	var tableName = session.statement.TableName()
217 217
 	if session.engine.dialect.DBType() == core.ORACLE {
218 218
 		sql = "INSERT ALL INTO %s (%v%v%v) VALUES (%v) SELECT 1 FROM DUAL"
219 219
 		temp := fmt.Sprintf(") INTO %s (%v%v%v) VALUES (",
220
-			session.engine.Quote(session.statement.TableName()),
220
+			session.engine.Quote(tableName),
221 221
 			session.engine.QuoteStr(),
222 222
 			strings.Join(colNames, session.engine.QuoteStr()+", "+session.engine.QuoteStr()),
223 223
 			session.engine.QuoteStr())
224 224
 		statement = fmt.Sprintf(sql,
225
-			session.engine.Quote(session.statement.TableName()),
225
+			session.engine.Quote(tableName),
226 226
 			session.engine.QuoteStr(),
227 227
 			strings.Join(colNames, session.engine.QuoteStr()+", "+session.engine.QuoteStr()),
228 228
 			session.engine.QuoteStr(),
229 229
 			strings.Join(colMultiPlaces, temp))
230 230
 	} else {
231 231
 		statement = fmt.Sprintf(sql,
232
-			session.engine.Quote(session.statement.TableName()),
232
+			session.engine.Quote(tableName),
233 233
 			session.engine.QuoteStr(),
234 234
 			strings.Join(colNames, session.engine.QuoteStr()+", "+session.engine.QuoteStr()),
235 235
 			session.engine.QuoteStr(),
@@ -241,7 +241,7 @@ func (session *Session) innerInsertMulti(rowsSlicePtr interface{}) (int64, error
241 241
 	}
242 242
 
243 243
 	if cacher := session.engine.getCacher2(table); cacher != nil && session.statement.UseCache {
244
-		session.cacheInsert(session.statement.TableName())
244
+		session.cacheInsert(table, tableName)
245 245
 	}
246 246
 
247 247
 	lenAfterClosures := len(session.afterClosures)
@@ -280,7 +280,6 @@ func (session *Session) innerInsertMulti(rowsSlicePtr interface{}) (int64, error
280 280
 
281 281
 // InsertMulti insert multiple records
282 282
 func (session *Session) InsertMulti(rowsSlicePtr interface{}) (int64, error) {
283
-	defer session.resetStatement()
284 283
 	if session.isAutoClose {
285 284
 		defer session.Close()
286 285
 	}
@@ -349,18 +348,19 @@ func (session *Session) innerInsert(bean interface{}) (int64, error) {
349 348
 	}
350 349
 
351 350
 	var sqlStr string
351
+	var tableName = session.statement.TableName()
352 352
 	if len(colPlaces) > 0 {
353 353
 		sqlStr = fmt.Sprintf("INSERT INTO %s (%v%v%v) VALUES (%v)",
354
-			session.engine.Quote(session.statement.TableName()),
354
+			session.engine.Quote(tableName),
355 355
 			session.engine.QuoteStr(),
356 356
 			strings.Join(colNames, session.engine.Quote(", ")),
357 357
 			session.engine.QuoteStr(),
358 358
 			colPlaces)
359 359
 	} else {
360 360
 		if session.engine.dialect.DBType() == core.MYSQL {
361
-			sqlStr = fmt.Sprintf("INSERT INTO %s VALUES ()", session.engine.Quote(session.statement.TableName()))
361
+			sqlStr = fmt.Sprintf("INSERT INTO %s VALUES ()", session.engine.Quote(tableName))
362 362
 		} else {
363
-			sqlStr = fmt.Sprintf("INSERT INTO %s DEFAULT VALUES", session.engine.Quote(session.statement.TableName()))
363
+			sqlStr = fmt.Sprintf("INSERT INTO %s DEFAULT VALUES", session.engine.Quote(tableName))
364 364
 		}
365 365
 	}
366 366
 
@@ -395,7 +395,7 @@ func (session *Session) innerInsert(bean interface{}) (int64, error) {
395 395
 	// for postgres, many of them didn't implement lastInsertId, so we should
396 396
 	// implemented it ourself.
397 397
 	if session.engine.dialect.DBType() == core.ORACLE && len(table.AutoIncrement) > 0 {
398
-		res, err := session.query("select seq_atable.currval from dual", args...)
398
+		res, err := session.queryBytes("select seq_atable.currval from dual", args...)
399 399
 		if err != nil {
400 400
 			return 0, err
401 401
 		}
@@ -403,7 +403,7 @@ func (session *Session) innerInsert(bean interface{}) (int64, error) {
403 403
 		handleAfterInsertProcessorFunc(bean)
404 404
 
405 405
 		if cacher := session.engine.getCacher2(table); cacher != nil && session.statement.UseCache {
406
-			session.cacheInsert(session.statement.TableName())
406
+			session.cacheInsert(table, tableName)
407 407
 		}
408 408
 
409 409
 		if table.Version != "" && session.statement.checkVersion {
@@ -440,7 +440,7 @@ func (session *Session) innerInsert(bean interface{}) (int64, error) {
440 440
 	} else if session.engine.dialect.DBType() == core.POSTGRES && len(table.AutoIncrement) > 0 {
441 441
 		//assert table.AutoIncrement != ""
442 442
 		sqlStr = sqlStr + " RETURNING " + session.engine.Quote(table.AutoIncrement)
443
-		res, err := session.query(sqlStr, args...)
443
+		res, err := session.queryBytes(sqlStr, args...)
444 444
 
445 445
 		if err != nil {
446 446
 			return 0, err
@@ -448,7 +448,7 @@ func (session *Session) innerInsert(bean interface{}) (int64, error) {
448 448
 		handleAfterInsertProcessorFunc(bean)
449 449
 
450 450
 		if cacher := session.engine.getCacher2(table); cacher != nil && session.statement.UseCache {
451
-			session.cacheInsert(session.statement.TableName())
451
+			session.cacheInsert(table, tableName)
452 452
 		}
453 453
 
454 454
 		if table.Version != "" && session.statement.checkVersion {
@@ -491,7 +491,7 @@ func (session *Session) innerInsert(bean interface{}) (int64, error) {
491 491
 		defer handleAfterInsertProcessorFunc(bean)
492 492
 
493 493
 		if cacher := session.engine.getCacher2(table); cacher != nil && session.statement.UseCache {
494
-			session.cacheInsert(session.statement.TableName())
494
+			session.cacheInsert(table, tableName)
495 495
 		}
496 496
 
497 497
 		if table.Version != "" && session.statement.checkVersion {
@@ -532,7 +532,6 @@ func (session *Session) innerInsert(bean interface{}) (int64, error) {
532 532
 // The in parameter bean must a struct or a point to struct. The return
533 533
 // parameter is inserted and error
534 534
 func (session *Session) InsertOne(bean interface{}) (int64, error) {
535
-	defer session.resetStatement()
536 535
 	if session.isAutoClose {
537 536
 		defer session.Close()
538 537
 	}
@@ -540,14 +539,12 @@ func (session *Session) InsertOne(bean interface{}) (int64, error) {
540 539
 	return session.innerInsert(bean)
541 540
 }
542 541
 
543
-func (session *Session) cacheInsert(tables ...string) error {
544
-	if session.statement.RefTable == nil {
542
+func (session *Session) cacheInsert(table *core.Table, tables ...string) error {
543
+	if table == nil {
545 544
 		return ErrCacheFailed
546 545
 	}
547 546
 
548
-	table := session.statement.RefTable
549 547
 	cacher := session.engine.getCacher2(table)
550
-
551 548
 	for _, t := range tables {
552 549
 		session.engine.logger.Debug("[cache] clear sql:", t)
553 550
 		cacher.ClearIds(t)

+ 4 - 0
vendor/github.com/go-xorm/xorm/session_iterate.go

@@ -19,6 +19,10 @@ func (session *Session) Rows(bean interface{}) (*Rows, error) {
19 19
 // are conditions. beans could be []Struct, []*Struct, map[int64]Struct
20 20
 // map[int64]*Struct
21 21
 func (session *Session) Iterate(bean interface{}, fun IterFunc) error {
22
+	if session.isAutoClose {
23
+		defer session.Close()
24
+	}
25
+
22 26
 	rows, err := session.Rows(bean)
23 27
 	if err != nil {
24 28
 		return err

+ 177 - 0
vendor/github.com/go-xorm/xorm/session_query.go

@@ -0,0 +1,177 @@
1
+// Copyright 2017 The Xorm Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+package xorm
6
+
7
+import (
8
+	"fmt"
9
+	"reflect"
10
+	"strconv"
11
+	"time"
12
+
13
+	"github.com/go-xorm/core"
14
+)
15
+
16
+// Query runs a raw sql and return records as []map[string][]byte
17
+func (session *Session) Query(sqlStr string, args ...interface{}) ([]map[string][]byte, error) {
18
+	if session.isAutoClose {
19
+		defer session.Close()
20
+	}
21
+
22
+	return session.queryBytes(sqlStr, args...)
23
+}
24
+
25
+func value2String(rawValue *reflect.Value) (str string, err error) {
26
+	aa := reflect.TypeOf((*rawValue).Interface())
27
+	vv := reflect.ValueOf((*rawValue).Interface())
28
+	switch aa.Kind() {
29
+	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
30
+		str = strconv.FormatInt(vv.Int(), 10)
31
+	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
32
+		str = strconv.FormatUint(vv.Uint(), 10)
33
+	case reflect.Float32, reflect.Float64:
34
+		str = strconv.FormatFloat(vv.Float(), 'f', -1, 64)
35
+	case reflect.String:
36
+		str = vv.String()
37
+	case reflect.Array, reflect.Slice:
38
+		switch aa.Elem().Kind() {
39
+		case reflect.Uint8:
40
+			data := rawValue.Interface().([]byte)
41
+			str = string(data)
42
+			if str == "\x00" {
43
+				str = "0"
44
+			}
45
+		default:
46
+			err = fmt.Errorf("Unsupported struct type %v", vv.Type().Name())
47
+		}
48
+	// time type
49
+	case reflect.Struct:
50
+		if aa.ConvertibleTo(core.TimeType) {
51
+			str = vv.Convert(core.TimeType).Interface().(time.Time).Format(time.RFC3339Nano)
52
+		} else {
53
+			err = fmt.Errorf("Unsupported struct type %v", vv.Type().Name())
54
+		}
55
+	case reflect.Bool:
56
+		str = strconv.FormatBool(vv.Bool())
57
+	case reflect.Complex128, reflect.Complex64:
58
+		str = fmt.Sprintf("%v", vv.Complex())
59
+	/* TODO: unsupported types below
60
+	   case reflect.Map:
61
+	   case reflect.Ptr:
62
+	   case reflect.Uintptr:
63
+	   case reflect.UnsafePointer:
64
+	   case reflect.Chan, reflect.Func, reflect.Interface:
65
+	*/
66
+	default:
67
+		err = fmt.Errorf("Unsupported struct type %v", vv.Type().Name())
68
+	}
69
+	return
70
+}
71
+
72
+func row2mapStr(rows *core.Rows, fields []string) (resultsMap map[string]string, err error) {
73
+	result := make(map[string]string)
74
+	scanResultContainers := make([]interface{}, len(fields))
75
+	for i := 0; i < len(fields); i++ {
76
+		var scanResultContainer interface{}
77
+		scanResultContainers[i] = &scanResultContainer
78
+	}
79
+	if err := rows.Scan(scanResultContainers...); err != nil {
80
+		return nil, err
81
+	}
82
+
83
+	for ii, key := range fields {
84
+		rawValue := reflect.Indirect(reflect.ValueOf(scanResultContainers[ii]))
85
+		// if row is null then as empty string
86
+		if rawValue.Interface() == nil {
87
+			result[key] = ""
88
+			continue
89
+		}
90
+
91
+		if data, err := value2String(&rawValue); err == nil {
92
+			result[key] = data
93
+		} else {
94
+			return nil, err
95
+		}
96
+	}
97
+	return result, nil
98
+}
99
+
100
+func rows2Strings(rows *core.Rows) (resultsSlice []map[string]string, err error) {
101
+	fields, err := rows.Columns()
102
+	if err != nil {
103
+		return nil, err
104
+	}
105
+	for rows.Next() {
106
+		result, err := row2mapStr(rows, fields)
107
+		if err != nil {
108
+			return nil, err
109
+		}
110
+		resultsSlice = append(resultsSlice, result)
111
+	}
112
+
113
+	return resultsSlice, nil
114
+}
115
+
116
+// QueryString runs a raw sql and return records as []map[string]string
117
+func (session *Session) QueryString(sqlStr string, args ...interface{}) ([]map[string]string, error) {
118
+	if session.isAutoClose {
119
+		defer session.Close()
120
+	}
121
+
122
+	rows, err := session.queryRows(sqlStr, args...)
123
+	if err != nil {
124
+		return nil, err
125
+	}
126
+	defer rows.Close()
127
+
128
+	return rows2Strings(rows)
129
+}
130
+
131
+func row2mapInterface(rows *core.Rows, fields []string) (resultsMap map[string]interface{}, err error) {
132
+	resultsMap = make(map[string]interface{}, len(fields))
133
+	scanResultContainers := make([]interface{}, len(fields))
134
+	for i := 0; i < len(fields); i++ {
135
+		var scanResultContainer interface{}
136
+		scanResultContainers[i] = &scanResultContainer
137
+	}
138
+	if err := rows.Scan(scanResultContainers...); err != nil {
139
+		return nil, err
140
+	}
141
+
142
+	for ii, key := range fields {
143
+		resultsMap[key] = reflect.Indirect(reflect.ValueOf(scanResultContainers[ii])).Interface()
144
+	}
145
+	return
146
+}
147
+
148
+func rows2Interfaces(rows *core.Rows) (resultsSlice []map[string]interface{}, err error) {
149
+	fields, err := rows.Columns()
150
+	if err != nil {
151
+		return nil, err
152
+	}
153
+	for rows.Next() {
154
+		result, err := row2mapInterface(rows, fields)
155
+		if err != nil {
156
+			return nil, err
157
+		}
158
+		resultsSlice = append(resultsSlice, result)
159
+	}
160
+
161
+	return resultsSlice, nil
162
+}
163
+
164
+// QueryInterface runs a raw sql and return records as []map[string]interface{}
165
+func (session *Session) QueryInterface(sqlStr string, args ...interface{}) ([]map[string]interface{}, error) {
166
+	if session.isAutoClose {
167
+		defer session.Close()
168
+	}
169
+
170
+	rows, err := session.queryRows(sqlStr, args...)
171
+	if err != nil {
172
+		return nil, err
173
+	}
174
+	defer rows.Close()
175
+
176
+	return rows2Interfaces(rows)
177
+}

+ 80 - 204
vendor/github.com/go-xorm/xorm/session_raw.go

@@ -6,87 +6,85 @@ package xorm
6 6
 
7 7
 import (
8 8
 	"database/sql"
9
-	"fmt"
10 9
 	"reflect"
11
-	"strconv"
12 10
 	"time"
13 11
 
14 12
 	"github.com/go-xorm/core"
15 13
 )
16 14
 
17
-func (session *Session) query(sqlStr string, paramStr ...interface{}) ([]map[string][]byte, error) {
18
-	session.queryPreprocess(&sqlStr, paramStr...)
19
-
20
-	if session.isAutoCommit {
21
-		return session.innerQuery2(sqlStr, paramStr...)
15
+func (session *Session) queryPreprocess(sqlStr *string, paramStr ...interface{}) {
16
+	for _, filter := range session.engine.dialect.Filters() {
17
+		*sqlStr = filter.Do(*sqlStr, session.engine.dialect, session.statement.RefTable)
22 18
 	}
23
-	return session.txQuery(session.tx, sqlStr, paramStr...)
19
+
20
+	session.lastSQL = *sqlStr
21
+	session.lastSQLArgs = paramStr
24 22
 }
25 23
 
26
-func (session *Session) txQuery(tx *core.Tx, sqlStr string, params ...interface{}) ([]map[string][]byte, error) {
27
-	rows, err := tx.Query(sqlStr, params...)
28
-	if err != nil {
29
-		return nil, err
30
-	}
31
-	defer rows.Close()
24
+func (session *Session) queryRows(sqlStr string, args ...interface{}) (*core.Rows, error) {
25
+	defer session.resetStatement()
32 26
 
33
-	return rows2maps(rows)
34
-}
27
+	session.queryPreprocess(&sqlStr, args...)
35 28
 
36
-func (session *Session) innerQuery(sqlStr string, params ...interface{}) (*core.Stmt, *core.Rows, error) {
37
-	var callback func() (*core.Stmt, *core.Rows, error)
38
-	if session.prepareStmt {
39
-		callback = func() (*core.Stmt, *core.Rows, error) {
29
+	if session.engine.showSQL {
30
+		if session.engine.showExecTime {
31
+			b4ExecTime := time.Now()
32
+			defer func() {
33
+				execDuration := time.Since(b4ExecTime)
34
+				if len(args) > 0 {
35
+					session.engine.logger.Infof("[SQL] %s %#v - took: %v", sqlStr, args, execDuration)
36
+				} else {
37
+					session.engine.logger.Infof("[SQL] %s - took: %v", sqlStr, execDuration)
38
+				}
39
+			}()
40
+		} else {
41
+			if len(args) > 0 {
42
+				session.engine.logger.Infof("[SQL] %v %#v", sqlStr, args)
43
+			} else {
44
+				session.engine.logger.Infof("[SQL] %v", sqlStr)
45
+			}
46
+		}
47
+	}
48
+
49
+	if session.isAutoCommit {
50
+		if session.prepareStmt {
51
+			// don't clear stmt since session will cache them
40 52
 			stmt, err := session.doPrepare(sqlStr)
41 53
 			if err != nil {
42
-				return nil, nil, err
54
+				return nil, err
43 55
 			}
44
-			rows, err := stmt.Query(params...)
56
+
57
+			rows, err := stmt.Query(args...)
45 58
 			if err != nil {
46
-				return nil, nil, err
59
+				return nil, err
47 60
 			}
48
-			return stmt, rows, nil
61
+			return rows, nil
49 62
 		}
50
-	} else {
51
-		callback = func() (*core.Stmt, *core.Rows, error) {
52
-			rows, err := session.DB().Query(sqlStr, params...)
53
-			if err != nil {
54
-				return nil, nil, err
55
-			}
56
-			return nil, rows, err
63
+
64
+		rows, err := session.DB().Query(sqlStr, args...)
65
+		if err != nil {
66
+			return nil, err
57 67
 		}
68
+		return rows, nil
58 69
 	}
59
-	stmt, rows, err := session.engine.logSQLQueryTime(sqlStr, params, callback)
60
-	if err != nil {
61
-		return nil, nil, err
62
-	}
63
-	return stmt, rows, nil
64
-}
65 70
 
66
-func rows2maps(rows *core.Rows) (resultsSlice []map[string][]byte, err error) {
67
-	fields, err := rows.Columns()
71
+	rows, err := session.tx.Query(sqlStr, args...)
68 72
 	if err != nil {
69 73
 		return nil, err
70 74
 	}
71
-	for rows.Next() {
72
-		result, err := row2map(rows, fields)
73
-		if err != nil {
74
-			return nil, err
75
-		}
76
-		resultsSlice = append(resultsSlice, result)
77
-	}
75
+	return rows, nil
76
+}
78 77
 
79
-	return resultsSlice, nil
78
+func (session *Session) queryRow(sqlStr string, args ...interface{}) *core.Row {
79
+	return core.NewRow(session.queryRows(sqlStr, args...))
80 80
 }
81 81
 
82
-func value2Bytes(rawValue *reflect.Value) (data []byte, err error) {
83
-	var str string
84
-	str, err = reflect2value(rawValue)
82
+func value2Bytes(rawValue *reflect.Value) ([]byte, error) {
83
+	str, err := value2String(rawValue)
85 84
 	if err != nil {
86
-		return
85
+		return nil, err
87 86
 	}
88
-	data = []byte(str)
89
-	return
87
+	return []byte(str), nil
90 88
 }
91 89
 
92 90
 func row2map(rows *core.Rows, fields []string) (resultsMap map[string][]byte, err error) {
@@ -104,7 +102,7 @@ func row2map(rows *core.Rows, fields []string) (resultsMap map[string][]byte, er
104 102
 		rawValue := reflect.Indirect(reflect.ValueOf(scanResultContainers[ii]))
105 103
 		//if row is null then ignore
106 104
 		if rawValue.Interface() == nil {
107
-			//fmt.Println("ignore ...", key, rawValue)
105
+			result[key] = []byte{}
108 106
 			continue
109 107
 		}
110 108
 
@@ -117,34 +115,13 @@ func row2map(rows *core.Rows, fields []string) (resultsMap map[string][]byte, er
117 115
 	return result, nil
118 116
 }
119 117
 
120
-func (session *Session) innerQuery2(sqlStr string, params ...interface{}) ([]map[string][]byte, error) {
121
-	_, rows, err := session.innerQuery(sqlStr, params...)
122
-	if rows != nil {
123
-		defer rows.Close()
124
-	}
125
-	if err != nil {
126
-		return nil, err
127
-	}
128
-	return rows2maps(rows)
129
-}
130
-
131
-// Query runs a raw sql and return records as []map[string][]byte
132
-func (session *Session) Query(sqlStr string, paramStr ...interface{}) ([]map[string][]byte, error) {
133
-	defer session.resetStatement()
134
-	if session.isAutoClose {
135
-		defer session.Close()
136
-	}
137
-
138
-	return session.query(sqlStr, paramStr...)
139
-}
140
-
141
-func rows2Strings(rows *core.Rows) (resultsSlice []map[string]string, err error) {
118
+func rows2maps(rows *core.Rows) (resultsSlice []map[string][]byte, err error) {
142 119
 	fields, err := rows.Columns()
143 120
 	if err != nil {
144 121
 		return nil, err
145 122
 	}
146 123
 	for rows.Next() {
147
-		result, err := row2mapStr(rows, fields)
124
+		result, err := row2map(rows, fields)
148 125
 		if err != nil {
149 126
 			return nil, err
150 127
 		}
@@ -154,122 +131,45 @@ func rows2Strings(rows *core.Rows) (resultsSlice []map[string]string, err error)
154 131
 	return resultsSlice, nil
155 132
 }
156 133
 
157
-func reflect2value(rawValue *reflect.Value) (str string, err error) {
158
-	aa := reflect.TypeOf((*rawValue).Interface())
159
-	vv := reflect.ValueOf((*rawValue).Interface())
160
-	switch aa.Kind() {
161
-	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
162
-		str = strconv.FormatInt(vv.Int(), 10)
163
-	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
164
-		str = strconv.FormatUint(vv.Uint(), 10)
165
-	case reflect.Float32, reflect.Float64:
166
-		str = strconv.FormatFloat(vv.Float(), 'f', -1, 64)
167
-	case reflect.String:
168
-		str = vv.String()
169
-	case reflect.Array, reflect.Slice:
170
-		switch aa.Elem().Kind() {
171
-		case reflect.Uint8:
172
-			data := rawValue.Interface().([]byte)
173
-			str = string(data)
174
-		default:
175
-			err = fmt.Errorf("Unsupported struct type %v", vv.Type().Name())
176
-		}
177
-	// time type
178
-	case reflect.Struct:
179
-		if aa.ConvertibleTo(core.TimeType) {
180
-			str = vv.Convert(core.TimeType).Interface().(time.Time).Format(time.RFC3339Nano)
181
-		} else {
182
-			err = fmt.Errorf("Unsupported struct type %v", vv.Type().Name())
183
-		}
184
-	case reflect.Bool:
185
-		str = strconv.FormatBool(vv.Bool())
186
-	case reflect.Complex128, reflect.Complex64:
187
-		str = fmt.Sprintf("%v", vv.Complex())
188
-	/* TODO: unsupported types below
189
-	   case reflect.Map:
190
-	   case reflect.Ptr:
191
-	   case reflect.Uintptr:
192
-	   case reflect.UnsafePointer:
193
-	   case reflect.Chan, reflect.Func, reflect.Interface:
194
-	*/
195
-	default:
196
-		err = fmt.Errorf("Unsupported struct type %v", vv.Type().Name())
197
-	}
198
-	return
199
-}
200
-
201
-func value2String(rawValue *reflect.Value) (data string, err error) {
202
-	data, err = reflect2value(rawValue)
203
-	if err != nil {
204
-		return
205
-	}
206
-	return
207
-}
208
-
209
-func row2mapStr(rows *core.Rows, fields []string) (resultsMap map[string]string, err error) {
210
-	result := make(map[string]string)
211
-	scanResultContainers := make([]interface{}, len(fields))
212
-	for i := 0; i < len(fields); i++ {
213
-		var scanResultContainer interface{}
214
-		scanResultContainers[i] = &scanResultContainer
215
-	}
216
-	if err := rows.Scan(scanResultContainers...); err != nil {
217
-		return nil, err
218
-	}
219
-
220
-	for ii, key := range fields {
221
-		rawValue := reflect.Indirect(reflect.ValueOf(scanResultContainers[ii]))
222
-		//if row is null then ignore
223
-		if rawValue.Interface() == nil {
224
-			//fmt.Println("ignore ...", key, rawValue)
225
-			continue
226
-		}
227
-
228
-		if data, err := value2String(&rawValue); err == nil {
229
-			result[key] = data
230
-		} else {
231
-			return nil, err // !nashtsai! REVIEW, should return err or just error log?
232
-		}
233
-	}
234
-	return result, nil
235
-}
236
-
237
-func txQuery2(tx *core.Tx, sqlStr string, params ...interface{}) ([]map[string]string, error) {
238
-	rows, err := tx.Query(sqlStr, params...)
134
+func (session *Session) queryBytes(sqlStr string, args ...interface{}) ([]map[string][]byte, error) {
135
+	rows, err := session.queryRows(sqlStr, args...)
239 136
 	if err != nil {
240 137
 		return nil, err
241 138
 	}
242 139
 	defer rows.Close()
243 140
 
244
-	return rows2Strings(rows)
245
-}
246
-
247
-func query2(db *core.DB, sqlStr string, params ...interface{}) ([]map[string]string, error) {
248
-	rows, err := db.Query(sqlStr, params...)
249
-	if err != nil {
250
-		return nil, err
251
-	}
252
-	defer rows.Close()
253
-	return rows2Strings(rows)
141
+	return rows2maps(rows)
254 142
 }
255 143
 
256
-// QueryString runs a raw sql and return records as []map[string]string
257
-func (session *Session) QueryString(sqlStr string, args ...interface{}) ([]map[string]string, error) {
144
+func (session *Session) exec(sqlStr string, args ...interface{}) (sql.Result, error) {
258 145
 	defer session.resetStatement()
259
-	if session.isAutoClose {
260
-		defer session.Close()
261
-	}
262 146
 
263 147
 	session.queryPreprocess(&sqlStr, args...)
264 148
 
265
-	if session.isAutoCommit {
266
-		return query2(session.DB(), sqlStr, args...)
149
+	if session.engine.showSQL {
150
+		if session.engine.showExecTime {
151
+			b4ExecTime := time.Now()
152
+			defer func() {
153
+				execDuration := time.Since(b4ExecTime)
154
+				if len(args) > 0 {
155
+					session.engine.logger.Infof("[SQL] %s %#v - took: %v", sqlStr, args, execDuration)
156
+				} else {
157
+					session.engine.logger.Infof("[SQL] %s - took: %v", sqlStr, execDuration)
158
+				}
159
+			}()
160
+		} else {
161
+			if len(args) > 0 {
162
+				session.engine.logger.Infof("[SQL] %v %#v", sqlStr, args)
163
+			} else {
164
+				session.engine.logger.Infof("[SQL] %v", sqlStr)
165
+			}
166
+		}
167
+	}
168
+
169
+	if !session.isAutoCommit {
170
+		return session.tx.Exec(sqlStr, args...)
267 171
 	}
268
-	return txQuery2(session.tx, sqlStr, args...)
269
-}
270 172
 
271
-// Execute sql
272
-func (session *Session) innerExec(sqlStr string, args ...interface{}) (sql.Result, error) {
273 173
 	if session.prepareStmt {
274 174
 		stmt, err := session.doPrepare(sqlStr)
275 175
 		if err != nil {
@@ -286,32 +186,8 @@ func (session *Session) innerExec(sqlStr string, args ...interface{}) (sql.Resul
286 186
 	return session.DB().Exec(sqlStr, args...)
287 187
 }
288 188
 
289
-func (session *Session) exec(sqlStr string, args ...interface{}) (sql.Result, error) {
290
-	for _, filter := range session.engine.dialect.Filters() {
291
-		// TODO: for table name, it's no need to RefTable
292
-		sqlStr = filter.Do(sqlStr, session.engine.dialect, session.statement.RefTable)
293
-	}
294
-
295
-	session.saveLastSQL(sqlStr, args...)
296
-
297
-	return session.engine.logSQLExecutionTime(sqlStr, args, func() (sql.Result, error) {
298
-		if session.isAutoCommit {
299
-			// FIXME: oci8 can not auto commit (github.com/mattn/go-oci8)
300
-			if session.engine.dialect.DBType() == core.ORACLE {
301
-				session.Begin()
302
-				r, err := session.tx.Exec(sqlStr, args...)
303
-				session.Commit()
304
-				return r, err
305
-			}
306
-			return session.innerExec(sqlStr, args...)
307
-		}
308
-		return session.tx.Exec(sqlStr, args...)
309
-	})
310
-}
311
-
312 189
 // Exec raw sql
313 190
 func (session *Session) Exec(sqlStr string, args ...interface{}) (sql.Result, error) {
314
-	defer session.resetStatement()
315 191
 	if session.isAutoClose {
316 192
 		defer session.Close()
317 193
 	}

+ 3 - 22
vendor/github.com/go-xorm/xorm/session_schema.go

@@ -16,7 +16,6 @@ import (
16 16
 
17 17
 // Ping test if database is ok
18 18
 func (session *Session) Ping() error {
19
-	defer session.resetStatement()
20 19
 	if session.isAutoClose {
21 20
 		defer session.Close()
22 21
 	}
@@ -35,7 +34,6 @@ func (session *Session) CreateTable(bean interface{}) error {
35 34
 }
36 35
 
37 36
 func (session *Session) createTable(bean interface{}) error {
38
-	defer session.resetStatement()
39 37
 	v := rValue(bean)
40 38
 	if err := session.statement.setRefValue(v); err != nil {
41 39
 		return err
@@ -56,7 +54,6 @@ func (session *Session) CreateIndexes(bean interface{}) error {
56 54
 }
57 55
 
58 56
 func (session *Session) createIndexes(bean interface{}) error {
59
-	defer session.resetStatement()
60 57
 	v := rValue(bean)
61 58
 	if err := session.statement.setRefValue(v); err != nil {
62 59
 		return err
@@ -81,7 +78,6 @@ func (session *Session) CreateUniques(bean interface{}) error {
81 78
 }
82 79
 
83 80
 func (session *Session) createUniques(bean interface{}) error {
84
-	defer session.resetStatement()
85 81
 	v := rValue(bean)
86 82
 	if err := session.statement.setRefValue(v); err != nil {
87 83
 		return err
@@ -107,7 +103,6 @@ func (session *Session) DropIndexes(bean interface{}) error {
107 103
 }
108 104
 
109 105
 func (session *Session) dropIndexes(bean interface{}) error {
110
-	defer session.resetStatement()
111 106
 	v := rValue(bean)
112 107
 	if err := session.statement.setRefValue(v); err != nil {
113 108
 		return err
@@ -133,7 +128,6 @@ func (session *Session) DropTable(beanOrTableName interface{}) error {
133 128
 }
134 129
 
135 130
 func (session *Session) dropTable(beanOrTableName interface{}) error {
136
-	defer session.resetStatement()
137 131
 	tableName, err := session.engine.tableName(beanOrTableName)
138 132
 	if err != nil {
139 133
 		return err
@@ -142,7 +136,7 @@ func (session *Session) dropTable(beanOrTableName interface{}) error {
142 136
 	var needDrop = true
143 137
 	if !session.engine.dialect.SupportDropIfExists() {
144 138
 		sqlStr, args := session.engine.dialect.TableCheckSql(tableName)
145
-		results, err := session.query(sqlStr, args...)
139
+		results, err := session.queryBytes(sqlStr, args...)
146 140
 		if err != nil {
147 141
 			return err
148 142
 		}
@@ -172,9 +166,8 @@ func (session *Session) IsTableExist(beanOrTableName interface{}) (bool, error)
172 166
 }
173 167
 
174 168
 func (session *Session) isTableExist(tableName string) (bool, error) {
175
-	defer session.resetStatement()
176 169
 	sqlStr, args := session.engine.dialect.TableCheckSql(tableName)
177
-	results, err := session.query(sqlStr, args...)
170
+	results, err := session.queryBytes(sqlStr, args...)
178 171
 	return len(results) > 0, err
179 172
 }
180 173
 
@@ -196,12 +189,9 @@ func (session *Session) IsTableEmpty(bean interface{}) (bool, error) {
196 189
 }
197 190
 
198 191
 func (session *Session) isTableEmpty(tableName string) (bool, error) {
199
-	defer session.resetStatement()
200
-
201 192
 	var total int64
202 193
 	sqlStr := fmt.Sprintf("select count(*) from %s", session.engine.Quote(tableName))
203
-	err := session.DB().QueryRow(sqlStr).Scan(&total)
204
-	session.saveLastSQL(sqlStr)
194
+	err := session.queryRow(sqlStr).Scan(&total)
205 195
 	if err != nil {
206 196
 		if err == sql.ErrNoRows {
207 197
 			err = nil
@@ -214,8 +204,6 @@ func (session *Session) isTableEmpty(tableName string) (bool, error) {
214 204
 
215 205
 // find if index is exist according cols
216 206
 func (session *Session) isIndexExist2(tableName string, cols []string, unique bool) (bool, error) {
217
-	defer session.resetStatement()
218
-
219 207
 	indexes, err := session.engine.dialect.GetIndexes(tableName)
220 208
 	if err != nil {
221 209
 		return false, err
@@ -233,8 +221,6 @@ func (session *Session) isIndexExist2(tableName string, cols []string, unique bo
233 221
 }
234 222
 
235 223
 func (session *Session) addColumn(colName string) error {
236
-	defer session.resetStatement()
237
-
238 224
 	col := session.statement.RefTable.GetColumn(colName)
239 225
 	sql, args := session.statement.genAddColumnStr(col)
240 226
 	_, err := session.exec(sql, args...)
@@ -242,18 +228,13 @@ func (session *Session) addColumn(colName string) error {
242 228
 }
243 229
 
244 230
 func (session *Session) addIndex(tableName, idxName string) error {
245
-	defer session.resetStatement()
246
-
247 231
 	index := session.statement.RefTable.Indexes[idxName]
248 232
 	sqlStr := session.engine.dialect.CreateIndexSql(tableName, index)
249
-
250 233
 	_, err := session.exec(sqlStr)
251 234
 	return err
252 235
 }
253 236
 
254 237
 func (session *Session) addUnique(tableName, uqeName string) error {
255
-	defer session.resetStatement()
256
-
257 238
 	index := session.statement.RefTable.Indexes[uqeName]
258 239
 	sqlStr := session.engine.dialect.CreateIndexSql(tableName, index)
259 240
 	_, err := session.exec(sqlStr)

+ 3 - 23
vendor/github.com/go-xorm/xorm/session_stats.go

@@ -13,7 +13,6 @@ import (
13 13
 // Count counts the records. bean's non-empty fields
14 14
 // are conditions.
15 15
 func (session *Session) Count(bean ...interface{}) (int64, error) {
16
-	defer session.resetStatement()
17 16
 	if session.isAutoClose {
18 17
 		defer session.Close()
19 18
 	}
@@ -31,15 +30,8 @@ func (session *Session) Count(bean ...interface{}) (int64, error) {
31 30
 		args = session.statement.RawParams
32 31
 	}
33 32
 
34
-	session.queryPreprocess(&sqlStr, args...)
35
-
36 33
 	var total int64
37
-	if session.isAutoCommit {
38
-		err = session.DB().QueryRow(sqlStr, args...).Scan(&total)
39
-	} else {
40
-		err = session.tx.QueryRow(sqlStr, args...).Scan(&total)
41
-	}
42
-
34
+	err = session.queryRow(sqlStr, args...).Scan(&total)
43 35
 	if err == sql.ErrNoRows || err == nil {
44 36
 		return total, nil
45 37
 	}
@@ -49,7 +41,6 @@ func (session *Session) Count(bean ...interface{}) (int64, error) {
49 41
 
50 42
 // sum call sum some column. bean's non-empty fields are conditions.
51 43
 func (session *Session) sum(res interface{}, bean interface{}, columnNames ...string) error {
52
-	defer session.resetStatement()
53 44
 	if session.isAutoClose {
54 45
 		defer session.Close()
55 46
 	}
@@ -73,22 +64,11 @@ func (session *Session) sum(res interface{}, bean interface{}, columnNames ...st
73 64
 		args = session.statement.RawParams
74 65
 	}
75 66
 
76
-	session.queryPreprocess(&sqlStr, args...)
77
-
78 67
 	if isSlice {
79
-		if session.isAutoCommit {
80
-			err = session.DB().QueryRow(sqlStr, args...).ScanSlice(res)
81
-		} else {
82
-			err = session.tx.QueryRow(sqlStr, args...).ScanSlice(res)
83
-		}
68
+		err = session.queryRow(sqlStr, args...).ScanSlice(res)
84 69
 	} else {
85
-		if session.isAutoCommit {
86
-			err = session.DB().QueryRow(sqlStr, args...).Scan(res)
87
-		} else {
88
-			err = session.tx.QueryRow(sqlStr, args...).Scan(res)
89
-		}
70
+		err = session.queryRow(sqlStr, args...).Scan(res)
90 71
 	}
91
-
92 72
 	if err == sql.ErrNoRows || err == nil {
93 73
 		return nil
94 74
 	}

+ 15 - 16
vendor/github.com/go-xorm/xorm/session_update.go

@@ -15,8 +15,8 @@ import (
15 15
 	"github.com/go-xorm/core"
16 16
 )
17 17
 
18
-func (session *Session) cacheUpdate(sqlStr string, args ...interface{}) error {
19
-	if session.statement.RefTable == nil ||
18
+func (session *Session) cacheUpdate(table *core.Table, tableName, sqlStr string, args ...interface{}) error {
19
+	if table == nil ||
20 20
 		session.tx != nil {
21 21
 		return ErrCacheFailed
22 22
 	}
@@ -26,7 +26,7 @@ func (session *Session) cacheUpdate(sqlStr string, args ...interface{}) error {
26 26
 		return ErrCacheFailed
27 27
 	}
28 28
 	for _, filter := range session.engine.dialect.Filters() {
29
-		newsql = filter.Do(newsql, session.engine.dialect, session.statement.RefTable)
29
+		newsql = filter.Do(newsql, session.engine.dialect, table)
30 30
 	}
31 31
 	session.engine.logger.Debug("[cacheUpdate] new sql", oldhead, newsql)
32 32
 
@@ -39,13 +39,12 @@ func (session *Session) cacheUpdate(sqlStr string, args ...interface{}) error {
39 39
 			nStart = strings.Count(oldhead, "$")
40 40
 		}
41 41
 	}
42
-	table := session.statement.RefTable
42
+
43 43
 	cacher := session.engine.getCacher2(table)
44
-	tableName := session.statement.TableName()
45 44
 	session.engine.logger.Debug("[cacheUpdate] get cache sql", newsql, args[nStart:])
46 45
 	ids, err := core.GetCacheSql(cacher, tableName, newsql, args[nStart:])
47 46
 	if err != nil {
48
-		rows, err := session.DB().Query(newsql, args[nStart:]...)
47
+		rows, err := session.NoCache().queryRows(newsql, args[nStart:]...)
49 48
 		if err != nil {
50 49
 			return err
51 50
 		}
@@ -144,7 +143,6 @@ func (session *Session) cacheUpdate(sqlStr string, args ...interface{}) error {
144 143
 //         You should call UseBool if you have bool to use.
145 144
 //        2.float32 & float64 may be not inexact as conditions
146 145
 func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int64, error) {
147
-	defer session.resetStatement()
148 146
 	if session.isAutoClose {
149 147
 		defer session.Close()
150 148
 	}
@@ -249,8 +247,7 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6
249 247
 		}
250 248
 	}
251 249
 
252
-	st := session.statement
253
-	defer session.resetStatement()
250
+	st := &session.statement
254 251
 
255 252
 	var sqlStr string
256 253
 	var condArgs []interface{}
@@ -282,6 +279,7 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6
282 279
 		condSQL = condSQL + fmt.Sprintf(" ORDER BY %v", st.OrderStr)
283 280
 	}
284 281
 
282
+	var tableName = session.statement.TableName()
285 283
 	// TODO: Oracle support needed
286 284
 	var top string
287 285
 	if st.LimitN > 0 {
@@ -290,7 +288,7 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6
290 288
 		} else if st.Engine.dialect.DBType() == core.SQLITE {
291 289
 			tempCondSQL := condSQL + fmt.Sprintf(" LIMIT %d", st.LimitN)
292 290
 			cond = cond.And(builder.Expr(fmt.Sprintf("rowid IN (SELECT rowid FROM %v %v)",
293
-				session.engine.Quote(session.statement.TableName()), tempCondSQL), condArgs...))
291
+				session.engine.Quote(tableName), tempCondSQL), condArgs...))
294 292
 			condSQL, condArgs, err = builder.ToSQL(cond)
295 293
 			if err != nil {
296 294
 				return 0, err
@@ -301,7 +299,7 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6
301 299
 		} else if st.Engine.dialect.DBType() == core.POSTGRES {
302 300
 			tempCondSQL := condSQL + fmt.Sprintf(" LIMIT %d", st.LimitN)
303 301
 			cond = cond.And(builder.Expr(fmt.Sprintf("CTID IN (SELECT CTID FROM %v %v)",
304
-				session.engine.Quote(session.statement.TableName()), tempCondSQL), condArgs...))
302
+				session.engine.Quote(tableName), tempCondSQL), condArgs...))
305 303
 			condSQL, condArgs, err = builder.ToSQL(cond)
306 304
 			if err != nil {
307 305
 				return 0, err
@@ -315,7 +313,7 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6
315 313
 				table != nil && len(table.PrimaryKeys) == 1 {
316 314
 				cond = builder.Expr(fmt.Sprintf("%s IN (SELECT TOP (%d) %s FROM %v%v)",
317 315
 					table.PrimaryKeys[0], st.LimitN, table.PrimaryKeys[0],
318
-					session.engine.Quote(session.statement.TableName()), condSQL), condArgs...)
316
+					session.engine.Quote(tableName), condSQL), condArgs...)
319 317
 
320 318
 				condSQL, condArgs, err = builder.ToSQL(cond)
321 319
 				if err != nil {
@@ -336,7 +334,7 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6
336 334
 
337 335
 	sqlStr = fmt.Sprintf("UPDATE %v%v SET %v %v",
338 336
 		top,
339
-		session.engine.Quote(session.statement.TableName()),
337
+		session.engine.Quote(tableName),
340 338
 		strings.Join(colNames, ", "),
341 339
 		condSQL)
342 340
 
@@ -351,8 +349,9 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6
351 349
 
352 350
 	if table != nil {
353 351
 		if cacher := session.engine.getCacher2(table); cacher != nil && session.statement.UseCache {
354
-			cacher.ClearIds(session.statement.TableName())
355
-			cacher.ClearBeans(session.statement.TableName())
352
+			//session.cacheUpdate(table, tableName, sqlStr, args...)
353
+			cacher.ClearIds(tableName)
354
+			cacher.ClearBeans(tableName)
356 355
 		}
357 356
 	}
358 357
 
@@ -362,7 +361,7 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6
362 361
 			closure(bean)
363 362
 		}
364 363
 		if processor, ok := interface{}(bean).(AfterUpdateProcessor); ok {
365
-			session.engine.logger.Debug("[event]", session.statement.TableName(), " has after update processor")
364
+			session.engine.logger.Debug("[event]", tableName, " has after update processor")
366 365
 			processor.AfterUpdate()
367 366
 		}
368 367
 	} else {

+ 2 - 1
vendor/github.com/go-xorm/xorm/statement.go

@@ -1205,7 +1205,8 @@ func (statement *Statement) convertIDSQL(sqlStr string) string {
1205 1205
 			top = fmt.Sprintf("TOP %d ", statement.LimitN)
1206 1206
 		}
1207 1207
 
1208
-		return fmt.Sprintf("SELECT %s%s FROM %v", top, colstrs, sqls[1])
1208
+		newsql := fmt.Sprintf("SELECT %s%s FROM %v", top, colstrs, sqls[1])
1209
+		return newsql
1209 1210
 	}
1210 1211
 	return ""
1211 1212
 }

+ 1 - 0
vendor/github.com/go-xorm/xorm/test_mssql_cache.sh

@@ -0,0 +1 @@
1
+go test -db=mssql -conn_str="server=192.168.1.58;user id=sa;password=123456;database=xorm_test" -cache=true

+ 1 - 0
vendor/github.com/go-xorm/xorm/test_mymysql_cache.sh

@@ -0,0 +1 @@
1
+go test -db=mymysql -conn_str="xorm_test/root/" -cache=true

+ 1 - 0
vendor/github.com/go-xorm/xorm/test_mysql_cache.sh

@@ -0,0 +1 @@
1
+go test -db=mysql -conn_str="root:@/xorm_test" -cache=true

+ 1 - 0
vendor/github.com/go-xorm/xorm/test_postgres_cache.sh

@@ -0,0 +1 @@
1
+go test -db=postgres -conn_str="dbname=xorm_test sslmode=disable" -cache=true

+ 1 - 0
vendor/github.com/go-xorm/xorm/test_sqlite_cache.sh

@@ -0,0 +1 @@
1
+go test -db=sqlite3 -conn_str="./test.db?cache=shared&mode=rwc" -cache=true

+ 1 - 1
vendor/github.com/go-xorm/xorm/xorm.go

@@ -17,7 +17,7 @@ import (
17 17
 
18 18
 const (
19 19
 	// Version show the xorm's version
20
-	Version string = "0.6.3.0713"
20
+	Version string = "0.6.4.0910"
21 21
 )
22 22
 
23 23
 func regDrvsNDialects() bool {

+ 6 - 6
vendor/vendor.json

@@ -456,10 +456,10 @@
456 456
 			"revisionTime": "2017-05-19T03:21:30Z"
457 457
 		},
458 458
 		{
459
-			"checksumSHA1": "KOHXTLwpgTMxBB9aGF2aIxkWdm8=",
459
+			"checksumSHA1": "HMavuxvDhKOwmbbFnYt9hfT6jE0=",
460 460
 			"path": "github.com/go-xorm/core",
461
-			"revision": "71c1070a861118827352b1394eb86cbfeef5c513",
462
-			"revisionTime": "2017-08-22T05:50:40Z"
461
+			"revision": "da1adaf7a28ca792961721a34e6e04945200c890",
462
+			"revisionTime": "2017-09-09T08:56:53Z"
463 463
 		},
464 464
 		{
465 465
 			"checksumSHA1": "k52lEKLp8j5M+jFpe+3u+bIFpxQ=",
@@ -468,10 +468,10 @@
468 468
 			"revisionTime": "2016-08-11T02:11:45Z"
469 469
 		},
470 470
 		{
471
-			"checksumSHA1": "0F65zfDi1ys3KD/wMKtxC2k13DA=",
471
+			"checksumSHA1": "SoZDnkd5NdwE0g4MY1nTAl8ZtPo=",
472 472
 			"path": "github.com/go-xorm/xorm",
473
-			"revision": "a10b5aba4bb97b30daa74e7c0363d3084ede0514",
474
-			"revisionTime": "2017-08-20T09:05:42Z"
473
+			"revision": "c29485f954ed6495861c0098f9a1642a467299c8",
474
+			"revisionTime": "2017-09-10T12:58:18Z"
475 475
 		},
476 476
 		{
477 477
 			"checksumSHA1": "1ft/4j5MFa7C9dPI9whL03HSUzk=",