MCPcopy
hub / github.com/go-sql-driver/mysql / Prepare

Method Prepare

connection.go:207–246  ·  view source on GitHub ↗
(query string)

Source from the content-addressed store, hash-verified

205}
206
207func (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
248func (mc *mysqlConn) interpolateParams(query string, args []driver.Value) (string, error) {
249 noBackslashEscapes := (mc.status & statusNoBackslashEscapes) != 0

Callers 13

PrepareContextMethod · 0.95
TestNULLFunction · 0.80
TestUint64Function · 0.80
TestCloseStmtBeforeRowsFunction · 0.80
TestStmtMultiRowsFunction · 0.80
TestPreparedManyColsFunction · 0.80
TestMultiResultSetFunction · 0.80
benchmarkQueryFunction · 0.80
BenchmarkExecFunction · 0.80
BenchmarkRoundtripBinFunction · 0.80
benchmark10kRowsFunction · 0.80

Calls 5

writeCommandPacketStrMethod · 0.95
logMethod · 0.95
skipColumnsMethod · 0.95
readColumnsMethod · 0.95

Tested by 12

TestNULLFunction · 0.64
TestUint64Function · 0.64
TestCloseStmtBeforeRowsFunction · 0.64
TestStmtMultiRowsFunction · 0.64
TestPreparedManyColsFunction · 0.64
TestMultiResultSetFunction · 0.64
benchmarkQueryFunction · 0.64
BenchmarkExecFunction · 0.64
BenchmarkRoundtripBinFunction · 0.64
benchmark10kRowsFunction · 0.64
BenchmarkReceiveMetadataFunction · 0.64