| 205 | } |
| 206 | |
| 207 | func (mc *mysqlConn) Prepare(query string) (driver.Stmt, error) { |
| 208 | if mc.closed.Load() { |
| 209 | return nil, driver.ErrBadConn |
| 210 | } |
| 211 | // Send command |
| 212 | err := mc.writeCommandPacketStr(comStmtPrepare, query) |
| 213 | if err != nil { |
| 214 | // STMT_PREPARE is safe to retry. So we can return ErrBadConn here. |
| 215 | mc.log(err) |
| 216 | return nil, driver.ErrBadConn |
| 217 | } |
| 218 | |
| 219 | stmt := &mysqlStmt{ |
| 220 | mc: mc, |
| 221 | } |
| 222 | |
| 223 | // Read Result |
| 224 | columnCount, err := stmt.readPrepareResultPacket() |
| 225 | if err == nil { |
| 226 | if stmt.paramCount > 0 { |
| 227 | if err = mc.skipColumns(stmt.paramCount); err != nil { |
| 228 | return nil, err |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | if columnCount > 0 { |
| 233 | if mc.extCapabilities&clientCacheMetadata != 0 { |
| 234 | if stmt.columns, err = mc.readColumns(int(columnCount), nil); err != nil { |
| 235 | return nil, err |
| 236 | } |
| 237 | } else { |
| 238 | if err = mc.skipColumns(int(columnCount)); err != nil { |
| 239 | return nil, err |
| 240 | } |
| 241 | } |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | return stmt, err |
| 246 | } |
| 247 | |
| 248 | func (mc *mysqlConn) interpolateParams(query string, args []driver.Value) (string, error) { |
| 249 | noBackslashEscapes := (mc.status & statusNoBackslashEscapes) != 0 |