Skip to content

Commit ae4dab8

Browse files
committed
update README.md
1 parent 699f269 commit ae4dab8

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

README.md

+18-2
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,29 @@ r, _ := conn.Execute(`insert into table (id, name) values (1, "abc")`)
166166

167167
// Get last insert id
168168
println(r.InsertId)
169+
// Or affected rows count
170+
println(r.AffectedRows)
169171

170172
// Select
171-
r, _ := conn.Execute(`select id, name from table where id = 1`)
173+
r, err := conn.Execute(`select id, name from table where id = 1`)
174+
175+
// Close result for reuse memory (it's not necessary but very useful)
176+
defer r.Close()
172177

173178
// Handle resultset
174179
v, _ := r.GetInt(0, 0)
175-
v, _ = r.GetIntByName(0, "id")
180+
v, _ = r.GetIntByName(0, "id")
181+
182+
// Direct access to fields
183+
for _, row := range r.Values {
184+
for _, val := range row {
185+
_ = val.Value() // interface{}
186+
// or
187+
if val.Type == mysql.FieldValueTypeFloat {
188+
_ = val.AsFloat64() // float64
189+
}
190+
}
191+
}
176192
```
177193

178194
Tested MySQL versions for the client include:

0 commit comments

Comments
 (0)