@@ -190,6 +190,7 @@ MySQL_Statement::cancel()
190
190
/* {{{ MySQL_Statement::execute() -I- */
191
191
bool
192
192
MySQL_Statement::execute (const sql::SQLString& sql)
193
+ try
193
194
{
194
195
CPP_ENTER (" MySQL_Statement::execute" );
195
196
CPP_INFO_FMT (" this=%p" , this );
@@ -201,15 +202,31 @@ MySQL_Statement::execute(const sql::SQLString& sql)
201
202
throw sql::InvalidInstanceException (" Connection has been closed" );
202
203
}
203
204
bool ret = proxy_p->field_count () > 0 ;
205
+ if (!ret)
206
+ {
207
+ // If no results the span can be ended.
208
+ telemetry.span_end (this );
209
+ }
204
210
last_update_count = ret? UL64 (~0 ):proxy_p->affected_rows ();
205
211
return ret;
206
212
}
213
+ catch (sql::SQLException &e)
214
+ {
215
+ telemetry.set_error (this , e.what ());
216
+ throw e;
217
+ }
218
+ catch (...)
219
+ {
220
+ telemetry.set_error (this , " Unknown error in MySQL_Statement::execute" );
221
+ throw ;
222
+ }
207
223
/* }}} */
208
224
209
225
210
226
/* {{{ MySQL_Statement::executeQuery() -I- */
211
227
sql::ResultSet *
212
228
MySQL_Statement::executeQuery (const sql::SQLString& sql)
229
+ try
213
230
{
214
231
CPP_ENTER (" MySQL_Statement::executeQuery" );
215
232
CPP_INFO_FMT (" this=%p" , this );
@@ -226,8 +243,23 @@ MySQL_Statement::executeQuery(const sql::SQLString& sql)
226
243
logger
227
244
);
228
245
CPP_INFO_FMT (" rset=%p" , tmp);
246
+ if (tmp->isClosed () || tmp->rowsCount () == 0 )
247
+ {
248
+ // Close span if the result set is closed or empty
249
+ telemetry.span_end (this );
250
+ }
229
251
return tmp;
230
252
}
253
+ catch (sql::SQLException &e)
254
+ {
255
+ telemetry.set_error (this , e.what ());
256
+ throw e;
257
+ }
258
+ catch (...)
259
+ {
260
+ telemetry.set_error (this , " Unknown error in MySQL_Statement::executeQuery" );
261
+ throw ;
262
+ }
231
263
/* }}} */
232
264
233
265
@@ -243,6 +275,7 @@ dirty_drop_rs(std::shared_ptr< NativeAPI::NativeConnectionWrapper > proxy)
243
275
/* {{{ MySQL_Statement::executeUpdate() -I- */
244
276
int
245
277
MySQL_Statement::executeUpdate (const sql::SQLString& sql)
278
+ try
246
279
{
247
280
CPP_ENTER (" MySQL_Statement::executeUpdate" );
248
281
CPP_INFO_FMT (" this=%p" , this );
@@ -272,6 +305,7 @@ MySQL_Statement::executeUpdate(const sql::SQLString& sql)
272
305
if (got_rs){
273
306
throw sql::InvalidArgumentException (" Statement returning result set" );
274
307
} else {
308
+ telemetry.span_end (this );
275
309
return static_cast <int >(last_update_count);
276
310
}
277
311
}
@@ -289,8 +323,20 @@ MySQL_Statement::executeUpdate(const sql::SQLString& sql)
289
323
} while (1 );
290
324
291
325
/* Should not actually get here*/
326
+ telemetry.span_end (this );
292
327
return 0 ;
293
328
}
329
+ catch (sql::SQLException &e)
330
+ {
331
+ telemetry.set_error (this , e.what ());
332
+ throw e;
333
+ }
334
+ catch (...)
335
+ {
336
+ telemetry.set_error (this , " Unknown error in MySQL_Statement::executeUpdate" );
337
+ throw ;
338
+ }
339
+
294
340
/* }}} */
295
341
296
342
@@ -322,6 +368,7 @@ MySQL_Statement::getFetchSize()
322
368
/* {{{ MySQL_Statement::getResultSet() -I- */
323
369
sql::ResultSet *
324
370
MySQL_Statement::getResultSet ()
371
+ try
325
372
{
326
373
CPP_ENTER (" MySQL_Statement::getResultSet" );
327
374
CPP_INFO_FMT (" this=%p" , this );
@@ -365,12 +412,15 @@ MySQL_Statement::getResultSet()
365
412
}
366
413
else
367
414
{
415
+ // End span for NULL resultset
416
+ telemetry.span_end (this );
368
417
return NULL ;
369
418
}
370
419
}
371
420
372
421
if (!result) {
373
422
/* if there was an update then this method should return NULL and not throw */
423
+ telemetry.span_end (this );
374
424
return NULL ;
375
425
}
376
426
@@ -379,6 +429,17 @@ MySQL_Statement::getResultSet()
379
429
CPP_INFO_FMT (" res=%p" , ret);
380
430
return ret;
381
431
}
432
+ catch (sql::SQLException &e)
433
+ {
434
+ telemetry.set_error (this , e.what ());
435
+ throw e;
436
+ }
437
+ catch (...)
438
+ {
439
+ telemetry.set_error (this , " Unknown error in MySQL_Statement::getResultSet" );
440
+ throw ;
441
+ }
442
+
382
443
/* }}} */
383
444
384
445
@@ -460,6 +521,7 @@ MySQL_Statement::getMaxRows()
460
521
/* {{{ MySQL_Statement::getMoreResults() -I- */
461
522
bool
462
523
MySQL_Statement::getMoreResults ()
524
+ try
463
525
{
464
526
CPP_ENTER (" MySQL_Statement::getMoreResults" );
465
527
CPP_INFO_FMT (" this=%p" , this );
@@ -486,8 +548,21 @@ MySQL_Statement::getMoreResults()
486
548
throw sql::SQLException (" Impossible! more_results() said true, next_result says no more results" );
487
549
}
488
550
}
551
+ // If no more results close the statement span
552
+ telemetry.span_end (this );
489
553
return false ;
490
554
}
555
+ catch (sql::SQLException &e)
556
+ {
557
+ telemetry.set_error (this , e.what ());
558
+ throw e;
559
+ }
560
+ catch (...)
561
+ {
562
+ telemetry.set_error (this , " Unknown error in MySQL_Statement::getMoreResults" );
563
+ throw ;
564
+ }
565
+
491
566
/* }}} */
492
567
493
568
0 commit comments