Browse Source

Allow all normal errors to be returned, except EOF.

Fixes #25
Matt Robenolt 12 years ago
parent
commit
46b10a201d
2 changed files with 14 additions and 2 deletions
  1. 2 2
      gocql.go
  2. 12 0
      gocql_test.go

+ 2 - 2
gocql.go

@@ -405,7 +405,7 @@ func (p *pool) Prepare(query string) (driver.Stmt, error) {
 			return nil, err
 		}
 		st, err := cn.Prepare(query)
-		if err != nil {
+		if err == io.EOF {
 			// the cn has gotten marked as dead already
 			if p.dead {
 				// The entire pool is dead, so we bubble up the ErrBadConn
@@ -414,7 +414,7 @@ func (p *pool) Prepare(query string) (driver.Stmt, error) {
 				continue // Retry request on another cn
 			}
 		}
-		return st, nil
+		return st, err
 	}
 }
 

+ 12 - 0
gocql_test.go

@@ -223,3 +223,15 @@ func TestNullColumnValues(t *testing.T) {
 		t.Fatal(err)
 	}
 }
+
+func TestBadQuery(t *testing.T) {
+	db, err := sql.Open("gocql", "localhost:9042 keyspace=system")
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	_, err = db.Query("SELECT keyspace_name FROM not_existant")
+	if err == nil {
+		t.Fatal("Should have returned an error")
+	}
+}