Skip to content

Commit dbad08d

Browse files
committed
Merge remote-tracking branch 'origin/wl11654' into wl12751-abi-bump
2 parents 786fe2c + 5afcb9f commit dbad08d

File tree

7 files changed

+430
-277
lines changed

7 files changed

+430
-277
lines changed

include/mysqlx/xapi.h

Lines changed: 63 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ typedef struct mysqlx_client_struct mysqlx_client_t;
220220
and can be manipulated using related functions.
221221
222222
@see mysqlx_get_session_from_options(), mysqlx_session_options_new(),
223-
mysqlx_session_option_set(), mysqlx_free_options().
223+
mysqlx_session_option_set(), mysqlx_free().
224224
*/
225225

226226
typedef struct mysqlx_session_options_struct mysqlx_session_options_t;
@@ -267,6 +267,8 @@ typedef struct mysqlx_table_struct mysqlx_table_t;
267267

268268
typedef struct mysqlx_stmt_struct mysqlx_stmt_t;
269269

270+
typedef struct Mysqlx_diag_base mysqlx_object_t;
271+
270272

271273
/**
272274
Type of row handles.
@@ -515,24 +517,25 @@ mysqlx_lock_contention_t;
515517
516518
@param conn_string connection string
517519
@param client_opts client options in the form of a JSON string.
518-
@param[out] out_error if error happens during connect the error message
519-
is returned through this parameter
520-
@param[out] err_code if error happens during connect the error code
520+
@param[out] error if error happens during connect the error object
521521
is returned through this parameter
522522
523523
@return client handle if client could be created, otherwise NULL
524524
is returned and the error information is returned through
525-
the out_error and err_code output parameters.
525+
the error output parameter.
526526
527527
@note The client returned by the function must be properly closed using
528528
`mysqlx_client_close()`.
529529
530+
@note If an error object returned through the output parameter it must be
531+
freed using `mysqlx_free()`.
532+
530533
@ingroup xapi_sess
531534
*/
532535

533536
PUBLIC_API mysqlx_client_t *
534537
mysqlx_get_client_from_url(const char *conn_string, const char *client_opts,
535-
char out_error[MYSQLX_MAX_ERROR_LEN], int *err_code);
538+
mysqlx_error_t **error);
536539

537540

538541
/**
@@ -568,25 +571,25 @@ mysqlx_get_client_from_url(http://github.com/const%20char%20*conn_string,%20const%20char%20*client_opts,%3C/div%3E%3C/code%3E%3C/div%3E%3C/td%3E%3C/tr%3E%3Ctr%20class=%22diff-line-row%22%3E%3Ctd%20data-grid-cell-id=%22diff-b6658fd3a7ff3e9e86a9e43cc349168f8a65baad705d5788511de6c9e6bd75cc-568-571-0%22%20data-selected=%22false%22%20role=%22gridcell%22%20style=%22background-color:var(--bgColor-default);text-align:center" tabindex="-1" valign="top" class="focusable-grid-cell diff-line-number position-relative diff-line-number-neutral left-side">568
571
569572
@param opt handle to client configuration data
570573
@param client_opts client options in the form of a JSON string.
571-
@param[out] out_error if error happens during connect the error message
572-
is returned through this parameter
573-
@param[out] err_code if error happens during connect the error code
574+
@param[out] error if error happens during connect the error object
574575
is returned through this parameter
575576
576577
@return client handle if client could be created, otherwise NULL
577578
is returned and the error information is returned through
578-
the out_error and err_code output parameters.
579+
the error output parameter.
579580
580581
@note The client returned by the function must be properly closed using
581582
`mysqlx_client_close()`.
582583
584+
@note If an error object returned through the output parameter it must be
585+
freed using `mysqlx_free()`.
586+
583587
@ingroup xapi_sess
584588
*/
585589

586590
PUBLIC_API mysqlx_client_t *
587591
mysqlx_get_client_from_options(mysqlx_session_options_t *opt,
588-
char out_error[MYSQLX_MAX_ERROR_LEN],
589-
int *err_code);
592+
mysqlx_error_t **error);
590593

591594
/**
592595
Close the client pool and all sessions created by them.
@@ -614,19 +617,16 @@ PUBLIC_API void mysqlx_client_close(mysqlx_client_t *client);
614617
Create a new session
615618
616619
@param client client pool to get session from
617-
@param[out] out_error if error happens during getting the session handle from
618-
the pool, the error message is returned through this
619-
parameter
620-
@param[out] err_code if error happens during getting the session handle from
621-
the pool, the error code is returned through this
622-
parameter
620+
@param[out] error if error happens during connect the error object
621+
is returned through this parameter
623622
623+
@note If an error object returned through the output parameter it must be
624+
freed using `mysqlx_free()`.
624625
*/
625626

626627
PUBLIC_API mysqlx_session_t *
627-
mysqlx_get_session_from_client(mysqlx_client_t *client,
628-
char out_error[MYSQLX_MAX_ERROR_LEN],
629-
int *err_code);
628+
mysqlx_get_session_from_client(mysqlx_client_t *cli,
629+
mysqlx_error_t **error);
630630

