HandleQuery handle COM_QUERY comamnd, like SELECT, INSERT, UPDATE, etc... if Result has a Resultset (SELECT, SHOW, etc...), we will send this as the response, otherwise, we will send Result.
(query string)
| 293 | // HandleQuery handle COM_QUERY comamnd, like SELECT, INSERT, UPDATE, etc... |
| 294 | // if Result has a Resultset (SELECT, SHOW, etc...), we will send this as the response, otherwise, we will send Result. |
| 295 | func (c *Cursor) HandleQuery(query string) (r *my.Result, err error) { |
| 296 | var processed bool |
| 297 | |
| 298 | log.WithField("query", query).Info("received query") |
| 299 | |
| 300 | if r, processed, err = c.handleSpecialQuery(query); processed { |
| 301 | return |
| 302 | } |
| 303 | |
| 304 | var conn *sql.DB |
| 305 | |
| 306 | if conn, err = c.ensureDatabase(); err != nil { |
| 307 | return |
| 308 | } |
| 309 | |
| 310 | // as normal query |
| 311 | if readQuery.MatchString(query) { |
| 312 | var rows *sql.Rows |
| 313 | if rows, err = conn.Query(query); err != nil { |
| 314 | err = my.NewError(my.ER_UNKNOWN_ERROR, err.Error()) |
| 315 | return |
| 316 | } |
| 317 | |
| 318 | // build result set |
| 319 | return c.buildResultSet(rows) |
| 320 | } |
| 321 | |
| 322 | var result sql.Result |
| 323 | if result, err = conn.Exec(query); err != nil { |
| 324 | err = my.NewError(my.ER_UNKNOWN_ERROR, err.Error()) |
| 325 | return |
| 326 | } |
| 327 | |
| 328 | lastInsertID, _ := result.LastInsertId() |
| 329 | affectedRows, _ := result.RowsAffected() |
| 330 | |
| 331 | r = &my.Result{ |
| 332 | Status: 0, |
| 333 | InsertId: uint64(lastInsertID), |
| 334 | AffectedRows: uint64(affectedRows), |
| 335 | Resultset: nil, |
| 336 | } |
| 337 | |
| 338 | return |
| 339 | } |
| 340 | |
| 341 | // HandleFieldList handle COM_FILED_LIST command. |
| 342 | func (c *Cursor) HandleFieldList(table string, fieldWildcard string) (fields []*my.Field, err error) { |
nothing calls this directly
no test coverage detected