Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
a4df6e40
Commit
a4df6e40
authored
Nov 01, 2013
by
slene
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix #265
parent
00abdcd0
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
8 deletions
+13
-8
db.go
orm/db.go
+12
-8
orm_test.go
orm/orm_test.go
+1
-0
No files found.
orm/db.go
View file @
a4df6e40
...
@@ -393,7 +393,7 @@ func (d *dbBase) UpdateBatch(q dbQuerier, qs *querySet, mi *modelInfo, cond *Con
...
@@ -393,7 +393,7 @@ func (d *dbBase) UpdateBatch(q dbQuerier, qs *querySet, mi *modelInfo, cond *Con
join
:=
tables
.
getJoinSql
()
join
:=
tables
.
getJoinSql
()
var
query
,
T
,
cols
string
var
query
,
T
string
Q
:=
d
.
ins
.
TableQuote
()
Q
:=
d
.
ins
.
TableQuote
()
...
@@ -401,30 +401,34 @@ func (d *dbBase) UpdateBatch(q dbQuerier, qs *querySet, mi *modelInfo, cond *Con
...
@@ -401,30 +401,34 @@ func (d *dbBase) UpdateBatch(q dbQuerier, qs *querySet, mi *modelInfo, cond *Con
T
=
"T0."
T
=
"T0."
}
}
cols
:=
make
([]
string
,
0
,
len
(
columns
))
for
i
,
v
:=
range
columns
{
for
i
,
v
:=
range
columns
{
col
:=
fmt
.
Sprintf
(
"%s%s%s%s"
,
T
,
Q
,
v
,
Q
)
col
:=
fmt
.
Sprintf
(
"%s%s%s%s"
,
T
,
Q
,
v
,
Q
)
if
c
,
ok
:=
values
[
i
]
.
(
colValue
);
ok
{
if
c
,
ok
:=
values
[
i
]
.
(
colValue
);
ok
{
switch
c
.
opt
{
switch
c
.
opt
{
case
Col_Add
:
case
Col_Add
:
cols
+=
col
+
" = "
+
col
+
" + ? "
cols
=
append
(
cols
,
col
+
" = "
+
col
+
" + ?"
)
case
Col_Minus
:
case
Col_Minus
:
cols
+=
col
+
" = "
+
col
+
" - ? "
cols
=
append
(
cols
,
col
+
" = "
+
col
+
" - ?"
)
case
Col_Multiply
:
case
Col_Multiply
:
cols
+=
col
+
" = "
+
col
+
" * ? "
cols
=
append
(
cols
,
col
+
" = "
+
col
+
" * ?"
)
case
Col_Except
:
case
Col_Except
:
cols
+=
col
+
" = "
+
col
+
" / ? "
cols
=
append
(
cols
,
col
+
" = "
+
col
+
" / ?"
)
}
}
values
[
i
]
=
c
.
value
values
[
i
]
=
c
.
value
}
else
{
}
else
{
cols
+=
col
+
" = ? "
cols
=
append
(
cols
,
col
+
" = ?"
)
}
}
}
}
sets
:=
strings
.
Join
(
cols
,
", "
)
+
" "
if
d
.
ins
.
SupportUpdateJoin
()
{
if
d
.
ins
.
SupportUpdateJoin
()
{
query
=
fmt
.
Sprintf
(
"UPDATE %s%s%s T0 %sSET %s%s"
,
Q
,
mi
.
table
,
Q
,
join
,
col
s
,
where
)
query
=
fmt
.
Sprintf
(
"UPDATE %s%s%s T0 %sSET %s%s"
,
Q
,
mi
.
table
,
Q
,
join
,
set
s
,
where
)
}
else
{
}
else
{
supQuery
:=
fmt
.
Sprintf
(
"SELECT T0.%s%s%s FROM %s%s%s T0 %s%s"
,
Q
,
mi
.
fields
.
pk
.
column
,
Q
,
Q
,
mi
.
table
,
Q
,
join
,
where
)
supQuery
:=
fmt
.
Sprintf
(
"SELECT T0.%s%s%s FROM %s%s%s T0 %s%s"
,
Q
,
mi
.
fields
.
pk
.
column
,
Q
,
Q
,
mi
.
table
,
Q
,
join
,
where
)
query
=
fmt
.
Sprintf
(
"UPDATE %s%s%s SET %sWHERE %s%s%s IN ( %s )"
,
Q
,
mi
.
table
,
Q
,
col
s
,
Q
,
mi
.
fields
.
pk
.
column
,
Q
,
supQuery
)
query
=
fmt
.
Sprintf
(
"UPDATE %s%s%s SET %sWHERE %s%s%s IN ( %s )"
,
Q
,
mi
.
table
,
Q
,
set
s
,
Q
,
mi
.
fields
.
pk
.
column
,
Q
,
supQuery
)
}
}
d
.
ins
.
ReplaceMarks
(
&
query
)
d
.
ins
.
ReplaceMarks
(
&
query
)
...
...
orm/orm_test.go
View file @
a4df6e40
...
@@ -1514,6 +1514,7 @@ func TestUpdate(t *testing.T) {
...
@@ -1514,6 +1514,7 @@ func TestUpdate(t *testing.T) {
qs
:=
dORM
.
QueryTable
(
"user"
)
qs
:=
dORM
.
QueryTable
(
"user"
)
num
,
err
:=
qs
.
Filter
(
"user_name"
,
"slene"
)
.
Filter
(
"is_staff"
,
false
)
.
Update
(
Params
{
num
,
err
:=
qs
.
Filter
(
"user_name"
,
"slene"
)
.
Filter
(
"is_staff"
,
false
)
.
Update
(
Params
{
"is_staff"
:
true
,
"is_staff"
:
true
,
"is_active"
:
true
,
})
})
throwFail
(
t
,
err
)
throwFail
(
t
,
err
)
throwFail
(
t
,
AssertIs
(
num
,
1
))
throwFail
(
t
,
AssertIs
(
num
,
1
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment