func (s *fakeStmt) execInsert(args []interface{}) (driver.Result, error) { db := s.c.db if len(args) != s.placeholders { panic("error in pkg db; should only get here if size is correct") } db.mu.Lock() t, ok := db.table(s.table) db.mu.Unlock() if !ok { return nil, fmt.Errorf("fakedb: table %q doesn't exist", s.table) } t.mu.Lock() defer t.mu.Unlock() cols := make([]interface{}, len(t.colname)) argPos := 0 for n, colname := range s.colName { colidx := t.columnIndex(colname) if colidx == -1 { return nil, fmt.Errorf("fakedb: column %q doesn't exist or dropped since prepared statement was created", colname) } var val interface{} if strvalue, ok := s.colValue[n].(string); ok && strvalue == "?" { val = args[argPos] argPos++ } else { val = s.colValue[n] } cols[colidx] = val } t.rows = append(t.rows, &row{cols: cols}) return driver.RowsAffected(1), nil }
func (cn *Conn) Exec(query string, args []interface{}) (driver.Result, os.Error) { if len(args) == 0 { err := cn.p.SimpleQuery(query) if err != nil { return nil, err } var serr os.Error for { m, err := cn.p.Next() if err != nil { return nil, err } switch m.Type { case 'E': serr = m.Err case 'Z': return driver.RowsAffected(0), serr } } } else { stmt, err := cn.Prepare(query) if err != nil { return nil, err } return stmt.Exec(args) } panic("not reached") }
func (stmt *Stmt) Exec(args []interface{}) (driver.Result, os.Error) { // NOTE: should return []drive.Result, because a PS can have more // than one statement and recv more than one tag. rows, err := stmt.Query(args) if err != nil { return nil, err } for rows.Next(nil) != os.EOF { } // TODO: use the tag given by CommandComplete return driver.RowsAffected(0), nil }