@@ -198,16 +198,34 @@ func ExampleSelectRequest() {
198198 }
199199
200200 key := []interface {}{uint (1111 )}
201- data , err := conn .Do (tarantool .NewSelectRequest (617 ).
201+ resp , err := conn .Do (tarantool .NewSelectRequest (617 ).
202202 Limit (100 ).
203203 Iterator (tarantool .IterEq ).
204204 Key (key ),
205- ).Get ()
205+ ).GetResponse ()
206206
207207 if err != nil {
208208 fmt .Printf ("error in select is %v" , err )
209209 return
210210 }
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+ }
211229 fmt .Printf ("response is %#v\n " , data )
212230
213231 var res []Tuple
@@ -224,6 +242,7 @@ func ExampleSelectRequest() {
224242 fmt .Printf ("response is %v\n " , res )
225243
226244 // Output:
245+ // pos for Select is []
227246 // response is []interface {}{[]interface {}{0x457, "hello", "world"}}
228247 // response is [{{} 1111 hello world}]
229248}
@@ -567,17 +586,21 @@ func ExampleExecuteRequest() {
567586 resp , err := conn .Do (req ).GetResponse ()
568587 fmt .Println ("Execute" )
569588 fmt .Println ("Error" , err )
589+
570590 data , err := resp .Decode ()
571591 fmt .Println ("Error" , err )
572592 fmt .Println ("Data" , data )
593+
573594 exResp , ok := resp .(* tarantool.ExecuteResponse )
574595 if ! ok {
575596 fmt .Printf ("wrong response type" )
576597 return
577598 }
599+
578600 metaData , err := exResp .MetaData ()
579601 fmt .Println ("MetaData" , metaData )
580602 fmt .Println ("Error" , err )
603+
581604 sqlInfo , err := exResp .SQLInfo ()
582605 fmt .Println ("SQL Info" , sqlInfo )
583606 fmt .Println ("Error" , err )
@@ -992,6 +1015,26 @@ func ExampleBeginRequest_TxnIsolation() {
9921015 fmt .Printf ("Select after Rollback: response is %#v\n " , data )
9931016}
9941017
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+
9951038func ExampleFuture_GetIterator () {
9961039 conn := exampleConnect (dialer , opts )
9971040 defer conn .Close ()
@@ -1008,11 +1051,11 @@ func ExampleFuture_GetIterator() {
10081051 if it .IsPush () {
10091052 // It is a push message.
10101053 fmt .Printf ("push message: %v\n " , data [0 ])
1011- } else if resp .Header ().Code == tarantool .OkCode {
1054+ } else if resp .Header ().Error == tarantool .ErrorNo {
10121055 // It is a regular response.
10131056 fmt .Printf ("response: %v" , data [0 ])
10141057 } else {
1015- fmt .Printf ("an unexpected response code %d" , resp .Header ().Code )
1058+ fmt .Printf ("an unexpected response code %d" , resp .Header ().Error )
10161059 }
10171060 }
10181061 if err := it .Err (); err != nil {
@@ -1224,6 +1267,11 @@ func ExampleConnection_Do_failure() {
12241267 if err != nil {
12251268 fmt .Printf ("Error in the future: %s\n " , err )
12261269 }
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+ }
12271275
12281276 data , err := future .Get ()
12291277 if err != nil {
@@ -1239,8 +1287,8 @@ func ExampleConnection_Do_failure() {
12391287 } else {
12401288 // Response exist. So it could be a Tarantool error or a decode
12411289 // 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 {
12441292 fmt .Printf ("Decode error: %s\n " , err )
12451293 } else {
12461294 code := err .(tarantool.Error ).Code
@@ -1251,6 +1299,7 @@ func ExampleConnection_Do_failure() {
12511299 }
12521300
12531301 // Output:
1302+ // Response error: ER_NO_SUCH_PROC
12541303 // Data: []
12551304 // Error code from the response: 33
12561305 // Error code from the error: 33
0 commit comments