@@ -210,16 +210,6 @@ func (conn *Connection) Execute(expr string, args interface{}) (resp *Response,
210
210
return conn .ExecuteAsync (expr , args ).Get ()
211
211
}
212
212
213
- // Prepare sends a sql statement to prepare.
214
- //
215
- // It is equal to conn.PrepareAsync(expr).Get().
216
- // Since 1.7.0
217
- func (conn * Connection ) Prepare (expr string ) (stmt * PreparedStatement , err error ) {
218
- stmt = conn .PrepareAsync (expr )
219
- err = stmt .wait ()
220
- return stmt , err
221
- }
222
-
223
213
// single used for conn.GetTyped for decode one tuple.
224
214
type single struct {
225
215
res interface {}
@@ -419,16 +409,6 @@ func (conn *Connection) ExecuteAsync(expr string, args interface{}) *Future {
419
409
return conn .DoAsync (req )
420
410
}
421
411
422
- // PrepareAsync sends a sql statement to prepare and returns PreparedStatement object.
423
- //
424
- // Since 1.7.0
425
- func (conn * Connection ) PrepareAsync (expr string ) * PreparedStatement {
426
- req := newPrepareRequest (expr )
427
- fut := conn .DoAsync (req )
428
- stmt := newPreparedStatement (fut , conn )
429
- return stmt
430
- }
431
-
432
412
type PreparedStatementID uint64
433
413
434
414
// PreparedStatement is a type for handling prepared statements
@@ -439,56 +419,15 @@ type PreparedStatement struct {
439
419
MetaData []ColumnMetaData
440
420
ParamCount uint64
441
421
conn * Connection
442
- fut * Future
443
422
}
444
423
445
- func newPreparedStatement ( fut * Future , conn * Connection ) * PreparedStatement {
424
+ func NewPreparedStatement ( conn * Connection , resp * Response ) * PreparedStatement {
446
425
stmt := new (PreparedStatement )
447
- stmt .fut = fut
448
426
stmt .conn = conn
449
- return stmt
450
- }
451
-
452
- // wait until the prepared statement is ready and fill the statement object
453
- func (stmt * PreparedStatement ) wait () error {
454
- resp , err := stmt .fut .Get ()
455
- stmt .StatementID = PreparedStatementID (resp .StmtID )
456
- stmt .MetaData = resp .MetaData
457
427
stmt .ParamCount = resp .BindCount
458
- return err
459
- }
460
-
461
- // UnprepareAsync sends an undo request and returns Future
462
- func (stmt * PreparedStatement ) UnprepareAsync () * Future {
463
- err := stmt .wait ()
464
- if err != nil {
465
- return NewErrorFuture (err )
466
- }
467
- req := newUnprepareRequest (* stmt )
468
- fut := stmt .conn .DoAsync (req )
469
- return fut
470
- }
471
-
472
- // Unprepare undo the prepared statement
473
- func (stmt * PreparedStatement ) Unprepare () (resp * Response , err error ) {
474
- return stmt .UnprepareAsync ().Get ()
475
- }
476
-
477
- // ExecuteAsync sends the prepared SQL statement for execution and returns Future
478
- func (stmt * PreparedStatement ) ExecuteAsync (args interface {}) * Future {
479
- err := stmt .wait ()
480
- if err != nil {
481
- return NewErrorFuture (err )
482
- }
483
- req := newPreparedExecuteRequest (* stmt )
484
- req .Args (args )
485
- fut := stmt .conn .DoAsync (req )
486
- return fut
487
- }
488
-
489
- // Execute sends the prepared SQL statement for execution
490
- func (stmt * PreparedStatement ) Execute (args interface {}) (resp * Response , err error ) {
491
- return stmt .ExecuteAsync (args ).Get ()
428
+ stmt .MetaData = resp .MetaData
429
+ stmt .StatementID = PreparedStatementID (resp .StmtID )
430
+ return stmt
492
431
}
493
432
494
433
// KeyValueBind is a type for encoding named SQL parameters
@@ -1084,62 +1023,62 @@ func (req *ExecuteRequest) Body(res SchemaResolver, enc *msgpack.Encoder) error
1084
1023
return fillExecute (enc , req .expr , req .args )
1085
1024
}
1086
1025
1087
- type prepareRequest struct {
1026
+ type PrepareRequest struct {
1088
1027
baseRequest
1089
1028
expr string
1090
1029
}
1091
1030
1092
- // newPrepareRequest returns a new empty prepareRequest .
1093
- func newPrepareRequest (expr string ) * prepareRequest {
1094
- req := new (prepareRequest )
1031
+ // NewPrepareRequest returns a new empty PrepareRequest .
1032
+ func NewPrepareRequest (expr string ) * PrepareRequest {
1033
+ req := new (PrepareRequest )
1095
1034
req .requestCode = PrepareRequestCode
1096
1035
req .expr = expr
1097
1036
return req
1098
1037
}
1099
1038
1100
1039
// Body fills an encoder with the execute request body.
1101
- func (req * prepareRequest ) Body (res SchemaResolver , enc * msgpack.Encoder ) error {
1040
+ func (req * PrepareRequest ) Body (res SchemaResolver , enc * msgpack.Encoder ) error {
1102
1041
return fillPrepare (enc , req .expr )
1103
1042
}
1104
1043
1105
- type unprepareRequest struct {
1044
+ type UnprepareRequest struct {
1106
1045
baseRequest
1107
- stmt PreparedStatement
1046
+ stmt * PreparedStatement
1108
1047
}
1109
1048
1110
- // newUnprepareRequest returns a new empty unprepareRequest .
1111
- func newUnprepareRequest (stmt PreparedStatement ) * unprepareRequest {
1112
- req := new (unprepareRequest )
1049
+ // NewUnprepareRequest returns a new empty UnprepareRequest .
1050
+ func NewUnprepareRequest (stmt * PreparedStatement ) * UnprepareRequest {
1051
+ req := new (UnprepareRequest )
1113
1052
req .requestCode = PrepareRequestCode
1114
1053
req .stmt = stmt
1115
1054
return req
1116
1055
}
1117
1056
1118
1057
// Body fills an encoder with the execute request body.
1119
- func (req * unprepareRequest ) Body (res SchemaResolver , enc * msgpack.Encoder ) error {
1120
- return fillUnprepare (enc , req .stmt )
1058
+ func (req * UnprepareRequest ) Body (res SchemaResolver , enc * msgpack.Encoder ) error {
1059
+ return fillUnprepare (enc , * req .stmt )
1121
1060
}
1122
1061
1123
- type preparedExecuteRequest struct {
1062
+ type PreparedExecuteRequest struct {
1124
1063
baseRequest
1125
- stmt PreparedStatement
1064
+ stmt * PreparedStatement
1126
1065
args interface {}
1127
1066
}
1128
1067
1129
- // newPreparedExecuteRequest returns a new empty preparedExecuteRequest.
1130
- func newPreparedExecuteRequest (stmt PreparedStatement ) * preparedExecuteRequest {
1131
- req := new (preparedExecuteRequest )
1068
+ // NewPreparedExecuteRequest returns a new empty preparedExecuteRequest.
1069
+ func NewPreparedExecuteRequest (stmt * PreparedStatement ) * PreparedExecuteRequest {
1070
+ req := new (PreparedExecuteRequest )
1132
1071
req .requestCode = ExecuteRequestCode
1133
1072
req .stmt = stmt
1134
1073
return req
1135
1074
}
1136
1075
1137
- func (req * preparedExecuteRequest ) Args (args interface {}) * preparedExecuteRequest {
1076
+ func (req * PreparedExecuteRequest ) Args (args interface {}) * PreparedExecuteRequest {
1138
1077
req .args = args
1139
1078
return req
1140
1079
}
1141
1080
1142
1081
// Body fills an encoder with the execute request body.
1143
- func (req * preparedExecuteRequest ) Body (res SchemaResolver , enc * msgpack.Encoder ) error {
1144
- return fillPreparedExecute (enc , req .stmt , req .args )
1082
+ func (req * PreparedExecuteRequest ) Body (res SchemaResolver , enc * msgpack.Encoder ) error {
1083
+ return fillPreparedExecute (enc , * req .stmt , req .args )
1145
1084
}
0 commit comments