good morning!!!!

Skip to content
Snippets Groups Projects
Commit 0eccd828 authored by José Carlos Nieto's avatar José Carlos Nieto
Browse files

Updating main test for MySQL.

parent 79896025
No related branches found
No related tags found
No related merge requests found
...@@ -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),
Case_Test VARCHAR(60) case_test VARCHAR(60)
) CHARSET=utf8`) ) CHARSET=utf8`)
if err != nil { if err != nil {
return err return err
......
...@@ -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
} }
......
...@@ -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.
......
...@@ -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
rows, err := r.table.source.doQuery(sqlgen.Statement{ row, err := r.table.source.doQueryRow(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
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment