MySQL Connector/C++ 9.5.0
MySQL connector library for C and C++ applications
xapi.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016, 2024, Oracle and/or its affiliates.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2.0, as
6 * published by the Free Software Foundation.
7 *
8 * This program is designed to work with certain software (including
9 * but not limited to OpenSSL) that is licensed under separate terms, as
10 * designated in a particular file or component or in included license
11 * documentation. The authors of MySQL hereby grant you an additional
12 * permission to link the program and your derivative works with the
13 * separately licensed software that they have either included with
14 * the program or referenced in the documentation.
15 *
16 * Without limiting anything contained in the foregoing, this file,
17 * which is part of Connector/C++, is also subject to the
18 * Universal FOSS Exception, version 1.0, a copy of which can be found at
19 * https://oss.oracle.com/licenses/universal-foss-exception.
20 *
21 * This program is distributed in the hope that it will be useful, but
22 * WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
24 * See the GNU General Public License, version 2.0, for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software Foundation, Inc.,
28 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 */
30
71#ifndef MYSQL_XAPI_H
72#define MYSQL_XAPI_H
73
74
75#ifdef __cplusplus
76extern "C" {
77#endif
78
79
80#include "common_constants.h"
81#include "common/api.h"
82
83#include <stdlib.h>
84#include <stdint.h>
85#include <stdbool.h>
86
93// FIXME
94#define STDCALL
95
97
98typedef char object_id[16];
99typedef object_id* MYSQLX_GUID;
100
103#define RESULT_OK 0
104
111#define RESULT_MORE_DATA 8
112
119#define RESULT_NULL 16
120
126#define RESULT_INFO 32
127
130#define RESULT_WARNING 64
131
134#define RESULT_ERROR 128
135
136
137#define MYSQLX_MAX_ERROR_LEN 255
138#define MYSQLX_NULL_TERMINATED 0xFFFFFFFF
139
140#define MYSQLX_ERR_UNKNOWN 0xFFFF
141
142#define MYSQLX_COLLATION_UNDEFINED 0
143
144
145/*
146 Error codes
147*/
148
149#define MYSQLX_ERROR_INDEX_OUT_OF_RANGE 1
150
151/*
152 Error messages
153*/
154
155#define MYSQLX_ERROR_INDEX_OUT_OF_RANGE_MSG "Index is out of range"
156#define MYSQLX_ERROR_MISSING_SCHEMA_NAME_MSG "Missing schema name"
157#define MYSQLX_ERROR_MISSING_TABLE_NAME_MSG "Missing table name"
158#define MYSQLX_ERROR_MISSING_VIEW_NAME_MSG "Missing view name"
159#define MYSQLX_ERROR_MISSING_COLLECTION_NAME_MSG "Missing collection name"
160#define MYSQLX_ERROR_MISSING_COLLECTION_OPT_MSG "Missing collection options"
161#define MYSQLX_ERROR_MISSING_VIEW_NAME_MSG "Missing view name"
162#define MYSQLX_ERROR_MISSING_KEY_NAME_MSG "Missing key name"
163#define MYSQLX_ERROR_MISSING_HOST_NAME "Missing host name"
164#define MYSQLX_ERROR_MISSING_SOCKET_NAME "Missing socket name"
165#define MYSQLX_ERROR_MISSING_CONN_INFO "Missing connecting information"
166#define MYSQLX_ERROR_HANDLE_NULL_MSG "Handle cannot be NULL"
167#define MYSQLX_ERROR_VIEW_INVALID_STMT_TYPE "Invalid statement type for View. Only SELECT type is supported"
168#define MYSQLX_ERROR_VIEW_TYPE_MSG "Statement must be of VIEW type"
169#define MYSQLX_ERROR_OUTPUT_BUFFER_NULL "The output buffer cannot be NULL"
170#define MYSQLX_ERROR_OUTPUT_BUFFER_ZERO "The output buffer cannot have zero length"
171#define MYSQLX_ERROR_OUTPUT_VARIABLE_NULL "The output variable cannot be NULL"
172#define MYSQLX_ERROR_OP_NOT_SUPPORTED "The operation is not supported by the function"
173#define MYSQLX_ERROR_WRONG_SSL_MODE "Wrong value for SSL Mode"
174#define MYSQLX_ERROR_NO_TLS_SUPPORT "Can not create TLS session - this connector is built without TLS support"
175#define MYSQLX_ERROR_MIX_PRIORITY "Mixing hosts with and without priority is not allowed"
176#define MYSQLX_ERROR_DUPLICATED_OPTION "Option already defined"
177#define MYSQLX_ERROR_MAX_PRIORITY "Priority should be a value between 0 and 100"
178#define MYSQLX_ERROR_AUTH_METHOD "Unknown authentication method"
179#define MYSQLX_ERROR_ROW_LOCKING "Row locking is supported only for SELECT and FIND"
180#define MYSQLX_ERROR_WRONG_LOCKING_MODE "Wrong value for the row locking mode"
181#define MYSQLX_ERROR_WRONG_EXPRESSION "Expression could not be parsed"
182#define MYSQLX_ERROR_EMPTY_JSON "Empty JSON document string"
183
184
185/* Opaque structures*/
186
196typedef struct mysqlx_error_struct mysqlx_error_t;
197
198
205typedef struct mysqlx_session_struct mysqlx_session_t;
206
213typedef struct mysqlx_client_struct mysqlx_client_t;
214
215
227typedef struct mysqlx_session_options_struct mysqlx_session_options_t;
228
236typedef struct mysqlx_collection_options_struct mysqlx_collection_options_t;
237
244typedef struct mysqlx_schema_struct mysqlx_schema_t;
245
246
253typedef struct mysqlx_collection_struct mysqlx_collection_t;
254
255
261typedef struct mysqlx_table_struct mysqlx_table_t;
262
263
277typedef struct mysqlx_stmt_struct mysqlx_stmt_t;
278
279typedef struct Mysqlx_diag_base mysqlx_object_t;
280
281
288typedef struct mysqlx_row_struct mysqlx_row_t;
289
290
301typedef struct mysqlx_result_struct mysqlx_result_t;
302
303
308typedef enum mysqlx_data_type_enum
309{
310 MYSQLX_TYPE_UNDEFINED = 0,
311
312 /* Column types as defined in protobuf (mysqlx_resultset.proto)*/
325 /* Column types from DevAPI (no number constants assigned, just names)*/
333 MYSQLX_TYPE_EXPR = 101
335
336#define PARAM_SINT(A) (void*)MYSQLX_TYPE_SINT, (int64_t)A
337#define PARAM_UINT(A) (void*)MYSQLX_TYPE_UINT, (uint64_t)A
338#define PARAM_FLOAT(A) (void*)MYSQLX_TYPE_FLOAT, (double)A
339#define PARAM_DOUBLE(A) (void*)MYSQLX_TYPE_DOUBLE, (double)A
340#define PARAM_BYTES(DATA, SIZE) (void*)MYSQLX_TYPE_BYTES, (void*)DATA, (size_t)SIZE
341#define PARAM_STRING(A) (void*)MYSQLX_TYPE_STRING, A
342#define PARAM_EXPR(A) (void*)MYSQLX_TYPE_EXPR, A
343#define PARAM_NULL() (void*)MYSQLX_TYPE_NULL
344
345#define PARAM_END (void*)0
346
347
352typedef enum mysqlx_sort_direction_enum
353{
355 SORT_ORDER_DESC = 2
357
358
359#define PARAM_SORT_ASC(A) A, SORT_ORDER_ASC
360#define PARAM_SORT_DESC(A) A, SORT_ORDER_DESC
361
368typedef enum mysqlx_client_opt_type_enum
369{
370
371#define XAPI_CLIENT_OPT_ENUM_str(X,N) MYSQLX_CLIENT_OPT_##X = -N,
372#define XAPI_CLIENT_OPT_ENUM_bool(X,N) MYSQLX_CLIENT_OPT_##X = -N,
373#define XAPI_CLIENT_OPT_ENUM_num(X,N) MYSQLX_CLIENT_OPT_##X = -N,
374#define XAPI_CLIENT_OPT_ENUM_any(X,N) MYSQLX_CLIENT_OPT_##X = -N,
375
376 CLIENT_OPTION_LIST(XAPI_CLIENT_OPT_ENUM)
377}
379
380#define OPT_POOLING(A) MYSQLX_CLIENT_OPT_POOLING, (int)(bool)(A)
381#define OPT_POOL_MAX_SIZE(A) MYSQLX_CLIENT_OPT_POOL_MAX_SIZE, (uint64_t)(A)
382#define OPT_POOL_QUEUE_TIMEOUT(A) MYSQLX_CLIENT_OPT_POOL_QUEUE_TIMEOUT, (uint64_t)(A)
383#define OPT_POOL_MAX_IDLE_TIME(A) MYSQLX_CLIENT_OPT_POOL_MAX_IDLE_TIME, (uint64_t)(A)
384
397typedef enum mysqlx_opt_type_enum
398{
399
400#define XAPI_OPT_ENUM_str(X,N) MYSQLX_OPT_##X = N,
401#define XAPI_OPT_ENUM_num(X,N) MYSQLX_OPT_##X = N,
402#define XAPI_OPT_ENUM_any(X,N) MYSQLX_OPT_##X = N,
403#define XAPI_OPT_ENUM_bool(X,N) MYSQLX_OPT_##X = N,
404
405 SESSION_OPTION_LIST(XAPI_OPT_ENUM)
406 MYSQLX_OPT_LAST
407}
409
410#define OPT_HOST(A) MYSQLX_OPT_HOST, (A)
411#define OPT_PORT(A) MYSQLX_OPT_PORT, (unsigned int)(A)
412#ifndef _WIN32
413#define OPT_SOCKET(A) MYSQLX_OPT_SOCKET, (A)
414#endif //_WIN32
415#define OPT_DNS_SRV(A) MYSQLX_OPT_DNS_SRV, (A)
416#define OPT_USER(A) MYSQLX_OPT_USER, (A)
417#define OPT_PWD(A) MYSQLX_OPT_PWD, (A)
418#define OPT_DB(A) MYSQLX_OPT_DB, (A)
419#define OPT_SSL_MODE(A) MYSQLX_OPT_SSL_MODE, (A)
420#define OPT_SSL_CA(A) MYSQLX_OPT_SSL_CA, (A)
421#define OPT_SSL_CAPATH(A) MYSQLX_OPT_SSL_CAPATH, (A)
422#define OPT_SSL_CRL(A) MYSQLX_OPT_SSL_CRL, (A)
423#define OPT_SSL_CRLPATH(A) MYSQLX_OPT_SSL_CRLPATH, (A)
424#define OPT_PRIORITY(A) MYSQLX_OPT_PRIORITY, (unsigned int)(A)
425#define OPT_AUTH(A) MYSQLX_OPT_AUTH, (unsigned int)(A)
426#define OPT_CONNECT_TIMEOUT(A) MYSQLX_OPT_CONNECT_TIMEOUT, (unsigned int)(A)
427#define OPT_CONNECTION_ATTRIBUTES(A) MYSQLX_OPT_CONNECTION_ATTRIBUTES, (A)
428#define OPT_TLS_VERSIONS(A) MYSQLX_OPT_TLS_VERSIONS, (A)
429#define OPT_TLS_CIPHERSUITES(A) MYSQLX_OPT_TLS_CIPHERSUITES, (A)
430#define OPT_COMPRESSION(A) MYSQLX_OPT_COMPRESSION, (unsigned int)(A)
431#define OPT_COMPRESSION_ALGORITHMS(A) MYSQLX_OPT_COMPRESSION_ALGORITHMS, (const char*)(A)
432#define OPT_READ_TIMEOUT(A) MYSQLX_OPT_READ_TIMEOUT, (unsigned int)(A)
433#define OPT_WRITE_TIMEOUT(A) MYSQLX_OPT_WRITE_TIMEOUT, (unsigned int)(A)
434
435
442typedef enum mysqlx_ssl_mode_enum
443{
444#define XAPI_SSL_MODE_ENUM(X,N) SSL_MODE_##X = N,
445
446 SSL_MODE_LIST(XAPI_SSL_MODE_ENUM)
447}
449
456typedef enum mysqlx_auth_method_enum
457{
458#define XAPI_AUTH_ENUM(X,N) MYSQLX_AUTH_##X = N,
460 AUTH_METHOD_LIST(XAPI_AUTH_ENUM)
461}
463
470typedef enum mysqlx_collection_opt_enum
471{
472
473#define XAPI_COLLECTION_OPT_ENUM(X,N) MYSQLX_OPT_COLLECTION_##X = N,
474
475 COLLECTION_OPTIONS_OPTION(XAPI_COLLECTION_OPT_ENUM)
476 MYSQLX_OPT_COLLECTION_LAST
477}
479
486typedef enum mysqlx_collection_validation_opt_enum
487{
489#define XAPI_COLLECTION_VALIDATION_OPT_ENUM(X,N) MYSQLX_OPT_COLLECTION_VALIDATION_##X = 1024+N,
490
491 COLLECTION_VALIDATION_OPTION(XAPI_COLLECTION_VALIDATION_OPT_ENUM)
492 MYSQLX_OPT_COLLECTION_VALIDATION_LAST
493}
495
501typedef enum mysqlx_collection_validation_level_enum
503
504#define XAPI_COLLECTION_VALIDATION_LEVEL_ENUM(X,N) MYSQLX_OPT_COLLECTION_VALIDATION_LEVEL_##X = 2048+N,
505
506 COLLECTION_VALIDATION_LEVEL(XAPI_COLLECTION_VALIDATION_LEVEL_ENUM)
507 MYSQLX_OPT_COLLECTION_VALIDATION_LEVEL_LAST
508}
510
511#define VALIDATION_OFF MYSQLX_OPT_COLLECTION_VALIDATION_LEVEL_OFF
512#define VALIDATION_STRICT MYSQLX_OPT_COLLECTION_VALIDATION_LEVEL_STRICT
513
514#define OPT_COLLECTION_REUSE(X) MYSQLX_OPT_COLLECTION_REUSE, (unsigned int)X
515#define OPT_COLLECTION_VALIDATION(X) MYSQLX_OPT_COLLECTION_VALIDATION, (const char*)X
516#define OPT_COLLECTION_VALIDATION_LEVEL(X) MYSQLX_OPT_COLLECTION_VALIDATION_LEVEL, (unsigned int)X
517#define OPT_COLLECTION_VALIDATION_SCHEMA(X) MYSQLX_OPT_COLLECTION_VALIDATION_SCHEMA, (const char*)X
523typedef enum mysqlx_compression_mode_enum
524{
525#define XAPI_COMPRESSION_ENUM(X,N) MYSQLX_COMPRESSION_##X = N,
526
527 COMPRESSION_MODE_LIST(XAPI_COMPRESSION_ENUM)
528}
536typedef enum mysqlx_row_locking_enum
537{
538#define XAPI_ROW_LOCK_ENUM(X,N) ROW_LOCK_##X = N,
539
540 ROW_LOCK_NONE = 0,
541 LOCK_MODE_LIST(XAPI_ROW_LOCK_ENUM)
542}
544
550typedef enum mysqlx_lock_contention_enum
551{
552#define XAPI_LOCK_CONTENTION_ENUM(X,N) LOCK_CONTENTION_##X = N,
553
554 LOCK_CONTENTION_LIST(XAPI_LOCK_CONTENTION_ENUM)
555}
557
558/*
559 ====================================================================
560 Client operations
561 ====================================================================
562*/
563
626PUBLIC_API mysqlx_client_t *
627mysqlx_get_client_from_url(const char *conn_string, const char *client_opts,
628 mysqlx_error_t **error);
629
630
679PUBLIC_API mysqlx_client_t *
681 mysqlx_error_t **error);
682
700PUBLIC_API void mysqlx_client_close(mysqlx_client_t *client);
701
702/*
703 ====================================================================
704 Session operations
705 ====================================================================
706*/
707
719PUBLIC_API mysqlx_session_t *
721 mysqlx_error_t **error);
722
747PUBLIC_API mysqlx_session_t *
748mysqlx_get_session(const char *host, int port, const char *user,
749 const char *password, const char *database,
750 mysqlx_error_t **error);
751
752
836PUBLIC_API mysqlx_session_t *
837mysqlx_get_session_from_url(const char *conn_string,
838 mysqlx_error_t **error);
839
859PUBLIC_API mysqlx_session_t *
861 mysqlx_error_t **error);
862
863
864
880PUBLIC_API void mysqlx_session_close(mysqlx_session_t *session);
881
882
900PUBLIC_API int mysqlx_session_valid(mysqlx_session_t *sess);
901
921PUBLIC_API mysqlx_result_t *
922mysqlx_get_schemas(mysqlx_session_t *sess, const char *schema_pattern);
923
924
944PUBLIC_API mysqlx_schema_t *
945mysqlx_get_schema(mysqlx_session_t *sess, const char *schema_name,
946 unsigned int check);
947
948
976PUBLIC_API mysqlx_result_t *
978 const char *table_pattern,
979 int get_views);
980
981
1001PUBLIC_API mysqlx_table_t *
1002mysqlx_get_table(mysqlx_schema_t *schema, const char *tab_name,
1003 unsigned int check);
1004
1005
1026PUBLIC_API mysqlx_result_t *
1028 const char *col_pattern);
1029
1030
1050PUBLIC_API mysqlx_collection_t *
1051mysqlx_get_collection(mysqlx_schema_t *schema, const char *col_name,
1052 unsigned int check);
1053
1054
1070PUBLIC_API int
1072
1073
1088PUBLIC_API int
1090
1091
1106PUBLIC_API int
1108
1109
1127PUBLIC_API const char*
1128mysqlx_savepoint_set( mysqlx_session_t *sess, const char *name);
1129
1130
1144PUBLIC_API int
1145mysqlx_savepoint_release(mysqlx_session_t *sess, const char *name);
1146
1147
1161PUBLIC_API int
1162mysqlx_rollback_to( mysqlx_session_t *sess, const char *name);
1163
1164
1177
1178
1190PUBLIC_API void mysqlx_free_options(mysqlx_session_options_t *opt);
1191
1192
1221PUBLIC_API int
1223
1224
1252PUBLIC_API int
1254 ...);
1255
1256/*
1257 ====================================================================
1258 SQL execution
1259 ====================================================================
1260*/
1261
1279 const char *query,
1280 size_t query_len);
1281
1282
1315 const char *query,
1316 size_t query_len, ...);
1317
1318
1344PUBLIC_API mysqlx_stmt_t *
1345mysqlx_sql_new(mysqlx_session_t *sess, const char *query,
1346 uint32_t length);
1347
1348
1349/*
1350 ====================================================================
1351 Collection operations
1352 ====================================================================
1353*/
1354
1367PUBLIC_API int
1368mysqlx_collection_count(mysqlx_collection_t *collection, uint64_t *count);
1369
1370
1386PUBLIC_API mysqlx_result_t *
1387mysqlx_collection_find(mysqlx_collection_t *collection, const char *criteria);
1388
1389
1422PUBLIC_API mysqlx_result_t *
1424
1425
1440PUBLIC_API mysqlx_result_t *
1441mysqlx_collection_remove(mysqlx_collection_t *collection, const char*criteria);
1442
1443
1476PUBLIC_API mysqlx_result_t *
1478 const char *criteria, ...);
1479
1480
1497PUBLIC_API mysqlx_result_t *
1499 const char *criteria, ...);
1500
1501
1519PUBLIC_API mysqlx_result_t *
1521 const char *criteria,
1522 const char *patch_spec);
1523
1524
1538PUBLIC_API int
1540 const char *patch_spec);
1541
1542/*
1543 Deferred statement execution
1544 ----------------------------
1545*/
1546
1563PUBLIC_API mysqlx_stmt_t *
1565
1566
1587PUBLIC_API int mysqlx_set_find_projection(mysqlx_stmt_t *stmt, const char *proj);
1588
1589
1598#define mysqlx_set_find_criteria mysqlx_set_where
1599
1600
1601/*
1602A macro defining a function for setting HAVING for FIND operation.
1603
1604@see mysqlx_set_having()
1605@ingroup xapi_tbl
1606*/
1607
1608#define mysqlx_set_find_having mysqlx_set_having
1609
1618#define mysqlx_set_find_group_by mysqlx_set_group_by
1619
1628#define mysqlx_set_find_limit_and_offset(STMT, LIM, OFFS) mysqlx_set_limit_and_offset(STMT, LIM, OFFS)
1629
1638#define mysqlx_set_find_order_by mysqlx_set_order_by
1639
1640
1649#define mysqlx_set_find_row_locking mysqlx_set_row_locking
1650
1651
1669PUBLIC_API mysqlx_stmt_t *
1671
1672
1698PUBLIC_API int
1699mysqlx_set_add_document(mysqlx_stmt_t *stmt, const char *json_doc);
1700
1701
1718PUBLIC_API mysqlx_stmt_t *
1720
1729#define mysqlx_set_remove_criteria mysqlx_set_where
1730
1739#define mysqlx_set_remove_order_by mysqlx_set_order_by
1740
1749#define mysqlx_set_remove_limit_and_offset mysqlx_set_limit_and_offset
1750
1751
1769PUBLIC_API mysqlx_stmt_t *
1771
1772
1795PUBLIC_API int
1797
1798
1812PUBLIC_API int
1814
1815
1835PUBLIC_API int
1837
1838
1858PUBLIC_API int
1860
1861
1874PUBLIC_API int mysqlx_set_modify_array_delete(mysqlx_stmt_t *stmt, ...);
1875
1884#define mysqlx_set_modify_criteria mysqlx_set_where
1885
1886
1887/*
1888 ====================================================================
1889 Table operations
1890 ====================================================================
1891*/
1892
1893
1906PUBLIC_API int
1907mysqlx_table_count(mysqlx_table_t *table, uint64_t *count);
1908
1909
1926PUBLIC_API mysqlx_result_t *
1927mysqlx_table_select(mysqlx_table_t *table, const char *criteria);
1928
1929
1957PUBLIC_API mysqlx_result_t *
1958mysqlx_table_select_limit(mysqlx_table_t *table, const char *criteria,
1959 uint64_t row_count, uint64_t offset, ...);
1960
1961
1986PUBLIC_API mysqlx_result_t *
1988
1989
2004PUBLIC_API mysqlx_result_t *
2005mysqlx_table_delete(mysqlx_table_t *table, const char *criteria);
2006
2007
2008
2034PUBLIC_API mysqlx_result_t *
2036 const char *criteria,
2037 ...);
2038
2039
2040/*
2041 Deferred statement execution
2042 ----------------------------
2043*/
2044
2064PUBLIC_API mysqlx_stmt_t *
2066
2075#define mysqlx_set_select_items mysqlx_set_items
2076
2085#define mysqlx_set_select_where mysqlx_set_where
2086
2087
2096#define mysqlx_set_select_order_by mysqlx_set_order_by
2097
2098
2099/*
2100 A macro defining a function for setting HAVING for SELECT operation.
2101
2102 @see mysqlx_set_having()
2103 @ingroup xapi_tbl
2104*/
2105
2106#define mysqlx_set_select_having mysqlx_set_having
2107
2116#define mysqlx_set_select_group_by mysqlx_set_group_by
2117
2126#define mysqlx_set_select_limit_and_offset mysqlx_set_limit_and_offset
2127
2128
2137#define mysqlx_set_select_row_locking mysqlx_set_row_locking
2138
2139
2157PUBLIC_API mysqlx_stmt_t *
2159
2160
2182PUBLIC_API int
2184
2185
2209PUBLIC_API int
2211
2212
2232PUBLIC_API mysqlx_stmt_t *
2234
2243#define mysqlx_set_delete_where mysqlx_set_where
2252#define mysqlx_set_delete_limit(STMT, LIM) mysqlx_set_limit_and_offset(STMT, LIM, 0)
2261#define mysqlx_set_delete_order_by mysqlx_set_order_by
2262
2263
2284PUBLIC_API mysqlx_stmt_t *
2286
2287
2316PUBLIC_API int mysqlx_set_update_values(mysqlx_stmt_t *stmt, ...);
2317
2326#define mysqlx_set_update_where mysqlx_set_where
2327
2336#define mysqlx_set_update_limit(STMT, LIM) mysqlx_set_limit_and_offset(STMT, LIM, 0)
2337
2338
2347#define mysqlx_set_update_order_by mysqlx_set_order_by
2348
2349
2350/*
2351 ====================================================================
2352 Statement execution
2353 ====================================================================
2354*/
2355
2378PUBLIC_API mysqlx_result_t *
2380
2381
2426PUBLIC_API int mysqlx_stmt_bind(mysqlx_stmt_t *stmt, ...);
2427
2428
2451PUBLIC_API int mysqlx_set_items(mysqlx_stmt_t *stmt, ...);
2452
2453
2482PUBLIC_API int mysqlx_set_where(mysqlx_stmt_t *stmt, const char *where_expr);
2483
2484
2513PUBLIC_API int mysqlx_set_having(mysqlx_stmt_t *stmt, const char *having_expr);
2514
2515
2542PUBLIC_API int mysqlx_set_group_by(mysqlx_stmt_t *stmt, ...);
2543
2575PUBLIC_API int mysqlx_set_order_by(mysqlx_stmt_t *stmt, ...);
2576
2577
2610PUBLIC_API int
2611mysqlx_set_limit_and_offset(mysqlx_stmt_t *stmt, uint64_t row_count,
2612 uint64_t offset);
2613
2644PUBLIC_API int
2645mysqlx_set_row_locking(mysqlx_stmt_t *stmt, int locking, int contention);
2646
2672PUBLIC_API void mysqlx_free(void *obj);
2673
2674
2675/*
2676 ====================================================================
2677 Result handling
2678 ====================================================================
2679*/
2680
2698
2699
2717PUBLIC_API const char * mysqlx_json_fetch_one(mysqlx_result_t *res, size_t *out_length);
2718
2719
2738PUBLIC_API int mysqlx_next_result(mysqlx_result_t *res);
2739
2740
2754PUBLIC_API uint64_t
2756
2757
2785PUBLIC_API int
2786mysqlx_store_result(mysqlx_result_t *result, size_t *num);
2787
2788
2806PUBLIC_API int
2807mysqlx_get_count(mysqlx_result_t *result, size_t *num);
2808
2809
2833PUBLIC_API const char *
2835
2836
2851PUBLIC_API uint64_t
2853
2854
2903PUBLIC_API int
2904mysqlx_get_bytes(mysqlx_row_t* row, uint32_t col,
2905 uint64_t offset, void *buf, size_t *buf_len);
2906
2907
2926PUBLIC_API int
2927mysqlx_get_uint(mysqlx_row_t* row, uint32_t col, uint64_t* val);
2928
2929
2948PUBLIC_API int
2949mysqlx_get_sint(mysqlx_row_t* row, uint32_t col, int64_t* val);
2950
2951
2970PUBLIC_API int
2971mysqlx_get_float(mysqlx_row_t* row, uint32_t col, float* val);
2972
2973
2992PUBLIC_API int
2993mysqlx_get_double(mysqlx_row_t* row, uint32_t col, double *val);
2994
2995
3009PUBLIC_API void mysqlx_result_free(mysqlx_result_t *res);
3010
3011
3012/*
3013 Result metadata
3014 ---------------
3015*/
3016
3028PUBLIC_API uint16_t
3029mysqlx_column_get_type(mysqlx_result_t *res, uint32_t pos);
3030
3031
3045PUBLIC_API uint16_t
3047
3048
3067PUBLIC_API uint32_t
3068mysqlx_column_get_length(mysqlx_result_t *res, uint32_t pos);
3069
3070
3082PUBLIC_API uint16_t
3084
3085
3086/*
3087 Get column flags.
3088
3089 @param res result handle
3090 @param pos zero-based column number
3091
3092 @return 32-bit unsigned integer containing column flags reported by
3093 server. TODO: Document these
3094
3095 @ingroup xapi_md
3096*/
3097//PUBLIC_API uint32_t
3098//mysqlx_column_get_flags(mysqlx_result_t *res, uint32_t pos);
3099
3100
3115PUBLIC_API uint32_t
3117
3118
3130PUBLIC_API const char *
3131mysqlx_column_get_name(mysqlx_result_t *res, uint32_t pos);
3132
3133
3145PUBLIC_API const char *
3147
3148
3160PUBLIC_API const char *
3161mysqlx_column_get_table(mysqlx_result_t *res, uint32_t pos);
3162
3163
3175PUBLIC_API const char *
3177
3178
3190PUBLIC_API const char *
3191mysqlx_column_get_schema(mysqlx_result_t *res, uint32_t pos);
3192
3193
3205PUBLIC_API const char *
3206mysqlx_column_get_catalog(mysqlx_result_t *res, uint32_t pos);
3207
3208
3209/*
3210 ====================================================================
3211 DDL statements
3212 ====================================================================
3213*/
3214
3228PUBLIC_API int
3229mysqlx_schema_create(mysqlx_session_t *sess, const char *schema);
3230
3231
3245PUBLIC_API int
3246mysqlx_schema_drop(mysqlx_session_t *sess, const char *schema);
3247
3248
3262PUBLIC_API int
3263mysqlx_collection_create(mysqlx_schema_t *schema, const char *collection);
3264
3265
3277PUBLIC_API mysqlx_collection_options_t *
3279
3280
3310PUBLIC_API int
3312
3313
3328PUBLIC_API int
3330 const char *collection,
3332
3380PUBLIC_API int
3382 const char *collection,
3383 const char* json_options);
3384
3385PUBLIC_API int
3386mysqlx_collection_modify_with_options(mysqlx_schema_t *schema,
3387 const char *collection,
3389
3390PUBLIC_API int
3391mysqlx_collection_modify_with_json_options(mysqlx_schema_t *schema,
3392 const char* collection,
3393 const char* json_options);
3394
3395
3396
3410PUBLIC_API int
3411mysqlx_collection_drop(mysqlx_schema_t *schema, const char *collection);
3412
3413
3414/*
3415 ====================================================================
3416 Diagnostics
3417 ====================================================================
3418*/
3419
3420
3435PUBLIC_API mysqlx_error_t * mysqlx_error(void *obj);
3436
3437
3452PUBLIC_API const char * mysqlx_error_message(void *obj);
3453
3454
3469PUBLIC_API unsigned int mysqlx_error_num(void *obj);
3470
3471
3481PUBLIC_API unsigned int mysqlx_result_warning_count(mysqlx_result_t *res);
3482
3483
3501PUBLIC_API mysqlx_error_t *
3503
3504
3525PUBLIC_API int
3527 const char *idx_spec);
3528
3547PUBLIC_API int
3548mysqlx_collection_drop_index(mysqlx_collection_t *coll, const char *name);
3549
3550
3551#ifdef __cplusplus
3552}
3553#endif
3554
3557#endif /* __MYSQLX_H__*/
int mysqlx_table_count(mysqlx_table_t *table, uint64_t *count)
Return a number of rows in a table.
int mysqlx_set_modify_array_append(mysqlx_stmt_t *stmt,...)
Append to array fields in a document.
mysqlx_stmt_t * mysqlx_collection_find_new(mysqlx_collection_t *collection)
Create a statement which finds documents in a collection.
int mysqlx_set_modify_patch(mysqlx_stmt_t *stmt, const char *patch_spec)
Set a given patch for a modify statement to be applied to documents in a collection after executing t...
mysqlx_result_t * mysqlx_collection_find(mysqlx_collection_t *collection, const char *criteria)
Execute a collection FIND statement with a specific find criteria.
mysqlx_result_t * mysqlx_collection_remove(mysqlx_collection_t *collection, const char *criteria)
Remove documents from a collection.
int mysqlx_set_modify_unset(mysqlx_stmt_t *stmt,...)
Unset fields in a document.
int mysqlx_collection_count(mysqlx_collection_t *collection, uint64_t *count)
Return a number of documents in a collection.
int mysqlx_set_modify_array_insert(mysqlx_stmt_t *stmt,...)
Insert elements into array fields in a document.
int mysqlx_set_modify_array_delete(mysqlx_stmt_t *stmt,...)
Delete elements from array fields in a document.
mysqlx_result_t * mysqlx_collection_modify_set(mysqlx_collection_t *collection, const char *criteria,...)
Modify documents in the collection.
mysqlx_result_t * mysqlx_collection_add(mysqlx_collection_t *collection,...)
Add a set of new documents to a collection.
mysqlx_stmt_t * mysqlx_collection_remove_new(mysqlx_collection_t *collection)
Create a statement which removes documents from a collection.
int mysqlx_set_add_document(mysqlx_stmt_t *stmt, const char *json_doc)
Specify a document to be added to a collection.
int mysqlx_set_modify_set(mysqlx_stmt_t *stmt,...)
Set fields in a document to given values.
mysqlx_stmt_t * mysqlx_collection_add_new(mysqlx_collection_t *collection)
Create a statement which adds documents to a collection.
mysqlx_result_t * mysqlx_collection_modify_unset(mysqlx_collection_t *collection, const char *criteria,...)
Unset fields in documents from the collection.
int mysqlx_set_find_projection(mysqlx_stmt_t *stmt, const char *proj)
Specify a projection for a collection find query.
mysqlx_result_t * mysqlx_collection_modify_patch(mysqlx_collection_t *collection, const char *criteria, const char *patch_spec)
Apply a given patch to documents in a collection.
mysqlx_stmt_t * mysqlx_collection_modify_new(mysqlx_collection_t *collection)
Create a statement which modifies documents in a collection.
int mysqlx_schema_drop(mysqlx_session_t *sess, const char *schema)
Drop a schema.
mysqlx_collection_options_t * mysqlx_collection_options_new()
Allocate a new create/modify collection options data.
int mysqlx_collection_create_with_json_options(mysqlx_schema_t *schema, const char *collection, const char *json_options)
Create a new collection in a specified schema.
int mysqlx_collection_options_set(mysqlx_collection_options_t *options,...)
Set collection options.
int mysqlx_collection_create_index(mysqlx_collection_t *coll, const char *name, const char *idx_spec)
Create index for a collection.
int mysqlx_collection_create_with_options(mysqlx_schema_t *schema, const char *collection, mysqlx_collection_options_t *options)
Create a new collection in a specified schema.
int mysqlx_collection_drop_index(mysqlx_collection_t *coll, const char *name)
Drop index on a collection.
int mysqlx_schema_create(mysqlx_session_t *sess, const char *schema)
Create a schema.
int mysqlx_collection_create(mysqlx_schema_t *schema, const char *collection)
Create a new collection in a specified schema.
int mysqlx_collection_drop(mysqlx_schema_t *schema, const char *collection)
Drop an existing collection in a specified schema.
mysqlx_error_t * mysqlx_error(void *obj)
Get the last error from the object.
unsigned int mysqlx_result_warning_count(mysqlx_result_t *res)
Get the number of warnings generated by a statement.
mysqlx_error_t * mysqlx_result_next_warning(mysqlx_result_t *res)
Get the next warning from the result.
const char * mysqlx_error_message(void *obj)
Get the error message from the object.
unsigned int mysqlx_error_num(void *obj)
Get the error number from the object.
const char * mysqlx_column_get_schema(mysqlx_result_t *res, uint32_t pos)
Get column's schema name.
const char * mysqlx_column_get_original_table(mysqlx_result_t *res, uint32_t pos)
Get column's original table name.
const char * mysqlx_column_get_name(mysqlx_result_t *res, uint32_t pos)
Get column name.
uint32_t mysqlx_column_get_length(mysqlx_result_t *res, uint32_t pos)
Get column length.
uint32_t mysqlx_column_get_count(mysqlx_result_t *res)
Get the number of columns in the result.
const char * mysqlx_column_get_original_name(mysqlx_result_t *res, uint32_t pos)
Get column original name.
const char * mysqlx_column_get_table(mysqlx_result_t *res, uint32_t pos)
Get column's table name.
uint16_t mysqlx_column_get_collation(mysqlx_result_t *res, uint32_t pos)
Get column collation number.
const char * mysqlx_column_get_catalog(mysqlx_result_t *res, uint32_t pos)
Get column's catalog name.
uint16_t mysqlx_column_get_precision(mysqlx_result_t *res, uint32_t pos)
Get column precision.
uint16_t mysqlx_column_get_type(mysqlx_result_t *res, uint32_t pos)
Get column type identifier.
const char * mysqlx_fetch_generated_id(mysqlx_result_t *result)
Get identifiers of the documents added to the collection.
uint64_t mysqlx_get_affected_count(mysqlx_result_t *res)
Get number of rows affected by a statement.
int mysqlx_store_result(mysqlx_result_t *result, size_t *num)
Store result data in an internal buffer.
int mysqlx_get_float(mysqlx_row_t *row, uint32_t col, float *val)
Get a float number from a row.
int mysqlx_get_uint(mysqlx_row_t *row, uint32_t col, uint64_t *val)
Get an unsigned integer number from a row.
mysqlx_row_t * mysqlx_row_fetch_one(mysqlx_result_t *res)
Fetch one row from the result.
const char * mysqlx_json_fetch_one(mysqlx_result_t *res, size_t *out_length)
Fetch one document as a JSON string.
int mysqlx_get_bytes(mysqlx_row_t *row, uint32_t col, uint64_t offset, void *buf, size_t *buf_len)
Read bytes stored in a row into a pre-allocated buffer.
int mysqlx_get_double(mysqlx_row_t *row, uint32_t col, double *val)
Get a double number from a row.
int mysqlx_get_count(mysqlx_result_t *result, size_t *num)
Function for getting the number of remaining cached items in a result.
int mysqlx_next_result(mysqlx_result_t *res)
Proceed to the next result set in the reply.
int mysqlx_get_sint(mysqlx_row_t *row, uint32_t col, int64_t *val)
Get a signed integer number from a row.
void mysqlx_result_free(mysqlx_result_t *res)
Free the result explicitly.
uint64_t mysqlx_get_auto_increment_value(mysqlx_result_t *res)
Get auto increment value generated by a statement that inserts rows into a table with auto increment ...
mysqlx_session_options_t * mysqlx_session_options_new()
Allocate a new session configuration data object.
mysqlx_client_t * mysqlx_get_client_from_url(const char *conn_string, const char *client_opts, mysqlx_error_t **error)
Create a client instance using connection string or URL and a client options JSON.
int mysqlx_session_option_set(mysqlx_session_options_t *opth,...)
Set session configuration options.
mysqlx_result_t * mysqlx_get_tables(mysqlx_schema_t *schema, const char *table_pattern, int get_views)
Get a list of tables and views in a schema.
int mysqlx_session_option_get(mysqlx_session_options_t *opth, int opt,...)
Read session configuration options.
mysqlx_session_t * mysqlx_get_session_from_url(const char *conn_string, mysqlx_error_t **error)
Create a session using connection string or URL.
mysqlx_result_t * mysqlx_get_schemas(mysqlx_session_t *sess, const char *schema_pattern)
Get a list of schemas.
void mysqlx_free_options(mysqlx_session_options_t *opt)
Free a session configuration data object.
int mysqlx_transaction_begin(mysqlx_session_t *sess)
Begin a transaction for the session.
int mysqlx_rollback_to(mysqlx_session_t *sess, const char *name)
Roll back to savepoint created by mysqlx_savepoint_set().
mysqlx_collection_t * mysqlx_get_collection(mysqlx_schema_t *schema, const char *col_name, unsigned int check)
Get a collection object and optionally check if it exists in the schema.
void mysqlx_session_close(mysqlx_session_t *session)
Close the session.
mysqlx_session_t * mysqlx_get_session(const char *host, int port, const char *user, const char *password, const char *database, mysqlx_error_t **error)
Create a new session.
int mysqlx_savepoint_release(mysqlx_session_t *sess, const char *name)
Release savepoint created by mysqlx_savepoint_set().
mysqlx_schema_t * mysqlx_get_schema(mysqlx_session_t *sess, const char *schema_name, unsigned int check)
Get a schema object and optionally check if it exists on the server.
void mysqlx_client_close(mysqlx_client_t *client)
Close the client pool and all sessions created by them.
mysqlx_result_t * mysqlx_get_collections(mysqlx_schema_t *schema, const char *col_pattern)
Get a list of collections in a schema.
int mysqlx_transaction_commit(mysqlx_session_t *sess)
Commit a transaction for the session.
mysqlx_client_t * mysqlx_get_client_from_options(mysqlx_session_options_t *opt, mysqlx_error_t **error)
Create a client pool using session configuration data.
int mysqlx_session_valid(mysqlx_session_t *sess)
Check the session validity.
const char * mysqlx_savepoint_set(mysqlx_session_t *sess, const char *name)
Create savepoint inside transaction.
mysqlx_table_t * mysqlx_get_table(mysqlx_schema_t *schema, const char *tab_name, unsigned int check)
Get a table object and optionally check if it exists in the schema.
mysqlx_session_t * mysqlx_get_session_from_options(mysqlx_session_options_t *opt, mysqlx_error_t **error)
Create a session using session configuration data.
int mysqlx_transaction_rollback(mysqlx_session_t *sess)
Roll back a transaction for the session.
mysqlx_result_t * mysqlx_sql(mysqlx_session_t *sess, const char *query, size_t query_len)
Execute a plain SQL query.
mysqlx_stmt_t * mysqlx_sql_new(mysqlx_session_t *sess, const char *query, uint32_t length)
Create a statement which executes a plain SQL query.
mysqlx_result_t * mysqlx_sql_param(mysqlx_session_t *sess, const char *query, size_t query_len,...)
Execute a plain SQL query with parameters.
int mysqlx_set_order_by(mysqlx_stmt_t *stmt,...)
Specify ordering for a statement.
mysqlx_result_t * mysqlx_execute(mysqlx_stmt_t *stmt)
Execute a statement.
int mysqlx_set_row_locking(mysqlx_stmt_t *stmt, int locking, int contention)
Set row locking mode for a statement.
int mysqlx_set_limit_and_offset(mysqlx_stmt_t *stmt, uint64_t row_count, uint64_t offset)
Set limit and offset information for a statement.
int mysqlx_stmt_bind(mysqlx_stmt_t *stmt,...)
Bind values for parametrized statements.
int mysqlx_set_having(mysqlx_stmt_t *stmt, const char *having_expr)
Specify filter conditions for a group of rows/documents or aggregates such as GROUP BY.
int mysqlx_set_insert_row(mysqlx_stmt_t *stmt,...)
Specify a row to be added by an INSERT statement.
int mysqlx_set_group_by(mysqlx_stmt_t *stmt,...)
Specify one or more columns/values to group the result in conjunction with the aggregate functions.
int mysqlx_set_items(mysqlx_stmt_t *stmt,...)
Specify a table query projection.
void mysqlx_free(void *obj)
Free the allocated handle explicitly.
int mysqlx_set_where(mysqlx_stmt_t *stmt, const char *where_expr)
Specify selection criteria for a statement.
mysqlx_stmt_t * mysqlx_table_delete_new(mysqlx_table_t *table)
Create a statement executing a table DELETE operation.
mysqlx_result_t * mysqlx_table_insert(mysqlx_table_t *table,...)
Execute a table INSERT statement with one row.
int mysqlx_set_insert_columns(mysqlx_stmt_t *stmt,...)
Specify column names for an INSERT statement.
mysqlx_result_t * mysqlx_table_delete(mysqlx_table_t *table, const char *criteria)
Execute a table DELETE statement with a WHERE clause.
mysqlx_stmt_t * mysqlx_table_update_new(mysqlx_table_t *table)
Create a statement executing a table UPDATE operation.
mysqlx_result_t * mysqlx_table_select(mysqlx_table_t *table, const char *criteria)
Execute a table SELECT statement with a WHERE clause.
mysqlx_stmt_t * mysqlx_table_select_new(mysqlx_table_t *table)
Create a statement which performs a table SELECT operation.
mysqlx_result_t * mysqlx_table_select_limit(mysqlx_table_t *table, const char *criteria, uint64_t row_count, uint64_t offset,...)
Execute a table SELECT statement with a WHERE, ORDER BY and LIMIT clauses.
mysqlx_stmt_t * mysqlx_table_insert_new(mysqlx_table_t *table)
Create a statement executing a table INSERT operation.
mysqlx_result_t * mysqlx_table_update(mysqlx_table_t *table, const char *criteria,...)
Execute a table UPDATE statement.
int mysqlx_set_update_values(mysqlx_stmt_t *stmt,...)
Set values for the columns in the UPDATE statement.
mysqlx_opt_type_t
Session options for use with mysqlx_session_option_get() and mysqlx_session_option_set() functions.
Definition: xapi.h:398
mysqlx_client_opt_type_t
Client options for use with mysqlx_session_option_get() and mysqlx_session_option_set() functions.
Definition: xapi.h:369
mysqlx_collection_validation_level_t
Collection validation level options .
Definition: xapi.h:498
mysqlx_lock_contention_t
Constants for defining the row locking options for mysqlx_set_row_locking() function.
Definition: xapi.h:544
struct mysqlx_result_struct mysqlx_result_t
Type of result handles.
Definition: xapi.h:301
mysqlx_collection_validation_opt_t
Collection validation options.
Definition: xapi.h:484
mysqlx_session_t * mysqlx_get_session_from_client(mysqlx_client_t *cli, mysqlx_error_t **error)
Create a new session.
struct mysqlx_row_struct mysqlx_row_t
Type of row handles.
Definition: xapi.h:288
mysqlx_collection_opt_t
Collection create/modify options.
Definition: xapi.h:469
struct mysqlx_stmt_struct mysqlx_stmt_t
Type of statement handles.
Definition: xapi.h:277
struct mysqlx_session_options_struct mysqlx_session_options_t
Type of handles for session configuration data.
Definition: xapi.h:227
struct mysqlx_session_struct mysqlx_session_t
Type of session handles.
Definition: xapi.h:205
mysqlx_data_type_t
The data type identifiers used in MYSQLX API.
Definition: xapi.h:309
struct mysqlx_client_struct mysqlx_client_t
Type of client handles.
Definition: xapi.h:213
struct mysqlx_collection_struct mysqlx_collection_t
Type of collection handles.
Definition: xapi.h:253
mysqlx_auth_method_t
Authentication method values for use with mysqlx_session_option_get() and mysqlx_session_option_set()...
Definition: xapi.h:456
mysqlx_compression_mode_t
Compression modes.
Definition: xapi.h:519
struct mysqlx_error_struct mysqlx_error_t
Type of error handles.
Definition: xapi.h:196
mysqlx_ssl_mode_t
Session SSL mode values for use with mysqlx_session_option_get() and mysqlx_session_option_set() func...
Definition: xapi.h:443
mysqlx_row_locking_t
Constants for defining the row locking options for mysqlx_set_row_locking() function.
Definition: xapi.h:531
struct mysqlx_schema_struct mysqlx_schema_t
Type of database schema handles.
Definition: xapi.h:244
struct mysqlx_collection_options_struct mysqlx_collection_options_t
Type of handles for collection create/modify options.
Definition: xapi.h:236
struct mysqlx_table_struct mysqlx_table_t
Type of table handles.
Definition: xapi.h:261
mysqlx_sort_direction_t
Sort directions in sorting operations such as ORDER BY.
Definition: xapi.h:353
@ MYSQLX_TYPE_DECIMAL
Decimal type.
Definition: xapi.h:323
@ MYSQLX_TYPE_BOOL
Bool type.
Definition: xapi.h:326
@ MYSQLX_TYPE_BIT
Bit type.
Definition: xapi.h:322
@ MYSQLX_TYPE_SINT
64-bit signed integer number type
Definition: xapi.h:313
@ MYSQLX_TYPE_TIME
Time type.
Definition: xapi.h:318
@ MYSQLX_TYPE_EXPR
Expression type.
Definition: xapi.h:333
@ MYSQLX_TYPE_FLOAT
Floating point float number type.
Definition: xapi.h:316
@ MYSQLX_TYPE_STRING
String type.
Definition: xapi.h:328
@ MYSQLX_TYPE_UINT
64-bit unsigned integer number type
Definition: xapi.h:314
@ MYSQLX_TYPE_DOUBLE
Floating point double number type.
Definition: xapi.h:315
@ MYSQLX_TYPE_ENUM
Enum type.
Definition: xapi.h:321
@ MYSQLX_TYPE_NULL
NULL value.
Definition: xapi.h:332
@ MYSQLX_TYPE_BYTES
Bytes array type.
Definition: xapi.h:317
@ MYSQLX_TYPE_GEOMETRY
Geometry type.
Definition: xapi.h:329
@ MYSQLX_TYPE_TIMESTAMP
Timestamp type.
Definition: xapi.h:330
@ MYSQLX_TYPE_SET
Set type.
Definition: xapi.h:320
@ MYSQLX_TYPE_DATETIME
Datetime type.
Definition: xapi.h:319
@ MYSQLX_TYPE_JSON
JSON type.
Definition: xapi.h:327
@ ROW_LOCK_NONE
No locking.
Definition: xapi.h:534
@ SORT_ORDER_ASC
Ascending sorting (Default)
Definition: xapi.h:354
@ SORT_ORDER_DESC
Descending sorting.
Definition: xapi.h:355