Browse Source

If the prepared statement does not exist on server, re-prepare it

Nimi Wariboko 12 years ago
parent
commit
31578cb546
1 changed files with 12 additions and 0 deletions
  1. 12 0
      conn.go

+ 12 - 0
conn.go

@@ -322,6 +322,18 @@ func (c *Conn) executeQuery(qry *Query) *Iter {
 	case resultKeyspaceFrame:
 		c.cluster.HandleKeyspace(c, x.Keyspace)
 		return &Iter{}
+	case errorFrame:
+		if x.Code == errUnprepared {
+			c.prepMu.Lock()
+			defer c.prepMu.Unlock()
+			if val, ok := c.prep[qry.stmt]; ok && val != nil {
+				delete(c.prep, qry.stmt)
+				return c.executeQuery(qry)
+			}
+			return &Iter{err: x}
+		} else {
+			return &Iter{err: x}
+		}
 	case error:
 		return &Iter{err: x}
 	default: