diff --git a/mysql/collection.go b/mysql/collection.go index b7f71a2a1025d0bbbfaf331722526930bbfa0e12..4db6cad74935501171a936e4fe83c43e2717e3b9 100644 --- a/mysql/collection.go +++ b/mysql/collection.go @@ -482,6 +482,7 @@ func (self *Table) Exists() bool { panic(err.Error()) } if result.Next() == true { + result.Close() return true } return false diff --git a/mysql/mysql_test.go b/mysql/mysql_test.go index 8ee1292c868334087b86354fc41147358078a325..dc07f1a6b3874d4decd9f672795459a49d8bcf9c 100644 --- a/mysql/mysql_test.go +++ b/mysql/mysql_test.go @@ -170,8 +170,6 @@ func TestUpdate(t *testing.T) { defer sess.Close() - sess.Use("test") - people, _ := sess.Collection("people") people.Update(db.Cond{"name": "José"}, db.Set{"name": "Joseph"}) @@ -219,13 +217,13 @@ func TestPopulate(t *testing.T) { for j := 0; j < 5; j++ { children.Append(db.Item{ "name": fmt.Sprintf("%s's child %d", person["name"], j+1), - "parent_id": person["_id"], + "parent_id": person["id"], }) } // Lives in people.Update( - db.Cond{"_id": person["_id"]}, + db.Cond{"id": person["id"]}, db.Set{"place_code_id": int(rand.Float32() * float32(len(results)))}, ) @@ -235,8 +233,8 @@ func TestPopulate(t *testing.T) { "code_id": int(rand.Float32() * float32(len(results))), }) visits.Append(db.Item{ - "place_id": place["_id"], - "person_id": person["_id"], + "place_id": place["id"], + "person_id": person["id"], }) } } diff --git a/sqlite/dumps/gotest.sqlite3.db b/sqlite/dumps/gotest.sqlite3.db index 6e2bb4eb2bba1cb1e9686b5af6cfd42363d7fe2d..eedf0c9eaf6f7be66c32c448ef85c6a3c1ba4ef2 100644 Binary files a/sqlite/dumps/gotest.sqlite3.db and b/sqlite/dumps/gotest.sqlite3.db differ diff --git a/sqlite/sqlite.go b/sqlite/sqlite.go index 50b2e69053391f294fc7d3f1a57824895c63c79d..c1442be9f4fa91836dd659e220d64cb52510aebb 100644 --- a/sqlite/sqlite.go +++ b/sqlite/sqlite.go @@ -209,10 +209,10 @@ type SqliteTable struct { } // Configures and returns a SQLite database session. -func (m *SqliteDataSource) Setup(config db.DataSource) error { - m.config = config - m.collections = make(map[string]db.Collection) - return m.Open() +func (self *SqliteDataSource) Setup(config db.DataSource) error { + self.config = config + self.collections = make(map[string]db.Collection) + return self.Open() } // Deprecated: Configures and returns a SQLite database session. @@ -236,9 +236,7 @@ func (sl *SqliteDataSource) Open() error { panic("Database name is required.") } - conn := sl.config.Database - - sl.session, err = sql.Open("sqlite3", conn) + sl.session, err = sql.Open("sqlite3", sl.config.Database) if err != nil { return fmt.Errorf("Could not connect to %s", sl.config.Host) @@ -249,7 +247,6 @@ func (sl *SqliteDataSource) Open() error { // Closes a previously opened SQLite database session. func (sl *SqliteDataSource) Close() error { - fmt.Printf("close: %v\n", sl.session) if sl.session != nil { return sl.session.Close() } @@ -758,6 +755,7 @@ func (self *SqliteTable) Exists() bool { panic(err.Error()) } if result.Next() == true { + result.Close() return true } return false diff --git a/sqlite/sqlite_test.go b/sqlite/sqlite_test.go index 408b129e183256486c296acee14b964b3df88db0..4eb8b83accffaebf566c842cb9439465f0b11e5d 100644 --- a/sqlite/sqlite_test.go +++ b/sqlite/sqlite_test.go @@ -54,7 +54,7 @@ func testItem() db.Item { } func TestEnableDebug(t *testing.T) { - // Debug = true + Debug = true } func TestTruncate(t *testing.T) { @@ -96,7 +96,7 @@ func TestAppend(t *testing.T) { if err == nil { t.Errorf("Collection should not exists.") - return + //return } people := sess.ExistentCollection("people") @@ -167,8 +167,6 @@ func TestUpdate(t *testing.T) { defer sess.Close() - sess.Use("test") - people, _ := sess.Collection("people") people.Update(db.Cond{"name": "José"}, db.Set{"name": "Joseph"}) @@ -216,13 +214,13 @@ func TestPopulate(t *testing.T) { for j := 0; j < 5; j++ { children.Append(db.Item{ "name": fmt.Sprintf("%s's child %d", person["name"], j+1), - "parent_id": person["_id"], + "parent_id": person["id"], }) } // Lives in people.Update( - db.Cond{"_id": person["_id"]}, + db.Cond{"id": person["id"]}, db.Set{"place_code_id": int(rand.Float32() * float32(len(results)))}, ) @@ -232,8 +230,8 @@ func TestPopulate(t *testing.T) { "code_id": int(rand.Float32() * float32(len(results))), }) visits.Append(db.Item{ - "place_id": place["_id"], - "person_id": person["_id"], + "place_id": place["id"], + "person_id": person["id"], }) } }