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
0eccd828
Commit
0eccd828
authored
Apr 18, 2015
by
José Carlos Nieto
Browse files
Options
Downloads
Patches
Plain Diff
Updating main test for MySQL.
parent
79896025
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
main_test.go
+10
-6
10 additions, 6 deletions
main_test.go
mysql/database.go
+2
-0
2 additions, 0 deletions
mysql/database.go
mysql/database_test.go
+12
-10
12 additions, 10 deletions
mysql/database_test.go
mysql/result.go
+17
-18
17 additions, 18 deletions
mysql/result.go
with
41 additions
and
34 deletions
main_test.go
+
10
−
6
View file @
0eccd828
...
@@ -35,7 +35,8 @@ import (
...
@@ -35,7 +35,8 @@ import (
"gopkg.in/mgo.v2/bson"
"gopkg.in/mgo.v2/bson"
"upper.io/db"
"upper.io/db"
_
"upper.io/db/mongo"
_
"upper.io/db/mongo"
//_ "upper.io/db/mysql" // Disabled temporarily.
"upper.io/db/mysql"
"upper.io/db/postgresql"
"upper.io/db/postgresql"
// Temporary removing QL. It includes a _solaris.go file that produces
// Temporary removing QL. It includes a _solaris.go file that produces
// compile time errors on < go1.3.
// compile time errors on < go1.3.
...
@@ -45,7 +46,7 @@ import (
...
@@ -45,7 +46,7 @@ import (
var
wrappers
=
[]
string
{
var
wrappers
=
[]
string
{
//`sqlite`,
//`sqlite`,
//
`mysql`,
`mysql`
,
`postgresql`
,
`postgresql`
,
//`mongo`,
//`mongo`,
// `ql`,
// `ql`,
...
@@ -87,11 +88,14 @@ func init() {
...
@@ -87,11 +88,14 @@ func init() {
User
:
`upperio`
,
User
:
`upperio`
,
Password
:
`upperio`
,
Password
:
`upperio`
,
},
},
`mysql`
:
&
db
.
Settings
{
`mysql`
:
&
mysql
.
ConnectionURL
{
Database
:
`upperio_tests`
,
Database
:
`upperio_tests`
,
Host
:
host
,
Address
:
db
.
Host
(
host
)
,
User
:
`upperio`
,
User
:
`upperio`
,
Password
:
`upperio`
,
Password
:
`upperio`
,
Options
:
map
[
string
]
string
{
"parseTime"
:
"true"
,
},
},
},
`postgresql`
:
&
postgresql
.
ConnectionURL
{
`postgresql`
:
&
postgresql
.
ConnectionURL
{
Database
:
`upperio_tests`
,
Database
:
`upperio_tests`
,
...
@@ -240,8 +244,8 @@ var setupFn = map[string]func(driver interface{}) error{
...
@@ -240,8 +244,8 @@ var setupFn = map[string]func(driver interface{}) error{
return
err
return
err
}
}
_
,
err
=
sqld
.
Exec
(
`CREATE TABLE CaSe_TesT (
_
,
err
=
sqld
.
Exec
(
`CREATE TABLE CaSe_TesT (
ID
BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, PRIMARY KEY(
ID
),
id
BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, PRIMARY KEY(
id
),
C
ase_
T
est VARCHAR(60)
c
ase_
t
est VARCHAR(60)
) CHARSET=utf8`
)
) CHARSET=utf8`
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
...
This diff is collapsed.
Click to expand it.
mysql/database.go
+
2
−
0
View file @
0eccd828
...
@@ -149,6 +149,8 @@ func (s *source) Open() error {
...
@@ -149,6 +149,8 @@ func (s *source) Open() error {
return
err
return
err
}
}
s
.
session
.
Mapper
=
sqlutil
.
NewMapper
()
if
err
=
s
.
populateSchema
();
err
!=
nil
{
if
err
=
s
.
populateSchema
();
err
!=
nil
{
return
err
return
err
}
}
...
...
This diff is collapsed.
Click to expand it.
mysql/database_test.go
+
12
−
10
View file @
0eccd828
...
@@ -24,7 +24,6 @@ package mysql
...
@@ -24,7 +24,6 @@ package mysql
import
(
import
(
"database/sql"
"database/sql"
"errors"
"errors"
"flag"
"fmt"
"fmt"
"math/rand"
"math/rand"
"os"
"os"
...
@@ -62,7 +61,7 @@ var settings = ConnectionURL{
...
@@ -62,7 +61,7 @@ var settings = ConnectionURL{
},
},
}
}
var
host
=
flag
.
String
(
"host"
,
"testserver.local"
,
"Testing server address."
)
var
host
string
// Structure for testing conversions and datatypes.
// Structure for testing conversions and datatypes.
type
testValuesStruct
struct
{
type
testValuesStruct
struct
{
...
@@ -87,7 +86,7 @@ type testValuesStruct struct {
...
@@ -87,7 +86,7 @@ type testValuesStruct struct {
Date
time
.
Time
`db:"_date"`
Date
time
.
Time
`db:"_date"`
DateN
*
time
.
Time
`db:"_nildate"`
DateN
*
time
.
Time
`db:"_nildate"`
DateP
*
time
.
Time
`db:"_ptrdate"`
DateP
*
time
.
Time
`db:"_ptrdate"`
DateD
*
time
.
Time
`db:"_defaultdate"`
DateD
*
time
.
Time
`db:"_defaultdate
,omitempty
"`
Time
int64
`db:"_time"`
Time
int64
`db:"_time"`
}
}
...
@@ -149,8 +148,11 @@ func init() {
...
@@ -149,8 +148,11 @@ func init() {
int64
(
time
.
Second
*
7331
),
int64
(
time
.
Second
*
7331
),
}
}
flag
.
Parse
()
if
host
=
os
.
Getenv
(
"TEST_HOST"
);
host
==
""
{
settings
.
Address
=
db
.
ParseAddress
(
*
host
)
host
=
"localhost"
}
settings
.
Address
=
db
.
ParseAddress
(
host
)
}
}
// Loggin some information to stdout (like the SQL query and its
// Loggin some information to stdout (like the SQL query and its
...
@@ -178,7 +180,7 @@ func TestOpenWithWrongData(t *testing.T) {
...
@@ -178,7 +180,7 @@ func TestOpenWithWrongData(t *testing.T) {
// Attempt to open with safe settings.
// Attempt to open with safe settings.
rightSettings
=
db
.
Settings
{
rightSettings
=
db
.
Settings
{
Database
:
database
,
Database
:
database
,
Host
:
*
host
,
Host
:
host
,
User
:
username
,
User
:
username
,
Password
:
password
,
Password
:
password
,
}
}
...
@@ -192,7 +194,7 @@ func TestOpenWithWrongData(t *testing.T) {
...
@@ -192,7 +194,7 @@ func TestOpenWithWrongData(t *testing.T) {
// Attempt to open with wrong password.
// Attempt to open with wrong password.
wrongSettings
=
db
.
Settings
{
wrongSettings
=
db
.
Settings
{
Database
:
database
,
Database
:
database
,
Host
:
*
host
,
Host
:
host
,
User
:
username
,
User
:
username
,
Password
:
"fail"
,
Password
:
"fail"
,
}
}
...
@@ -204,7 +206,7 @@ func TestOpenWithWrongData(t *testing.T) {
...
@@ -204,7 +206,7 @@ func TestOpenWithWrongData(t *testing.T) {
// Attempt to open with wrong database.
// Attempt to open with wrong database.
wrongSettings
=
db
.
Settings
{
wrongSettings
=
db
.
Settings
{
Database
:
"fail"
,
Database
:
"fail"
,
Host
:
*
host
,
Host
:
host
,
User
:
username
,
User
:
username
,
Password
:
password
,
Password
:
password
,
}
}
...
@@ -216,7 +218,7 @@ func TestOpenWithWrongData(t *testing.T) {
...
@@ -216,7 +218,7 @@ func TestOpenWithWrongData(t *testing.T) {
// Attempt to open with wrong username.
// Attempt to open with wrong username.
wrongSettings
=
db
.
Settings
{
wrongSettings
=
db
.
Settings
{
Database
:
database
,
Database
:
database
,
Host
:
*
host
,
Host
:
host
,
User
:
"fail"
,
User
:
"fail"
,
Password
:
password
,
Password
:
password
,
}
}
...
@@ -235,7 +237,7 @@ func TestOldSettings(t *testing.T) {
...
@@ -235,7 +237,7 @@ func TestOldSettings(t *testing.T) {
Database
:
database
,
Database
:
database
,
User
:
username
,
User
:
username
,
Password
:
password
,
Password
:
password
,
Host
:
*
host
,
Host
:
host
,
}
}
// Opening database.
// Opening database.
...
...
This diff is collapsed.
Click to expand it.
mysql/result.go
+
17
−
18
View file @
0eccd828
...
@@ -92,6 +92,7 @@ func (r *result) Group(fields ...interface{}) db.Result {
...
@@ -92,6 +92,7 @@ func (r *result) Group(fields ...interface{}) db.Result {
groupByColumns
:=
make
(
sqlgen
.
GroupBy
,
0
,
len
(
fields
))
groupByColumns
:=
make
(
sqlgen
.
GroupBy
,
0
,
len
(
fields
))
l
:=
len
(
fields
)
l
:=
len
(
fields
)
for
i
:=
0
;
i
<
l
;
i
++
{
for
i
:=
0
;
i
<
l
;
i
++
{
switch
value
:=
fields
[
i
]
.
(
type
)
{
switch
value
:=
fields
[
i
]
.
(
type
)
{
// Maybe other types?
// Maybe other types?
...
@@ -217,35 +218,31 @@ func (r *result) One(dst interface{}) error {
...
@@ -217,35 +218,31 @@ func (r *result) One(dst interface{}) error {
}
}
// Fetches the next result from the resultset.
// Fetches the next result from the resultset.
func
(
r
*
result
)
Next
(
dst
interface
{})
error
{
func
(
r
*
result
)
Next
(
dst
interface
{})
(
err
error
)
{
var
err
error
// Current cursor.
err
=
r
.
setCursor
()
if
err
!=
nil
{
if
err
=
r
.
setCursor
();
err
!=
nil
{
r
.
Close
()
r
.
Close
()
return
err
}
}
// Fetching the next result from the cursor.
if
err
=
sqlutil
.
FetchRow
(
r
.
cursor
,
dst
);
err
!=
nil
{
err
=
sqlutil
.
FetchRow
(
r
.
cursor
,
dst
)
if
err
!=
nil
{
r
.
Close
()
r
.
Close
()
return
err
}
}
return
err
return
nil
}
}
// Removes the matching items from the collection.
// Removes the matching items from the collection.
func
(
r
*
result
)
Remove
()
error
{
func
(
r
*
result
)
Remove
()
error
{
var
err
error
var
err
error
_
,
err
=
r
.
table
.
source
.
doExec
(
sqlgen
.
Statement
{
_
,
err
=
r
.
table
.
source
.
doExec
(
sqlgen
.
Statement
{
Type
:
sqlgen
.
SqlDelete
,
Type
:
sqlgen
.
SqlDelete
,
Table
:
sqlgen
.
Table
{
r
.
table
.
Name
()},
Table
:
sqlgen
.
Table
{
r
.
table
.
Name
()},
Where
:
r
.
where
,
Where
:
r
.
where
,
},
r
.
arguments
...
)
},
r
.
arguments
...
)
return
err
return
err
}
}
...
@@ -255,6 +252,9 @@ func (r *result) Remove() error {
...
@@ -255,6 +252,9 @@ func (r *result) Remove() error {
func
(
r
*
result
)
Update
(
values
interface
{})
error
{
func
(
r
*
result
)
Update
(
values
interface
{})
error
{
ff
,
vv
,
err
:=
r
.
table
.
FieldValues
(
values
)
ff
,
vv
,
err
:=
r
.
table
.
FieldValues
(
values
)
if
err
!=
nil
{
return
err
}
total
:=
len
(
ff
)
total
:=
len
(
ff
)
...
@@ -277,8 +277,7 @@ func (r *result) Update(values interface{}) error {
...
@@ -277,8 +277,7 @@ func (r *result) Update(values interface{}) error {
}
}
// Closes the result set.
// Closes the result set.
func
(
r
*
result
)
Close
()
error
{
func
(
r
*
result
)
Close
()
(
err
error
)
{
var
err
error
if
r
.
cursor
!=
nil
{
if
r
.
cursor
!=
nil
{
err
=
r
.
cursor
.
Close
()
err
=
r
.
cursor
.
Close
()
r
.
cursor
=
nil
r
.
cursor
=
nil
...
@@ -286,11 +285,11 @@ func (r *result) Close() error {
...
@@ -286,11 +285,11 @@ func (r *result) Close() error {
return
err
return
err
}
}
// Counts
matching elements
.
// Counts
the elements within the main conditions of the set
.
func
(
r
*
result
)
Count
()
(
uint64
,
error
)
{
func
(
r
*
result
)
Count
()
(
uint64
,
error
)
{
var
count
counter
var
count
counter
row
s
,
err
:=
r
.
table
.
source
.
doQuery
(
sqlgen
.
Statement
{
row
,
err
:=
r
.
table
.
source
.
doQuery
Row
(
sqlgen
.
Statement
{
Type
:
sqlgen
.
SqlSelectCount
,
Type
:
sqlgen
.
SqlSelectCount
,
Table
:
sqlgen
.
Table
{
r
.
table
.
Name
()},
Table
:
sqlgen
.
Table
{
r
.
table
.
Name
()},
Where
:
r
.
where
,
Where
:
r
.
where
,
...
@@ -300,8 +299,8 @@ func (r *result) Count() (uint64, error) {
...
@@ -300,8 +299,8 @@ func (r *result) Count() (uint64, error) {
return
0
,
err
return
0
,
err
}
}
defer
rows
.
Close
(
)
err
=
row
.
Scan
(
&
count
.
Total
)
if
err
=
sqlutil
.
FetchRow
(
rows
,
&
count
);
err
!=
nil
{
if
err
!=
nil
{
return
0
,
err
return
0
,
err
}
}
...
...
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