631631
/**
632632
Create a new session.
@@ -636,26 +636,26 @@ mysqlx_get_session_from_client(mysqlx_client_t *client,
636636
@param user user name
637637
@param password password
638638
@param database default database name
639-
@param[out] out_error if error happens during connect the error message
640-
is returned through this parameter
641-
@param[out] err_code if error happens during connect the error code
639+
@param[out] error if error happens during connect the error object
642640
is returned through this parameter
643641
644642
@return session handle if session could be created, otherwise NULL
645643
is returned and the error information is returned through
646-
the out_error and err_code output parameters.
644+
output error parameter.
647645
648646
@note The session returned by the function must be properly closed using
649647
`mysqlx_session_close()`.
650648
@note This function always establishes connection with SSL enabled
649+
@note If an error object returned through the output parameter it must be
650+
freed using `mysqlx_free()`.
651651
652652
@ingroup xapi_sess
653653
*/
654654

655655
PUBLIC_API mysqlx_session_t *
656656
mysqlx_get_session(const char *host, int port, const char *user,
657-
const char *password, const char *database,
658-
char out_error[MYSQLX_MAX_ERROR_LEN], int *err_code);
657+
const char *password, const char *database,
658+
mysqlx_error_t **error);
659659

660660

661661
/**
@@ -673,49 +673,48 @@ mysqlx_get_session(const char *host, int port, const char *user,
673673
674674
Specifying `ssl-ca` option implies `ssl-mode=VERIFY_CA`.
675675
676-
@param conn_string connection string
677-
@param[out] out_error if error happens during connect the error message
678-
is returned through this parameter
679-
@param[out] err_code if error happens during connect the error code
680-
is returned through this parameter
676+
@param conn_string connection string
677+
@param[out] error if error happens during connect the error object
678+
is returned through this parameter
681679
682680
@return session handle if session could be created, otherwise NULL
683681
is returned and the error information is returned through
684-
the out_error and err_code output parameters.
682+
the error output parameter.
685683
686684
@note The session returned by the function must be properly closed using
687685
`mysqlx_session_close()`.
686+
@note If an error object returned through the output parameter it must be
687+
freed using `mysqlx_free()`.
688688
689689
@ingroup xapi_sess
690690
*/
691691

692692
PUBLIC_API mysqlx_session_t *
693693
mysqlx_get_session_from_url(const char *conn_string,
694-
char out_error[MYSQLX_MAX_ERROR_LEN], int *err_code);
695-
694+
mysqlx_error_t **error);
696695

697696
/**
698697
Create a session using session configuration data.
699698
700-
@param opt handle to session configuration data
701-
@param[out] out_error if error happens during connect the error message
702-
is returned through this parameter
703-
@param[out] err_code if error happens during connect the error code
704-
is returned through this parameter
699+
@param opt handle to session configuration data
700+
@param[out] error if error happens during connect the error object
701+
is returned through this parameter
705702
706703
@return session handle if session could be created, otherwise NULL
707704
is returned and the error information is returned through
708-
the out_error and err_code output parameters.
705+
the error output parameter.
709706
710707
@note The session returned by the function must be properly closed using
711708
`mysqlx_session_close()`.
709+
@note If an error object returned through the output parameter it must be
710+
freed using `mysqlx_free()`.
712711
713712
@ingroup xapi_sess
714713
*/
715714

716715
PUBLIC_API mysqlx_session_t *
717716
mysqlx_get_session_from_options(mysqlx_session_options_t *opt,
718-
char out_error[MYSQLX_MAX_ERROR_LEN], int *err_code);
717+
mysqlx_error_t **error);
719718

720719

721720

@@ -1018,7 +1017,7 @@ mysqlx_rollback_to( mysqlx_session_t *sess, const char *name);
10181017
@return handle to the newly allocated configuration data
10191018
10201019
@note The allocated object must be eventually freed by
1021-
`mysqlx_free_options()` to prevent memory leaks
1020+
`mysqlx_free()` to prevent memory leaks
10221021
10231022
@ingroup xapi_sess
10241023
*/
@@ -1032,6 +1031,8 @@ PUBLIC_API mysqlx_session_options_t * mysqlx_session_options_new();
10321031
@param opt handle to sessin configuartion data object
10331032
that has to be freed
10341033
1034+
@note This function is DEPRECATED. Use `mysqlx_free()` instead.
1035+
10351036
@ingroup xapi_sess
10361037
*/
10371038

@@ -2214,7 +2215,7 @@ PUBLIC_API int mysqlx_set_update_values(mysqlx_stmt_t *stmt, ...);
22142215
`mysqlx_free()`) or until another call to `mysqlx_execute()`
22152216
on the same statement handle is made. It is also possible to close
22162217
a result handle and free all resources used by it earlier with
2217-
`mysqlx_result_free()` call.
2218+
`mysqlx_free()` call.
22182219
On error NULL is returned. The statement is set to an error state and
22192220
errors can be examined using the statement handle.
22202221
@@ -2491,17 +2492,28 @@ PUBLIC_API int
24912492
mysqlx_set_row_locking(mysqlx_stmt_t *stmt, int locking, int contention);
24922493

