@@ -198,16 +198,34 @@ func ExampleSelectRequest() {
198
198
}
199
199
200
200
key := []interface {}{uint (1111 )}
201
- data , err := conn .Do (tarantool .NewSelectRequest (617 ).
201
+ resp , err := conn .Do (tarantool .NewSelectRequest (617 ).
202
202
Limit (100 ).
203
203
Iterator (tarantool .IterEq ).
204
204
Key (key ),
205
- ).Get ()
205
+ ).GetResponse ()
206
206
207
207
if err != nil {
208
208
fmt .Printf ("error in select is %v" , err )
209
209
return
210
210
}
211
+ selResp , ok := resp .(* tarantool.SelectResponse )
212
+ if ! ok {
213
+ fmt .Print ("wrong response type" )
214
+ return
215
+ }
216
+
217
+ pos , err := selResp .Pos ()
218
+ if err != nil {
219
+ fmt .Printf ("error in Pos: %v" , err )
220
+ return
221
+ }
222
+ fmt .Printf ("pos for Select is %v\n " , pos )
223
+
224
+ data , err := resp .Decode ()
225
+ if err != nil {
226
+ fmt .Printf ("error while decoding: %v" , err )
227
+ return
228
+ }
211
229
fmt .Printf ("response is %#v\n " , data )
212
230
213
231
var res []Tuple
@@ -224,6 +242,7 @@ func ExampleSelectRequest() {
224
242
fmt .Printf ("response is %v\n " , res )
225
243
226
244
// Output:
245
+ // pos for Select is []
227
246
// response is []interface {}{[]interface {}{0x457, "hello", "world"}}
228
247
// response is [{{} 1111 hello world}]
229
248
}
@@ -567,17 +586,21 @@ func ExampleExecuteRequest() {
567
586
resp , err := conn .Do (req ).GetResponse ()
568
587
fmt .Println ("Execute" )
569
588
fmt .Println ("Error" , err )
589
+
570
590
data , err := resp .Decode ()
571
591
fmt .Println ("Error" , err )
572
592
fmt .Println ("Data" , data )
593
+
573
594
exResp , ok := resp .(* tarantool.ExecuteResponse )
574
595
if ! ok {
575
596
fmt .Printf ("wrong response type" )
576
597
return
577
598
}
599
+
578
600
metaData , err := exResp .MetaData ()
579
601
fmt .Println ("MetaData" , metaData )
580
602
fmt .Println ("Error" , err )
603
+
581
604
sqlInfo , err := exResp .SQLInfo ()
582
605
fmt .Println ("SQL Info" , sqlInfo )
583
606
fmt .Println ("Error" , err )
@@ -992,6 +1015,26 @@ func ExampleBeginRequest_TxnIsolation() {
992
1015
fmt .Printf ("Select after Rollback: response is %#v\n " , data )
993
1016
}
994
1017
1018
+ func ExampleErrorNo () {
1019
+ conn := exampleConnect (dialer , opts )
1020
+ defer conn .Close ()
1021
+
1022
+ req := tarantool .NewPingRequest ()
1023
+ resp , err := conn .Do (req ).GetResponse ()
1024
+ if err != nil {
1025
+ fmt .Printf ("error getting the response: %s\n " , err )
1026
+ return
1027
+ }
1028
+
1029
+ if resp .Header ().Error != tarantool .ErrorNo {
1030
+ fmt .Printf ("response error code: %s\n " , resp .Header ().Error )
1031
+ } else {
1032
+ fmt .Println ("Success." )
1033
+ }
1034
+ // Output:
1035
+ // Success.
1036
+ }
1037
+
995
1038
func ExampleFuture_GetIterator () {
996
1039
conn := exampleConnect (dialer , opts )
997
1040
defer conn .Close ()
@@ -1008,11 +1051,11 @@ func ExampleFuture_GetIterator() {
1008
1051
if it .IsPush () {
1009
1052
// It is a push message.
1010
1053
fmt .Printf ("push message: %v\n " , data [0 ])
1011
- } else if resp .Header ().Code == tarantool .OkCode {
1054
+ } else if resp .Header ().Error == tarantool .ErrorNo {
1012
1055
// It is a regular response.
1013
1056
fmt .Printf ("response: %v" , data [0 ])
1014
1057
} else {
1015
- fmt .Printf ("an unexpected response code %d" , resp .Header ().Code )
1058
+ fmt .Printf ("an unexpected response code %d" , resp .Header ().Error )
1016
1059
}
1017
1060
}
1018
1061
if err := it .Err (); err != nil {
@@ -1224,6 +1267,11 @@ func ExampleConnection_Do_failure() {
1224
1267
if err != nil {
1225
1268
fmt .Printf ("Error in the future: %s\n " , err )
1226
1269
}
1270
+ // Optional step: check a response error.
1271
+ // It allows checking that response has or hasn't an error without decoding.
1272
+ if resp .Header ().Error != tarantool .ErrorNo {
1273
+ fmt .Printf ("Response error: %s\n " , resp .Header ().Error )
1274
+ }
1227
1275
1228
1276
data , err := future .Get ()
1229
1277
if err != nil {
@@ -1239,8 +1287,8 @@ func ExampleConnection_Do_failure() {
1239
1287
} else {
1240
1288
// Response exist. So it could be a Tarantool error or a decode
1241
1289
// error. We need to check the error code.
1242
- fmt .Printf ("Error code from the response: %d\n " , resp .Header ().Code )
1243
- if resp .Header ().Code == tarantool .OkCode {
1290
+ fmt .Printf ("Error code from the response: %d\n " , resp .Header ().Error )
1291
+ if resp .Header ().Error == tarantool .ErrorNo {
1244
1292
fmt .Printf ("Decode error: %s\n " , err )
1245
1293
} else {
1246
1294
code := err .(tarantool.Error ).Code
@@ -1251,6 +1299,7 @@ func ExampleConnection_Do_failure() {
1251
1299
}
1252
1300
1253
1301
// Output:
1302
+ // Response error: ER_NO_SUCH_PROC
1254
1303
// Data: []
1255
1304
// Error code from the response: 33
1256
1305
// Error code from the error: 33
0 commit comments