Permalink
Browse files

Execute() returns ResultSet instead of channel.

  • Loading branch information...
1 parent ea6be8b commit 2379f7757972eda4f2456f2baedc6b287ce1d6cf @phf committed Dec 12, 2009
Showing with 17 additions and 14 deletions.
  1. +11 −11 core.go
  2. +6 −3 example.go
View
22 core.go
@@ -430,17 +430,15 @@ func iterate(rset db.ClassicResultSet, channel chan<- db.Result) {
close(channel);
}
-func (self *Connection) Execute(statement db.Statement, parameters ...) (channel <-chan db.Result, error os.Error) {
- ch := make(chan db.Result);
-
- cur, error := self.ExecuteClassic(statement, parameters);
+func (self *Connection) Execute(statement db.Statement, parameters ...) (rs db.ResultSet, error os.Error) {
+ var crs db.ClassicResultSet;
+ crs, error = self.ExecuteClassic(statement, parameters);
if error != nil {
return
}
-
- go iterate(cur, ch);
-
- channel = ch;
+ mrs := new(ResultSet);
+ mrs.init(crs);
+ rs = mrs;
return;
}
@@ -595,14 +593,14 @@ func (self *ClassicResultSet) Close() os.Error {
type ResultSet struct {
// we implement everything in terms of classic stuff
- classic *ClassicResultSet;
+ classic db.ClassicResultSet;
// channel to send results through
results chan db.Result;
// channel to check for termination
stops chan bool;
}
-func (self *ResultSet) init(crs *ClassicResultSet) {
+func (self *ResultSet) init(crs db.ClassicResultSet) {
self.classic = crs;
self.results = make(chan db.Result);
self.stops = make(chan bool);
@@ -640,7 +638,9 @@ func (self *ResultSet) Iter() <-chan db.Result {
}
func (self *ResultSet) Close() os.Error {
- self.stops <- true;
+ if self.stops != nil {
+ self.stops <- true;
+ }
return nil;
}
View
@@ -91,18 +91,21 @@ func main() {
}
fmt.Printf("About to re-execute query\n");
- ch, e := c.Execute(s, "somepassword");
+ rs, e := c.Execute(s, "somepassword");
if e != nil {
fmt.Printf("error: %s\n", e.String())
}
- fmt.Printf("channel: %s\n", ch);
+ fmt.Printf("resultset: %s\n", rs);
fmt.Printf("About to fetch all using for range\n");
- for r := range ch {
+ for r := range rs.Iter() {
fmt.Printf("data: %s\n", r.Data());
fmt.Printf("error: %s\n", r.Error());
}
+ fmt.Printf("About to close resultset\n");
+ rs.Close();
+
fmt.Printf("About to close statement\n");
e = s.Close();
if e != nil {

0 comments on commit 2379f77

Please sign in to comment.