24932494
/**
2494-
Free the statement handle explicitly.
2495+
Free the allocated handle explicitly.
24952496
2496-
@note Statement handles are also freed automatically when
2497-
statement's session is closed.
2497+
After calling this function on a handle it becomes invalid and
2498+
should not be used any more.
24982499
2499-
@param stmt statement handle
2500+
@note Statement, result, schema, collection, table and some error
2501+
handles are also freed automatically when the session is closed.
2502+
2503+
@note Only errors that originate from an already established session are
2504+
freed automatically when that session is closed.
2505+
Errors reported from one of the following functions when they
2506+
fail to create a new session or a new client must be freed explicitly:
2507+
`mysqlx_get_session()`, `mysqlx_get_session_from_url()`,
2508+
`mysqlx_get_session_from_options()`, `mysqlx_get_session_from_client()`,
2509+
`mysqlx_get_client_from_url()` and `mysqlx_get_client_from_options()`.
2510+
2511+
@param obj object handle
25002512
25012513
@ingroup xapi_stmt
25022514
*/
25032515

2504-
PUBLIC_API void mysqlx_free(mysqlx_stmt_t *stmt);
2516+
PUBLIC_API void mysqlx_free(void *obj);
25052517

25062518

25072519
/*
@@ -2799,6 +2811,8 @@ mysqlx_get_double(mysqlx_row_t* row, uint32_t col, double *val);
27992811
/**
28002812
Free the result explicitly.
28012813
2814+
@note This function is DEPRECATED. Use `mysqlx_free()` instead.
2815+
28022816
@note Results are also freed automatically when the corresponding
28032817
statement handle is freed.
28042818

testapp/xapi_test.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,7 @@ int main(int argc, const char* argv[])
6868

6969
const char *url = (argc > 1 ? argv[1] : "mysqlx://[email protected]");
7070

71-
72-
73-
char conn_error[MYSQLX_MAX_ERROR_LEN];
74-
int conn_err_code;
75-
71+
mysqlx_error_t *error;
7672
int64_t v_sint = -17;
7773
uint64_t v_uint = 101;
7874
float v_float = 3.31f;
@@ -88,10 +84,12 @@ int main(int argc, const char* argv[])
8884
Connect and create session.
8985
*/
9086

91-
sess = mysqlx_get_session_from_url(url, conn_error, &conn_err_code);
87+
sess = mysqlx_get_session_from_url(url, &error);
9288
if (!sess)
9389
{
94-
printf("\nError! %s. Error Code: %d", conn_error, conn_err_code);
90+
printf("\nError! %s. Error Code: %d", mysqlx_error_message(error),
91+
mysqlx_error_num(error));
92+
mysqlx_free(error);
9593
return -1;
9694
}
9795

@@ -117,7 +115,7 @@ int main(int argc, const char* argv[])
117115

118116
major_version = atoi(buffer);
119117

120-
mysqlx_result_free(res);
118+
mysqlx_free(res);
121119

122120
if (major_version < 8)
123121
{

xapi/error_internal.h

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,8 @@ class Mysqlx_exception
6565

6666
typedef struct mysqlx_error_struct mysqlx_error_t;
6767

68-
class Mysqlx_diag_base
68+
struct Mysqlx_diag_base
6969
{
70-
public:
7170
virtual mysqlx_error_t * get_error() = 0;
7271
};
7372

@@ -80,17 +79,23 @@ typedef struct mysqlx_error_struct : public Mysqlx_diag_base
8079
mysqlx_error_struct() : m_error_num(0), m_is_warning(false)
8180
{}
8281

83-
mysqlx_error_struct(const char *m, unsigned int n, bool is_warning = false) : m_is_warning(is_warning)
82+
mysqlx_error_struct(const char *m, unsigned int n,
83+
bool is_warning = false) :
84+
m_is_warning(is_warning)
8485
{
8586
set(m, n);
8687
}
8788

88-
mysqlx_error_struct(const cdk::Error* cdk_error, bool is_warning = false) : m_is_warning(is_warning)
89+
mysqlx_error_struct(const cdk::Error* cdk_error,
90+
bool is_warning = false) :
91+
m_is_warning(is_warning)
8992
{
9093
set(cdk_error);
9194
}
9295

93-
mysqlx_error_struct(const cdk::Error &cdk_error, bool is_warning = false) : m_is_warning(is_warning)
96+
mysqlx_error_struct(const cdk::Error &cdk_error,
97+
bool is_warning = false) :
98+
m_is_warning(is_warning)
9499
{
95100
set(&cdk_error);
96101
}
@@ -150,6 +155,12 @@ typedef struct mysqlx_error_struct : public Mysqlx_diag_base
150155
{}
151156
} mysqlx_error_t;
152157

158+
159+
struct mysqlx_dyn_error_struct : public mysqlx_error_struct
160+
{
161+
using mysqlx_error_struct::mysqlx_error_struct;
162+
};
163+
153164
class Mysqlx_diag : public Mysqlx_diag_base
154165
{
155166
protected:

0 commit comments

Comments
 (0)