good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
U
upper
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
open
upper
Commits
6b3eea05
Commit
6b3eea05
authored
Jul 7, 2015
by
Peter Kieltyka
Browse files
Options
Downloads
Plain Diff
Merge branch 'issue-79' into v2
parents
1ffab3d6
bc354737
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
db_test.go
+53
-1
53 additions, 1 deletion
db_test.go
util/sqlutil/convert.go
+22
-7
22 additions, 7 deletions
util/sqlutil/convert.go
with
75 additions
and
8 deletions
db_test.go
+
53
−
1
View file @
6b3eea05
...
@@ -847,14 +847,62 @@ func TestFibonacci(t *testing.T) {
...
@@ -847,14 +847,62 @@ func TestFibonacci(t *testing.T) {
t
.
Fatalf
(
`%s: Unexpected count %d.`
,
wrapper
,
total
)
t
.
Fatalf
(
`%s: Unexpected count %d.`
,
wrapper
,
total
)
}
}
// Find() with no arguments.
res
=
col
.
Find
()
res
=
col
.
Find
()
total
,
err
=
res
.
Count
()
total
,
err
=
res
.
Count
()
if
total
!=
6
{
if
total
!=
6
{
t
.
Fatalf
(
`%s: Unexpected count %d.`
,
wrapper
,
total
)
t
.
Fatalf
(
`%s: Unexpected count %d.`
,
wrapper
,
total
)
}
}
// Find() with empty db.Cond.
res1
:=
col
.
Find
(
db
.
Cond
{})
total
,
err
=
res1
.
Count
()
if
total
!=
6
{
t
.
Fatalf
(
`%s: Unexpected count %d.`
,
wrapper
,
total
)
}
// Find() with explicit IS NULL
res2
:=
col
.
Find
(
db
.
Cond
{
"input IS"
:
nil
})
total
,
err
=
res2
.
Count
()
if
total
!=
0
{
t
.
Fatalf
(
`%s: Unexpected count %d.`
,
wrapper
,
total
)
}
// Find() with implicit IS NULL
res2a
:=
col
.
Find
(
db
.
Cond
{
"input"
:
nil
})
total
,
err
=
res2a
.
Count
()
if
total
!=
0
{
t
.
Fatalf
(
`%s: Unexpected count %d.`
,
wrapper
,
total
)
}
// Find() with explicit = NULL
res2b
:=
col
.
Find
(
db
.
Cond
{
"input ="
:
nil
})
total
,
err
=
res2b
.
Count
()
if
total
!=
0
{
t
.
Fatalf
(
`%s: Unexpected count %d.`
,
wrapper
,
total
)
}
// Find() with implicit IN
res3
:=
col
.
Find
(
db
.
Cond
{
"input"
:
[]
int
{
1
,
2
,
3
,
4
}})
total
,
err
=
res3
.
Count
()
if
total
!=
3
{
t
.
Fatalf
(
`%s: Unexpected count %d.`
,
wrapper
,
total
)
}
// Find() with implicit NOT IN
res3a
:=
col
.
Find
(
db
.
Cond
{
"input NOT IN"
:
[]
int
{
1
,
2
,
3
,
4
}})
total
,
err
=
res3a
.
Count
()
if
total
!=
3
{
t
.
Fatalf
(
`%s: Unexpected count %d.`
,
wrapper
,
total
)
}
var
items
[]
fibonacci
var
items
[]
fibonacci
err
=
res
.
All
(
&
items
)
err
=
res
.
All
(
&
items
)
...
@@ -862,6 +910,10 @@ func TestFibonacci(t *testing.T) {
...
@@ -862,6 +910,10 @@ func TestFibonacci(t *testing.T) {
t
.
Fatalf
(
`%s: %q`
,
wrapper
,
err
)
t
.
Fatalf
(
`%s: %q`
,
wrapper
,
err
)
}
}
if
len
(
items
)
!=
6
{
t
.
Fatalf
(
`Waiting for 6 items.`
)
}
for
_
,
item
:=
range
items
{
for
_
,
item
:=
range
items
{
switch
item
.
Input
{
switch
item
.
Input
{
case
0
:
case
0
:
...
...
This diff is collapsed.
Click to expand it.
util/sqlutil/convert.go
+
22
−
7
View file @
6b3eea05
...
@@ -11,6 +11,9 @@ import (
...
@@ -11,6 +11,9 @@ import (
var
(
var
(
sqlPlaceholder
=
sqlgen
.
RawValue
(
`?`
)
sqlPlaceholder
=
sqlgen
.
RawValue
(
`?`
)
sqlNull
=
sqlgen
.
RawValue
(
`NULL`
)
sqlNull
=
sqlgen
.
RawValue
(
`NULL`
)
sqlIsOperator
=
`IS`
sqlInOperator
=
`IN`
sqlDefaultOperator
=
`=`
)
)
type
TemplateWithUtils
struct
{
type
TemplateWithUtils
struct
{
...
@@ -122,8 +125,6 @@ func (tu *TemplateWithUtils) ToColumnValues(cond db.Cond) (ToColumnValues sqlgen
...
@@ -122,8 +125,6 @@ func (tu *TemplateWithUtils) ToColumnValues(cond db.Cond) (ToColumnValues sqlgen
if
len
(
chunks
)
>
1
{
if
len
(
chunks
)
>
1
{
columnValue
.
Operator
=
chunks
[
1
]
columnValue
.
Operator
=
chunks
[
1
]
}
else
{
columnValue
.
Operator
=
tu
.
DefaultOperator
}
}
switch
value
:=
value
.
(
type
)
{
switch
value
:=
value
.
(
type
)
{
...
@@ -143,14 +144,19 @@ func (tu *TemplateWithUtils) ToColumnValues(cond db.Cond) (ToColumnValues sqlgen
...
@@ -143,14 +144,19 @@ func (tu *TemplateWithUtils) ToColumnValues(cond db.Cond) (ToColumnValues sqlgen
default
:
default
:
v
:=
tu
.
ToInterfaceArguments
(
value
)
v
:=
tu
.
ToInterfaceArguments
(
value
)
l
:=
len
(
v
)
if
v
==
nil
{
if
v
==
nil
||
l
==
0
{
// Nil value given.
// Nil value given.
columnValue
.
Value
=
sqlNull
columnValue
.
Value
=
sqlNull
if
columnValue
.
Operator
==
""
{
columnValue
.
Operator
=
sqlIsOperator
}
}
else
{
}
else
{
if
l
>
1
{
if
l
en
(
v
)
>
1
{
// Array value given.
// Array value given.
columnValue
.
Value
=
sqlgen
.
RawValue
(
fmt
.
Sprintf
(
`(?%s)`
,
strings
.
Repeat
(
`, ?`
,
len
(
v
)
-
1
)))
columnValue
.
Value
=
sqlgen
.
RawValue
(
fmt
.
Sprintf
(
`(?%s)`
,
strings
.
Repeat
(
`, ?`
,
len
(
v
)
-
1
)))
if
columnValue
.
Operator
==
""
{
columnValue
.
Operator
=
sqlInOperator
}
}
else
{
}
else
{
// Single value given.
// Single value given.
columnValue
.
Value
=
sqlPlaceholder
columnValue
.
Value
=
sqlPlaceholder
...
@@ -159,6 +165,15 @@ func (tu *TemplateWithUtils) ToColumnValues(cond db.Cond) (ToColumnValues sqlgen
...
@@ -159,6 +165,15 @@ func (tu *TemplateWithUtils) ToColumnValues(cond db.Cond) (ToColumnValues sqlgen
}
}
}
}
// Using guessed operator if no operator was given.
if
columnValue
.
Operator
==
""
{
if
tu
.
DefaultOperator
!=
""
{
columnValue
.
Operator
=
tu
.
DefaultOperator
}
else
{
columnValue
.
Operator
=
sqlDefaultOperator
}
}
ToColumnValues
.
ColumnValues
=
append
(
ToColumnValues
.
ColumnValues
,
&
columnValue
)
ToColumnValues
.
ColumnValues
=
append
(
ToColumnValues
.
ColumnValues
,
&
columnValue
)
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment