Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
张磊
/
FileStorageBeego
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
a4df6e40
authored
2013-11-01 18:32:03 +0800
by
slene
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fix #265
1 parent
00abdcd0
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
8 deletions
orm/db.go
orm/orm_test.go
orm/db.go
View file @
a4df6e4
...
...
@@ -393,7 +393,7 @@ func (d *dbBase) UpdateBatch(q dbQuerier, qs *querySet, mi *modelInfo, cond *Con
join
:=
tables
.
getJoinSql
()
var
query
,
T
,
cols
string
var
query
,
T
string
Q
:=
d
.
ins
.
TableQuote
()
...
...
@@ -401,30 +401,34 @@ func (d *dbBase) UpdateBatch(q dbQuerier, qs *querySet, mi *modelInfo, cond *Con
T
=
"T0."
}
cols
:=
make
([]
string
,
0
,
len
(
columns
))
for
i
,
v
:=
range
columns
{
col
:=
fmt
.
Sprintf
(
"%s%s%s%s"
,
T
,
Q
,
v
,
Q
)
if
c
,
ok
:=
values
[
i
]
.
(
colValue
);
ok
{
switch
c
.
opt
{
case
Col_Add
:
cols
+=
col
+
" = "
+
col
+
" + ? "
cols
=
append
(
cols
,
col
+
" = "
+
col
+
" + ?"
)
case
Col_Minus
:
cols
+=
col
+
" = "
+
col
+
" - ? "
cols
=
append
(
cols
,
col
+
" = "
+
col
+
" - ?"
)
case
Col_Multiply
:
cols
+=
col
+
" = "
+
col
+
" * ? "
cols
=
append
(
cols
,
col
+
" = "
+
col
+
" * ?"
)
case
Col_Except
:
cols
+=
col
+
" = "
+
col
+
" / ? "
cols
=
append
(
cols
,
col
+
" = "
+
col
+
" / ?"
)
}
values
[
i
]
=
c
.
value
}
else
{
cols
+=
col
+
" = ? "
cols
=
append
(
cols
,
col
+
" = ?"
)
}
}
sets
:=
strings
.
Join
(
cols
,
", "
)
+
" "
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
{
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
)
...
...
orm/orm_test.go
View file @
a4df6e4
...
...
@@ -1514,6 +1514,7 @@ func TestUpdate(t *testing.T) {
qs
:=
dORM
.
QueryTable
(
"user"
)
num
,
err
:=
qs
.
Filter
(
"user_name"
,
"slene"
)
.
Filter
(
"is_staff"
,
false
)
.
Update
(
Params
{
"is_staff"
:
true
,
"is_active"
:
true
,
})
throwFail
(
t
,
err
)
throwFail
(
t
,
AssertIs
(
num
,
1
))
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
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 post a comment