From dce9353bc82b95d29e7fd3b27e9cf76b2b3fc7f2 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sun, 21 Jun 2020 15:30:44 +0000 Subject: [PATCH] added the mio_svc_marc_dev_error_t type --- mio/bin/t04.c | 5 ++++- mio/lib/mar-cli.c | 5 ++++- mio/lib/mio-mar.h | 34 +++++++++++++++++++++------------- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/mio/bin/t04.c b/mio/bin/t04.c index a1b2adb..7173eb0 100644 --- a/mio/bin/t04.c +++ b/mio/bin/t04.c @@ -138,8 +138,11 @@ printf ("[%lu] NO DATA..\n", sid); break; case MIO_SVC_MARC_RCODE_ERROR: - printf ("QUERY ERROR - %s\n", data); /* TODO: how to get both error code and error message? */ + { + mio_svc_marc_dev_error_t* err = (mio_svc_marc_dev_error_t*)data; + printf ("QUERY ERROR - [%d] %s\n", err->mar_errcode, err->mar_errmsg); break; + } } } diff --git a/mio/lib/mar-cli.c b/mio/lib/mar-cli.c index c94fab7..c1cd260 100644 --- a/mio/lib/mar-cli.c +++ b/mio/lib/mar-cli.c @@ -219,13 +219,16 @@ static void mar_on_query_started (mio_dev_mar_t* dev, int mar_ret, const mio_bch if (mar_ret) { + mio_svc_marc_dev_error_t err; printf ("QUERY FAILED...%d -> %s\n", mar_ret, mar_errmsg); #if 0 if (mar_ret == CR_SERVER_GONE_ERROR || /* server gone away between queries */ mar_ret == CR_SERVER_LOST) /* server gone away during a query */ #endif - sq->on_result(sess->svc, sess->sid, MIO_SVC_MARC_RCODE_ERROR, mysql_error(dev->hnd), sq->qctx); + err.mar_errcode = mar_ret; + err.mar_errmsg = mar_errmsg; + sq->on_result(sess->svc, sess->sid, MIO_SVC_MARC_RCODE_ERROR, &err, sq->qctx); dequeue_session_query (sess->svc->mio, sess); send_pending_query_if_any (sess); diff --git a/mio/lib/mio-mar.h b/mio/lib/mio-mar.h index 10f8cea..a51b22f 100644 --- a/mio/lib/mio-mar.h +++ b/mio/lib/mio-mar.h @@ -50,11 +50,11 @@ enum mio_dev_mar_state_t /* convenience bit masks */ MIO_DEV_MAR_ALL_PROGRESS_BITS = (MIO_DEV_MAR_CONNECTING | - MIO_DEV_MAR_CONNECTED | - MIO_DEV_MAR_QUERY_STARTING | - MIO_DEV_MAR_QUERY_STARTED | - MIO_DEV_MAR_ROW_FETCHING | - MIO_DEV_MAR_ROW_FETCHED) + MIO_DEV_MAR_CONNECTED | + MIO_DEV_MAR_QUERY_STARTING | + MIO_DEV_MAR_QUERY_STARTED | + MIO_DEV_MAR_ROW_FETCHING | + MIO_DEV_MAR_ROW_FETCHED) }; typedef enum mio_dev_mar_state_t mio_dev_mar_state_t; @@ -168,10 +168,18 @@ enum mio_svc_marc_rcode_t { MIO_SVC_MARC_RCODE_ROW, /* has row *- data is MYSQL_ROW */ MIO_SVC_MARC_RCODE_DONE, /* completed or no more row - data is NULL */ - MIO_SVC_MARC_RCODE_ERROR /* query error - data is a numeric database error code cast to void* */ + MIO_SVC_MARC_RCODE_ERROR /* query error - data is mio_sv_marc_dev_error_t* */ }; typedef enum mio_svc_marc_rcode_t mio_svc_marc_rcode_t; + +struct mio_svc_marc_dev_error_t +{ + int mar_errcode; + const mio_bch_t* mar_errmsg; +}; +typedef struct mio_svc_marc_dev_error_t mio_svc_marc_dev_error_t; + typedef void (*mio_svc_marc_on_result_t) ( mio_svc_marc_t* marc, mio_oow_t sid, @@ -250,13 +258,13 @@ static MIO_INLINE mio_t* mio_svc_marc_getmio(mio_svc_marc_t* svc) { return mio_s MIO_EXPORT int mio_svc_mar_querywithbchars ( - mio_svc_marc_t* marc, - mio_oow_t sid, - mio_svc_marc_qtype_t qtype, - const mio_bch_t* qptr, - mio_oow_t qlen, - mio_svc_marc_on_result_t on_result, - void* qctx + mio_svc_marc_t* marc, + mio_oow_t sid, + mio_svc_marc_qtype_t qtype, + const mio_bch_t* qptr, + mio_oow_t qlen, + mio_svc_marc_on_result_t on_result, + void* qctx ); #ifdef __cplusplus