xapi.h 93 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169
  1. /*
  2. * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
  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 also distributed with certain software (including
  9. * but not limited to OpenSSL) that is licensed under separate terms,
  10. * as designated in a particular file or component or in included license
  11. * documentation. The authors of MySQL hereby grant you an
  12. * additional permission to link the program and your derivative works
  13. * with the separately licensed software that they have included with
  14. * MySQL.
  15. *
  16. * Without limiting anything contained in the foregoing, this file,
  17. * which is part of MySQL Connector/C++, is also subject to the
  18. * Universal FOSS Exception, version 1.0, a copy of which can be found at
  19. * http://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. /**
  31. @defgroup xapi X DevAPI for C
  32. Functions and types defined by X DevAPI for C. See @ref xapi_ref for introduction.
  33. @{
  34. @defgroup xapi_sess Session operations
  35. @defgroup xapi_coll Statements operating on document collections
  36. @defgroup xapi_tbl Statements operating on tables
  37. @defgroup xapi_sql SQL execution
  38. @defgroup xapi_ddl DDL statements
  39. @note To create a table or a view, use reqular SQL statement.
  40. @defgroup xapi_stmt Statement execution
  41. @defgroup xapi_res Result processing
  42. @defgroup xapi_md Meta data access
  43. @defgroup xapi_diag Diganostics
  44. @}
  45. */
  46. /**
  47. @file
  48. The main header for MySQL Connector/C++ X DevAPI for C.
  49. This header should be included by C and C++ code which uses the X DevAPI
  50. for C implemented by MySQL Connector/C++
  51. @ingroup xapi
  52. */
  53. #ifndef MYSQL_XAPI_H
  54. #define MYSQL_XAPI_H
  55. #ifdef __cplusplus
  56. extern "C" {
  57. #endif
  58. #include "common_constants.h"
  59. #include "common/api.h"
  60. #include <stdlib.h>
  61. #include <stdint.h>
  62. /**
  63. @addtogroup xapi
  64. @{
  65. */
  66. // FIXME
  67. #define STDCALL
  68. ///////////////////// COMMON TYPE DECLARATIONS, REMOVE LATER
  69. #ifndef __cplusplus
  70. typedef unsigned char bool;
  71. #endif
  72. typedef char object_id[16];
  73. typedef object_id* MYSQLX_GUID;
  74. /** Return value indicating function/operation success. */
  75. #define RESULT_OK 0
  76. /**
  77. Return value flag indicating that the last reading operation
  78. did not finish reading to the end and there is still more data
  79. to be fetched by functions such as mysqlx_get_bytes()
  80. */
  81. #define RESULT_MORE_DATA 8
  82. /**
  83. Return value flag indicating end of data items (documents or
  84. rows) in a query result. This is used by functions which iterate
  85. over result data.
  86. */
  87. #define RESULT_NULL 16
  88. /**
  89. Return value flag indicating that operation generated
  90. information diagnostic entries.
  91. */
  92. #define RESULT_INFO 32
  93. /** Return value flag indicating that operation generated warnings. */
  94. #define RESULT_WARNING 64
  95. /** Return value flag indicating function/operation error. */
  96. #define RESULT_ERROR 128
  97. #define MYSQLX_MAX_ERROR_LEN 255
  98. #define MYSQLX_NULL_TERMINATED 0xFFFFFFFF
  99. #define MYSQLX_ERR_UNKNOWN 0xFFFF
  100. #define MYSQLX_COLLATION_UNDEFINED 0
  101. /*
  102. Error codes
  103. */
  104. #define MYSQLX_ERROR_INDEX_OUT_OF_RANGE 1
  105. /*
  106. Error messages
  107. */
  108. #define MYSQLX_ERROR_INDEX_OUT_OF_RANGE_MSG "Index is out of range"
  109. #define MYSQLX_ERROR_MISSING_SCHEMA_NAME_MSG "Missing schema name"
  110. #define MYSQLX_ERROR_MISSING_TABLE_NAME_MSG "Missing table name"
  111. #define MYSQLX_ERROR_MISSING_VIEW_NAME_MSG "Missing view name"
  112. #define MYSQLX_ERROR_MISSING_COLLECTION_NAME_MSG "Missing collection name"
  113. #define MYSQLX_ERROR_MISSING_VIEW_NAME_MSG "Missing view name"
  114. #define MYSQLX_ERROR_MISSING_KEY_NAME_MSG "Missing key name"
  115. #define MYSQLX_ERROR_MISSING_HOST_NAME "Missing host name"
  116. #define MYSQLX_ERROR_MISSING_SOCKET_NAME "Missing socket name"
  117. #define MYSQLX_ERROR_MISSING_CONN_INFO "Missing connecting information"
  118. #define MYSQLX_ERROR_HANDLE_NULL_MSG "Handle cannot be NULL"
  119. #define MYSQLX_ERROR_VIEW_INVALID_STMT_TYPE "Invalid statement type for View. Only SELECT type is supported"
  120. #define MYSQLX_ERROR_VIEW_TYPE_MSG "Statement must be of VIEW type"
  121. #define MYSQLX_ERROR_OUTPUT_BUFFER_NULL "The output buffer cannot be NULL"
  122. #define MYSQLX_ERROR_OUTPUT_BUFFER_ZERO "The output buffer cannot have zero length"
  123. #define MYSQLX_ERROR_OP_NOT_SUPPORTED "The operation is not supported by the function"
  124. #define MYSQLX_ERROR_WRONG_SSL_MODE "Wrong value for SSL Mode"
  125. #define MYSQLX_ERROR_NO_TLS_SUPPORT "Can not create TLS session - this connector is built without TLS support"
  126. #define MYSQLX_ERROR_MIX_PRIORITY "Mixing hosts with and without priority is not allowed"
  127. #define MYSQLX_ERROR_DUPLICATED_OPTION "Option already defined"
  128. #define MYSQLX_ERROR_MAX_PRIORITY "Priority should be a value between 0 and 100"
  129. #define MYSQLX_ERROR_AUTH_METHOD "Unknown authentication method"
  130. #define MYSQLX_ERROR_ROW_LOCKING "Row locking is supported only for SELECT and FIND"
  131. #define MYSQLX_ERROR_WRONG_LOCKING_MODE "Wrong value for the row locking mode"
  132. #define MYSQLX_ERROR_WRONG_EXPRESSION "Expression could not be parsed"
  133. #define MYSQLX_ERROR_EMPTY_JSON "Empty JSON document string"
  134. /* Opaque structures*/
  135. /**
  136. Type of error handles.
  137. Error handles give access to diagnostic information from the session
  138. and statement operations.
  139. @see mysqlx_error()
  140. */
  141. typedef struct mysqlx_error_struct mysqlx_error_t;
  142. /**
  143. Type of session handles.
  144. @see mysqlx_get_session()
  145. */
  146. typedef struct mysqlx_session_struct mysqlx_session_t;
  147. /**
  148. Type of client handles.
  149. @see mysqlx_get_client()
  150. */
  151. typedef struct mysqlx_client_struct mysqlx_client_t;
  152. /**
  153. Type of handles for session configuration data.
  154. Session can be created using previously prepared session configuration
  155. data. New configuration data is allocated by `mysqlx_session_options_new()`
  156. and can be manipulated using related functions.
  157. @see mysqlx_get_session_from_options(), mysqlx_session_options_new(),
  158. mysqlx_session_option_set(), mysqlx_free_options().
  159. */
  160. typedef struct mysqlx_session_options_struct mysqlx_session_options_t;
  161. /**
  162. Type of database schema handles.
  163. @see mysqlx_get_schema()
  164. */
  165. typedef struct mysqlx_schema_struct mysqlx_schema_t;
  166. /**
  167. Type of collection handles.
  168. @see mysqlx_get_collection()
  169. */
  170. typedef struct mysqlx_collection_struct mysqlx_collection_t;
  171. /**
  172. Type of table handles.
  173. @see mysqlx_get_table()
  174. */
  175. typedef struct mysqlx_table_struct mysqlx_table_t;
  176. /**
  177. Type of statement handles.
  178. Some X DevAPI for C functions create statements without executing them. These
  179. functions return a statement handle which can be used to define statement
  180. properties and then execute it.
  181. @see mysqlx_sql_new(), mysqlx_table_select_new(), mysqlx_table_insert_new(),
  182. mysqlx_table_update_new(), mysqlx_table_delete_new(),
  183. mysqlx_collection_find_new(), mysqlx_collection_modify_new(),
  184. mysqlx_collection_add_new(), mysqlx_collection_remove_new()
  185. */
  186. typedef struct mysqlx_stmt_struct mysqlx_stmt_t;
  187. /**
  188. Type of row handles.
  189. @see mysqlx_row_fetch_one()
  190. */
  191. typedef struct mysqlx_row_struct mysqlx_row_t;
  192. /**
  193. Type of result handles.
  194. Functions which produce results return a result handle which is
  195. then used to examine the result.
  196. @see mysqlx_execute(), mysqlx_store_result(), mysqlx_row_fetch_one(),
  197. mysqlx_json_fetch_one(), mysqlx_next_result())
  198. */
  199. typedef struct mysqlx_result_struct mysqlx_result_t;
  200. /**
  201. The data type identifiers used in MYSQLX API.
  202. */
  203. typedef enum mysqlx_data_type_enum
  204. {
  205. MYSQLX_TYPE_UNDEFINED = 0,
  206. /* Column types as defined in protobuf (mysqlx_resultset.proto)*/
  207. MYSQLX_TYPE_SINT = 1, /**< 64-bit signed integer number type*/
  208. MYSQLX_TYPE_UINT = 2, /**< 64-bit unsigned integer number type*/
  209. MYSQLX_TYPE_DOUBLE = 5, /**< Floating point double number type*/
  210. MYSQLX_TYPE_FLOAT = 6, /**< Floating point float number type*/
  211. MYSQLX_TYPE_BYTES = 7, /**< Bytes array type*/
  212. MYSQLX_TYPE_TIME = 10, /**< Time type*/
  213. MYSQLX_TYPE_DATETIME = 12,/**< Datetime type*/
  214. MYSQLX_TYPE_SET = 15, /**< Set type*/
  215. MYSQLX_TYPE_ENUM = 16,/**< Enum type*/
  216. MYSQLX_TYPE_BIT = 17, /**< Bit type*/
  217. MYSQLX_TYPE_DECIMAL = 18,/**< Decimal type*/
  218. /* Column types from DevAPI (no number constants assigned, just names)*/
  219. MYSQLX_TYPE_BOOL = 19,/**< Bool type*/
  220. MYSQLX_TYPE_JSON = 20,/**< JSON type*/
  221. MYSQLX_TYPE_STRING = 21,/**< String type*/
  222. MYSQLX_TYPE_GEOMETRY = 22,/**< Geometry type*/
  223. MYSQLX_TYPE_TIMESTAMP= 23,/**< Timestamp type*/
  224. MYSQLX_TYPE_NULL = 100, /**< NULL value*/
  225. MYSQLX_TYPE_EXPR = 101 /**< Expression type*/
  226. } mysqlx_data_type_t;
  227. #define PARAM_SINT(A) (void*)MYSQLX_TYPE_SINT, (int64_t)A
  228. #define PARAM_UINT(A) (void*)MYSQLX_TYPE_UINT, (uint64_t)A
  229. #define PARAM_FLOAT(A) (void*)MYSQLX_TYPE_FLOAT, (double)A
  230. #define PARAM_DOUBLE(A) (void*)MYSQLX_TYPE_DOUBLE, (double)A
  231. #define PARAM_BYTES(DATA, SIZE) (void*)MYSQLX_TYPE_BYTES, (void*)DATA, (size_t)SIZE
  232. #define PARAM_STRING(A) (void*)MYSQLX_TYPE_STRING, A
  233. #define PARAM_EXPR(A) (void*)MYSQLX_TYPE_EXPR, A
  234. #define PARAM_NULL() (void*)MYSQLX_TYPE_NULL
  235. #define PARAM_END (void*)0
  236. /**
  237. Sort directions in sorting operations such as ORDER BY.
  238. */
  239. typedef enum mysqlx_sort_direction_enum
  240. {
  241. SORT_ORDER_ASC = 1, /**< Ascending sorting (Default)*/
  242. SORT_ORDER_DESC = 2 /**< Descending sorting*/
  243. } mysqlx_sort_direction_t;
  244. #define PARAM_SORT_ASC(A) A, SORT_ORDER_ASC
  245. #define PARAM_SORT_DESC(A) A, SORT_ORDER_DESC
  246. /**
  247. Client options for use with `mysqlx_session_option_get()`
  248. and `mysqlx_session_option_set()` functions.
  249. */
  250. typedef enum mysqlx_client_opt_type_enum
  251. {
  252. #define XAPI_CLIENT_OPT_ENUM_str(X,N) MYSQLX_CLIENT_OPT_##X = -N,
  253. #define XAPI_CLIENT_OPT_ENUM_bool(X,N) MYSQLX_CLIENT_OPT_##X = -N,
  254. #define XAPI_CLIENT_OPT_ENUM_num(X,N) MYSQLX_CLIENT_OPT_##X = -N,
  255. #define XAPI_CLIENT_OPT_ENUM_any(X,N) MYSQLX_CLIENT_OPT_##X = -N,
  256. #define XAPI_CLIENT_OPT_ENUM_end(X,N) MYSQLX_CLIENT_OPT_##X = -N,
  257. CLIENT_OPTION_LIST(XAPI_CLIENT_OPT_ENUM)
  258. }
  259. mysqlx_client_opt_type_t;
  260. #define OPT_POOLING(A) MYSQLX_CLIENT_OPT_POOLING, (int)(bool)(A)
  261. #define OPT_POOL_MAX_SIZE(A) MYSQLX_CLIENT_OPT_POOL_MAX_SIZE, (uint64_t)(A)
  262. #define OPT_POOL_QUEUE_TIMEOUT(A) MYSQLX_CLIENT_OPT_POOL_QUEUE_TIMEOUT, (uint64_t)(A)
  263. #define OPT_POOL_MAX_IDLE_TIME(A) MYSQLX_CLIENT_OPT_POOL_MAX_IDLE_TIME, (uint64_t)(A)
  264. /**
  265. Session options for use with `mysqlx_session_option_get()`
  266. and `mysqlx_session_option_set()` functions.
  267. @note Specifying `MYSQLX_OPT_SSL_CA` option requires `MYSQLX_OPT_SSL_MODE`
  268. value of `SSL_MODE_VERIFY_CA` or `SSL_MODE_VERIFY_IDENTITY`.
  269. If `MYSQLX_OPT_SSL_MODE` is not explicitly given then setting
  270. `MYSQLX_OPT_SSL_CA` implies `SSL_MODE_VERIFY_CA`.
  271. */
  272. typedef enum mysqlx_opt_type_enum
  273. {
  274. #define XAPI_OPT_ENUM_str(X,N) MYSQLX_OPT_##X = N,
  275. #define XAPI_OPT_ENUM_num(X,N) MYSQLX_OPT_##X = N,
  276. #define XAPI_OPT_ENUM_any(X,N) MYSQLX_OPT_##X = N,
  277. SESSION_OPTION_LIST(XAPI_OPT_ENUM)
  278. MYSQLX_OPT_LAST
  279. }
  280. mysqlx_opt_type_t;
  281. #define OPT_HOST(A) MYSQLX_OPT_HOST, (A)
  282. #define OPT_PORT(A) MYSQLX_OPT_PORT, (unsigned int)(A)
  283. #ifndef _WIN32
  284. #define OPT_SOCKET(A) MYSQLX_OPT_SOCKET, (A)
  285. #endif //_WIN32
  286. #define OPT_USER(A) MYSQLX_OPT_USER, (A)
  287. #define OPT_PWD(A) MYSQLX_OPT_PWD, (A)
  288. #define OPT_DB(A) MYSQLX_OPT_DB, (A)
  289. #define OPT_SSL_MODE(A) MYSQLX_OPT_SSL_MODE, (A)
  290. #define OPT_SSL_CA(A) MYSQLX_OPT_SSL_CA, (A)
  291. #define OPT_PRIORITY(A) MYSQLX_OPT_PRIORITY, (unsigned int)(A)
  292. #define OPT_AUTH(A) MYSQLX_OPT_AUTH, (unsigned int)(A)
  293. #define OPT_CONNECT_TIMEOUT(A) MYSQLX_OPT_CONNECT_TIMEOUT, (unsigned int)(A)
  294. /**
  295. Session SSL mode values for use with `mysqlx_session_option_get()`
  296. and `mysqlx_session_option_set()` functions setting or getting
  297. MYSQLX_OPT_SSL_MODE option.
  298. */
  299. typedef enum mysqlx_ssl_mode_enum
  300. {
  301. #define XAPI_SSL_MODE_ENUM(X,N) SSL_MODE_##X = N,
  302. SSL_MODE_LIST(XAPI_SSL_MODE_ENUM)
  303. }
  304. mysqlx_ssl_mode_t;
  305. /**
  306. Authentication method values for use with `mysqlx_session_option_get()`
  307. and `mysqlx_session_option_set()` functions setting or getting
  308. MYSQLX_OPT_AUTH option.
  309. */
  310. typedef enum mysqlx_auth_method_enum
  311. {
  312. #define XAPI_AUTH_ENUM(X,N) MYSQLX_AUTH_##X = N,
  313. AUTH_METHOD_LIST(XAPI_AUTH_ENUM)
  314. }
  315. mysqlx_auth_method_t;
  316. /**
  317. Constants for defining the row locking options for
  318. mysqlx_set_row_locking() function.
  319. @see https://dev.mysql.com/doc/refman/8.0/en/innodb-locking-reads.html
  320. */
  321. typedef enum mysqlx_row_locking_enum
  322. {
  323. #define XAPI_ROW_LOCK_ENUM(X,N) ROW_LOCK_##X = N,
  324. ROW_LOCK_NONE = 0, /**< No locking */
  325. LOCK_MODE_LIST(XAPI_ROW_LOCK_ENUM)
  326. }
  327. mysqlx_row_locking_t;
  328. /**
  329. Constants for defining the row locking options for
  330. mysqlx_set_row_locking() function.
  331. @see https://dev.mysql.com/doc/refman/8.0/en/innodb-locking-reads.html#innodb-locking-reads-nowait-skip-locked
  332. */
  333. typedef enum mysqlx_lock_contention_enum
  334. {
  335. #define XAPI_LOCK_CONTENTION_ENUM(X,N) LOCK_CONTENTION_##X = N,
  336. LOCK_CONTENTION_LIST(XAPI_LOCK_CONTENTION_ENUM)
  337. }
  338. mysqlx_lock_contention_t;
  339. /*
  340. ====================================================================
  341. Client operations
  342. ====================================================================
  343. */
  344. /**
  345. Create a client instance using connection string or URL and a client options
  346. JSON.
  347. Connection sting has the form `"user:pass\@host:port/?option&option"`,
  348. valid URL is like a connection string with a `mysqlx://` prefix. Host is
  349. specified as either DNS name, IPv4 address of the form "nn.nn.nn.nn" or
  350. IPv6 address of the form "[nn:nn:nn:...]".
  351. Possible connection options are:
  352. - `ssl-enable` : use TLS connection
  353. - `ssl-ca=`path : path to a PEM file specifying trusted root certificates
  354. Specifying `ssl-ca` option implies `ssl-enable`.
  355. Client options are expressed in a JSON string format. Here is an example:
  356. ~~~~~~
  357. { "pooling": {
  358. "enabled": true,
  359. "maxSize": 25,
  360. "queueTimeout": 1000,
  361. "maxIdleTime": 5000}
  362. }
  363. ~~~~~~
  364. All options are defined under a document with key vale "pooling". Inside the
  365. document, the available options are these:
  366. - `enabled` : boolean value that enable or disable connection pooling. If
  367. disabled, session created from pool are the same as created
  368. directly without client handle.
  369. Enabled by default.
  370. - `mazSize` : integer that defines the max pooling sessions possible. If uses
  371. tries to get session from pool when maximum sessions are used,
  372. it will wait for an available session untill `queueTimeout`.
  373. Defaults to 25.
  374. - `queueTimeout` : integer value that defines the time, in milliseconds, that
  375. client will wait to get an available session.
  376. By default it doesn't timeouts.
  377. - `maxIdleTime` : integer value that defines the time, in milliseconds, that
  378. an available session will wait in the pool before it is
  379. removed.
  380. By default it doesn't cleans sessions.
  381. @param conn_string connection string
  382. @param client_opts client options in the form of a JSON string.
  383. @param[out] out_error if error happens during connect the error message
  384. is returned through this parameter
  385. @param[out] err_code if error happens during connect the error code
  386. is returned through this parameter
  387. @return client handle if client could be created, otherwise NULL
  388. is returned and the error information is returned through
  389. the out_error and err_code output parameters.
  390. @note The client returned by the function must be properly closed using
  391. `mysqlx_client_close()`.
  392. @ingroup xapi_sess
  393. */
  394. PUBLIC_API mysqlx_client_t *
  395. mysqlx_get_client_from_url(const char *conn_string, const char *client_opts,
  396. char out_error[MYSQLX_MAX_ERROR_LEN], int *err_code);
  397. /**
  398. Create a client pool using session configuration data.
  399. Client options are expressed in a JSON string format. Here is an example:
  400. ~~~~~~
  401. { "pooling": {
  402. "enabled": true,
  403. "maxSize": 25,
  404. "queueTimeout": 1000,
  405. "maxIdleTime": 5000}
  406. }
  407. ~~~~~~
  408. All options are defined under a document with key vale "pooling". Inside the
  409. document, the available options are these:
  410. - `enabled` : boolean value that enable or disable connection pooling. If
  411. disabled, session created from pool are the same as created
  412. directly without client handle.
  413. Enabled by default.
  414. - `mazSize` : integer that defines the max pooling sessions possible. If uses
  415. tries to get session from pool when maximum sessions are used,
  416. it will wait for an available session untill `queueTimeout`.
  417. Defaults to 25.
  418. - `queueTimeout` : integer value that defines the time, in milliseconds, that
  419. client will wait to get an available session.
  420. By default it doesn't timeouts.
  421. - `maxIdleTime` : integer value that defines the time, in milliseconds, that
  422. an available session will wait in the pool before it is
  423. removed.
  424. By default it doesn't cleans sessions.
  425. @param opt handle to client configuration data
  426. @param client_opts client options in the form of a JSON string.
  427. @param[out] out_error if error happens during connect the error message
  428. is returned through this parameter
  429. @param[out] err_code if error happens during connect the error code
  430. is returned through this parameter
  431. @return client handle if client could be created, otherwise NULL
  432. is returned and the error information is returned through
  433. the out_error and err_code output parameters.
  434. @note The client returned by the function must be properly closed using
  435. `mysqlx_client_close()`.
  436. @ingroup xapi_sess
  437. */
  438. PUBLIC_API mysqlx_client_t *
  439. mysqlx_get_client_from_options(mysqlx_session_options_t *opt,
  440. char out_error[MYSQLX_MAX_ERROR_LEN],
  441. int *err_code);
  442. /**
  443. Close the client pool and all sessions created by them.
  444. This function must be called by the user to prevent memory leaks.
  445. Closing client closes all sessions created by this client.\n
  446. Sessions created by this client are closed, but their resources are not freed.
  447. `mysqlx_session_close()` has to be called to prevent memory leaks.
  448. @param client client handle
  449. @ingroup xapi_sess
  450. */
  451. PUBLIC_API void mysqlx_client_close(mysqlx_client_t *client);
  452. /*
  453. ====================================================================
  454. Session operations
  455. ====================================================================
  456. */
  457. /**
  458. Create a new session
  459. @param client client pool to get session from
  460. @param[out] out_error if error happens during getting the session handle from
  461. the pool, the error message is returned through this
  462. parameter
  463. @param[out] err_code if error happens during getting the session handle from
  464. the pool, the error code is returned through this
  465. parameter
  466. */
  467. PUBLIC_API mysqlx_session_t *
  468. mysqlx_get_session_from_client(mysqlx_client_t *client,
  469. char out_error[MYSQLX_MAX_ERROR_LEN],
  470. int *err_code);
  471. /**
  472. Create a new session.
  473. @param host server host DNS name, IPv4 address or IPv6 address
  474. @param port port number
  475. @param user user name
  476. @param password password
  477. @param database default database name
  478. @param[out] out_error if error happens during connect the error message
  479. is returned through this parameter
  480. @param[out] err_code if error happens during connect the error code
  481. is returned through this parameter
  482. @return session handle if session could be created, otherwise NULL
  483. is returned and the error information is returned through
  484. the out_error and err_code output parameters.
  485. @note The session returned by the function must be properly closed using
  486. `mysqlx_session_close()`.
  487. @note This function always establishes connection with SSL enabled
  488. @ingroup xapi_sess
  489. */
  490. PUBLIC_API mysqlx_session_t *
  491. mysqlx_get_session(const char *host, int port, const char *user,
  492. const char *password, const char *database,
  493. char out_error[MYSQLX_MAX_ERROR_LEN], int *err_code);
  494. /**
  495. Create a session using connection string or URL.
  496. Connection sting has the form `"user:pass\@host:port/?option&option"`,
  497. valid URL is like a connection string with a `mysqlx://` prefix. Host is
  498. specified as either DNS name, IPv4 address of the form "nn.nn.nn.nn" or
  499. IPv6 address of the form "[nn:nn:nn:...]".
  500. Possible connection options are:
  501. - `ssl-enable` : use TLS connection
  502. - `ssl-ca=`path : path to a PEM file specifying trusted root certificates
  503. Specifying `ssl-ca` option implies `ssl-enable`.
  504. @param conn_string connection string
  505. @param[out] out_error if error happens during connect the error message
  506. is returned through this parameter
  507. @param[out] err_code if error happens during connect the error code
  508. is returned through this parameter
  509. @return session handle if session could be created, otherwise NULL
  510. is returned and the error information is returned through
  511. the out_error and err_code output parameters.
  512. @note The session returned by the function must be properly closed using
  513. `mysqlx_session_close()`.
  514. @ingroup xapi_sess
  515. */
  516. PUBLIC_API mysqlx_session_t *
  517. mysqlx_get_session_from_url(const char *conn_string,
  518. char out_error[MYSQLX_MAX_ERROR_LEN], int *err_code);
  519. /**
  520. Create a session using session configuration data.
  521. @param opt handle to session configuration data
  522. @param[out] out_error if error happens during connect the error message
  523. is returned through this parameter
  524. @param[out] err_code if error happens during connect the error code
  525. is returned through this parameter
  526. @return session handle if session could be created, otherwise NULL
  527. is returned and the error information is returned through
  528. the out_error and err_code output parameters.
  529. @note The session returned by the function must be properly closed using
  530. `mysqlx_session_close()`.
  531. @ingroup xapi_sess
  532. */
  533. PUBLIC_API mysqlx_session_t *
  534. mysqlx_get_session_from_options(mysqlx_session_options_t *opt,
  535. char out_error[MYSQLX_MAX_ERROR_LEN], int *err_code);
  536. /**
  537. Close the session.
  538. This function must be called by the user to prevent memory leaks.
  539. Closing session frees all related resources, including those
  540. allocated by statements and results belonging to the session.
  541. @param session session handle
  542. @ingroup xapi_sess
  543. */
  544. PUBLIC_API void mysqlx_session_close(mysqlx_session_t *session);
  545. /**
  546. Check the session validity.
  547. @param sess session handle
  548. @return 1 - if the session is valid, 0 - if the session is not valid
  549. @note The function checks only the internal session status without
  550. communicating with server(s).
  551. @ingroup xapi_sess
  552. */
  553. PUBLIC_API int mysqlx_session_valid(mysqlx_session_t *sess);
  554. /**
  555. Get a list of schemas.
  556. The result is returned as a set of rows with one column containing schema
  557. name. The rows can be read with functions such as `mysqlx_row_fetch_one()`,
  558. `mysqlx_store_result()` etc.
  559. @param sess session handle
  560. @param schema_pattern schema name pattern to search, using "%" as a wildcard
  561. character; if this parameter is NULL then all schemas will be
  562. returned.
  563. @return handle to the result with rows containing schema names.
  564. NULL is returned only in case of an error. The error details
  565. can be obtained using `mysqlx_error()` function
  566. @ingroup xapi_sess
  567. */
  568. PUBLIC_API mysqlx_result_t *
  569. mysqlx_get_schemas(mysqlx_session_t *sess, const char *schema_pattern);
  570. /**
  571. Get a schema object and optionally check if it exists on the server.
  572. @param sess session handle
  573. @param schema_name name of the schema
  574. @param check flag to verify if the schema with the given name
  575. exists on the server (1 - check, 0 - do not check)
  576. @return handle to the schema object or NULL
  577. if an error occurred or the schema does not exist on the server
  578. @note Performing existence check involves communication with server(s).
  579. Without the check, this operation is executed locally. It is then possible
  580. to create a handle to a non-existent schema. Attempt to use such
  581. a handle later would eventually trigger an error.
  582. @ingroup xapi_sess
  583. */
  584. PUBLIC_API mysqlx_schema_t *
  585. mysqlx_get_schema(mysqlx_session_t *sess, const char *schema_name,
  586. unsigned int check);
  587. /**
  588. Get a list of tables and views in a schema.
  589. The result is returned as a set of rows with two columns. The first column
  590. contains table/view name, the second column contains object type, either
  591. "TABLE" or "VIEW". The rows can be read with functions such as
  592. `mysqlx_row_fetch_one()`, `mysqlx_store_result()` etc.
  593. @param schema schema handle
  594. @param table_pattern table name pattern to search, using "%" as a wildcard
  595. character; if this parameter is NULL then all tables/views in the
  596. given schema will be returned.
  597. @param get_views flag specifying whether view names should be included
  598. into the result. 0 - do not show views (only table names are in
  599. the result), 1 - show views (table and view names are in the result)
  600. @return handle to the result with rows containing table/view names.
  601. NULL is returned only in case of an error. The error details
  602. can be obtained using `mysqlx_error()` function
  603. @note this function does not return names of tables that represent
  604. collections, use `mysqlx_get_collections()` function for getting
  605. collections.
  606. @ingroup xapi_sess
  607. */
  608. PUBLIC_API mysqlx_result_t *
  609. mysqlx_get_tables(mysqlx_schema_t *schema,
  610. const char *table_pattern,
  611. int get_views);
  612. /**
  613. Get a table object and optionally check if it exists in the schema
  614. @param schema schema handle
  615. @param tab_name name of the table
  616. @param check flag to verify if the table with the given name
  617. exists in the schema (1 - check, 0 - do not check)
  618. @return handle to the table or NULL
  619. if an error occurred or the table does not exist in the schema
  620. @note Performing existence check involves communication with server(s).
  621. Without the check, this operation is executed locally. It is then possible
  622. to create a handle to a non-existent table. Attempt to use such
  623. a handle later would eventually trigger an error.
  624. @ingroup xapi_sess
  625. */
  626. PUBLIC_API mysqlx_table_t *
  627. mysqlx_get_table(mysqlx_schema_t *schema, const char *tab_name,
  628. unsigned int check);
  629. /**
  630. Get a list of collections in a schema.
  631. The result is returned as a set of rows with two columns. The first column
  632. contains collection name and the second column contains string "COLLECTION".
  633. The rows can be read with functions such as `mysqlx_row_fetch_one()`,
  634. `mysqlx_store_result()` etc.
  635. @param schema handle
  636. @param col_pattern collection name pattern to search, using "%" as a wildcard
  637. character; if this parameter is NULL then all collections in the given
  638. schema will be returned.
  639. @return handle to the result with rows containing collection names.
  640. NULL is returned only in case of an error. The error details
  641. can be obtained using `mysqlx_error()` function
  642. @ingroup xapi_sess
  643. */
  644. PUBLIC_API mysqlx_result_t *
  645. mysqlx_get_collections(mysqlx_schema_t *schema,
  646. const char *col_pattern);
  647. /**
  648. Get a collection object and optionally check if it exists in the schema
  649. @param schema schema handle
  650. @param col_name name of the collection
  651. @param check flag to verify if the collection with the given name
  652. exists in the schema (1 - check, 0 - do not check)
  653. @return handle to the collection or NULL
  654. if an error occurred or the collection does not exist in the schema
  655. @note Performing existence check involves communication with server(s).
  656. Without the check, this operation is executed locally. It is then possible
  657. to create a handle to a non-existent collection. Attempt to use such
  658. a handle later would eventually trigger an error.
  659. @ingroup xapi_sess
  660. */
  661. PUBLIC_API mysqlx_collection_t *
  662. mysqlx_get_collection(mysqlx_schema_t *schema, const char *col_name,
  663. unsigned int check);
  664. /**
  665. Begin a transaction for the session.
  666. @param sess session handle
  667. @return `RESULT_OK` - on success; `RESULT_ERR` - on error
  668. @note a statement will belong to the transaction when
  669. it is actually executed after the transaction began (and before
  670. it is committed or rolled back) even if this statement
  671. was created before `mysqlx_transaction_begin()` call
  672. @ingroup xapi_sess
  673. */
  674. PUBLIC_API int
  675. mysqlx_transaction_begin(mysqlx_session_t *sess);
  676. /**
  677. Commit a transaction for the session.
  678. @param sess session handle
  679. @return `RESULT_OK` - on success; `RESULT_ERR` - on error
  680. @note This will commit all statements that were executed as part of this
  681. transaction, regardless of when the statements were created (see
  682. `mysqlx_transaction_begin()`).
  683. @ingroup xapi_sess
  684. */
  685. PUBLIC_API int
  686. mysqlx_transaction_commit(mysqlx_session_t *sess);
  687. /**
  688. Roll back a transaction for the session.
  689. @param sess session handle
  690. @return `RESULT_OK` - on success; `RESULT_ERR` - on error
  691. @note This will roll back all statements that were executed as part of this
  692. transaction, regardless of when the statements were created (see
  693. `mysqlx_transaction_begin()`).
  694. @ingroup xapi_sess
  695. */
  696. PUBLIC_API int
  697. mysqlx_transaction_rollback(mysqlx_session_t *sess);
  698. /**
  699. Create savepoint inside transaction.
  700. @param sess session handle.
  701. @param name savepoint name (NULL for automatically generated one)
  702. @return savepoint name
  703. @note Savepoints are created inside transaction! Later, you can roll back
  704. the transaction to a created savepoint using mysqlx_rollback_to().
  705. If the current transaction has a savepoint with the same name, the old
  706. savepoint is deleted and a new one is set.
  707. @ingroup xapi_sess
  708. */
  709. PUBLIC_API const char*
  710. mysqlx_savepoint_set( mysqlx_session_t *sess, const char *name);
  711. /**
  712. Release savepoint created by mysqlx_savepoint_set().
  713. @param sess session handle
  714. @param name savepoint name to be released
  715. @return `RESULT_OK` - savepoint exists and is released;
  716. `RESULT_ERR` - on error
  717. @ingroup xapi_sess
  718. */
  719. PUBLIC_API int
  720. mysqlx_savepoint_release(mysqlx_session_t *sess, const char *name);
  721. /**
  722. Roll back to savepoint created by mysqlx_savepoint_set().
  723. @param sess session handle.
  724. @param name savepoint name.
  725. @return `RESULT_OK` - savepoint exists and is released;
  726. `RESULT_ERR` - on error.
  727. @ingroup xapi_sess
  728. */
  729. PUBLIC_API int
  730. mysqlx_rollback_to( mysqlx_session_t *sess, const char *name);
  731. /**
  732. Allocate a new session configuration data object.
  733. @return handle to the newly allocated configuration data
  734. @note The allocated object must be eventually freed by
  735. `mysqlx_free_options()` to prevent memory leaks
  736. @ingroup xapi_sess
  737. */
  738. PUBLIC_API mysqlx_session_options_t * mysqlx_session_options_new();
  739. /**
  740. Free a session configuration data object.
  741. @param opt handle to sessin configuartion data object
  742. that has to be freed
  743. @ingroup xapi_sess
  744. */
  745. PUBLIC_API void mysqlx_free_options(mysqlx_session_options_t *opt);
  746. /**
  747. Set session configuration options.
  748. @param opt handle to session configuration data object
  749. @param ... variable parameters list consisting of (type, value) pairs
  750. terminated by `PARAM_END`: type_id1, value1, type_id2, value2, ...,
  751. type_id_n, value_n, `PARAM_END` (`PARAM_END` marks the end of
  752. the parameters list).
  753. type_id is the numeric identifier, which helps to determine the type
  754. of the value provided as the next parameter. The user code must
  755. ensure that type_id corresponds to the actual value type. Otherwise,
  756. the value along with and all sequential types and values are most
  757. likely to be corrupted.
  758. Allowed types are listed in `mysqlx_opt_type_t` enum.
  759. The X DevAPI for C defines the convenience macros that help to specify
  760. the types and values: See `OPT_HOST()`, `OPT_PORT()`, `OPT_USER()`,
  761. `OPT_PWD()`, `OPT_DB()`, `OPT_SSL_MODE()`, `OPT_SSL_CA()`,
  762. `OPT_PRIORITY()`.
  763. @return `RESULT_OK` if option was successfully set; `RESULT_ERROR`
  764. is set otherwise (use `mysqlx_error()` to get the error
  765. information)
  766. @ingroup xapi_sess
  767. */
  768. PUBLIC_API int
  769. mysqlx_session_option_set(mysqlx_session_options_t *opt, ...);
  770. /**
  771. Read session configuration options.
  772. @param opt handle to session configuration data object
  773. @param type option type to get (see `mysqlx_opt_type_t` enum)
  774. @param[out] ... pointer to a buffer where to return the requested
  775. value
  776. TODO: Point to documentation explaining what data is returned for
  777. each option.
  778. @return `RESULT_OK` if option was successfully read; `RESULT_ERROR`
  779. is set otherwise (use `mysqlx_error()` to get the error
  780. information)
  781. @note When reading string option values to a bufer, user is responsible for
  782. providing a large enough buffer. No overrun checks are done when
  783. copying data to the buffer.
  784. @note For failover configurations with multiple hosts this function
  785. will return only the last added host name. Same is true for the port
  786. or the priority associated with this host name.
  787. @ingroup xapi_sess
  788. */
  789. PUBLIC_API int
  790. mysqlx_session_option_get(mysqlx_session_options_t *opt, int type,
  791. ...);
  792. /*
  793. ====================================================================
  794. SQL execution
  795. ====================================================================
  796. */
  797. /**
  798. Execute a plain SQL query.
  799. @param sess session handle
  800. @param query SQL query
  801. @param query_len length of the query. For NULL-terminated query strings
  802. `MYSQLX_NULL_TERMINATED` can be specified instead of the
  803. actual length
  804. @return handle to the query results.
  805. NULL is returned only in case of an error. The error details
  806. can be obtained using `mysqlx_error()` function
  807. @ingroup xapi_sql
  808. */
  809. PUBLIC_API mysqlx_result_t * mysqlx_sql(mysqlx_session_t *sess,
  810. const char *query,
  811. size_t query_len);
  812. /**
  813. Execute a plain SQL query with parameters.
  814. @param sess session handle
  815. @param query SQL query
  816. @param query_len length of the query. For NULL-terminated query strings
  817. `MYSQLX_NULL_TERMINATED` can be specified instead of the
  818. actual length
  819. @param ... variable parameters list consisting of (type, value) pairs
  820. terminated by `PARAM_END`: type_id1, value1, type_id2, value2, ...,
  821. type_id_n, value_n, `PARAM_END` (`PARAM_END` marks the end of
  822. the parameters list).
  823. type_id is the numeric identifier, which helps to determine the type
  824. of the value provided as the next parameter. The user code must
  825. ensure that type_id corresponds to the actual value type. Otherwise,
  826. the value along with and all sequential types and values are most
  827. likely to be corrupted.
  828. Allowed types are listed in `mysqlx_data_type_t` enum.
  829. The X DevAPI for C defines the convenience macros that help to specify
  830. the types and values: See `PARAM_SINT()`, `PARAM_UINT()`,
  831. `PARAM_FLOAT()`, `PARAM_DOUBLE()`, `PARAM_BYTES()`,
  832. `PARAM_STRING()`.
  833. @return handle to the query results.
  834. NULL is returned only in case of an error. The error details
  835. can be obtained using `mysqlx_error()` function
  836. @ingroup xapi_sql
  837. */
  838. PUBLIC_API mysqlx_result_t * mysqlx_sql_param(mysqlx_session_t *sess,
  839. const char *query,
  840. size_t query_len, ...);
  841. /**
  842. Create a statement which executes a plain SQL query.
  843. @note The query can contain `?` placeholders whose values should be
  844. specified using `mysqlx_stmt_bind()` function before executing
  845. the statement.
  846. @param sess session handle
  847. @param query SQL query
  848. @param length length of the query
  849. @return statement handle containing the results and/or error.
  850. NULL can be returned only in case when there are problems
  851. allocating memory, which normally should not happen.
  852. It is very unlikely for this function to end with an error
  853. because it does not do any parsing, parameter checking etc.
  854. @note To actually execute the SQL query the returned statement has to be
  855. given to `mysqlx_execute()`.
  856. @see mysqlx_stmt_bind()
  857. @ingroup xapi_sql
  858. */
  859. PUBLIC_API mysqlx_stmt_t *
  860. mysqlx_sql_new(mysqlx_session_t *sess, const char *query,
  861. uint32_t length);
  862. /*
  863. ====================================================================
  864. Collection operations
  865. ====================================================================
  866. */
  867. /**
  868. Execute a collection FIND statement with a specific find
  869. criteria.
  870. @param collection collection handle
  871. @param criteria criteria for finding documents; if this parameter is
  872. NULL then all documents are returned
  873. @return handle to the query results.
  874. NULL is returned only in case of an error. The error details
  875. can be obtained using `mysqlx_error()` function
  876. @ingroup xapi_coll
  877. */
  878. PUBLIC_API mysqlx_result_t *
  879. mysqlx_collection_find(mysqlx_collection_t *collection, const char *criteria);
  880. /**
  881. Add a set of new documents to a collection.
  882. Each document is defined by a JSON string like
  883. "{ \"key_1\\": value_1, ..., \"key_N\\": value_N }"
  884. @param collection collection handle
  885. @param ... list of parameters containing the character JSON strings
  886. describing documents to be added. Each parameter
  887. is a separate document. The list has to be terminated by
  888. PARAM_END macro
  889. @return handle to the statement result.
  890. NULL is returned only in case of an error. The error details
  891. can be obtained using `mysqlx_error()` function
  892. Each document must have a unique identifier which is stored in `_id`
  893. field of the document. Document identifiers are character strings no longer
  894. than 32 characters. If added document does not have `_id` field, a unique
  895. identifier will be generated for it. Document identifier generated by given
  896. collection add operation can be examined using `mysqlx_fetch_generated_id()`
  897. function. Generated document identifiers are strings of 32 hexadecimal digits,
  898. like this one `0512020981044082E6119DFA0E4C0584`.
  899. @note Generated document identifiers are based on UUIDs but they are not
  900. valid UUIDs (fields are reversed).
  901. @see `mysqlx_collection_add_new()`
  902. @ingroup xapi_coll
  903. */
  904. PUBLIC_API mysqlx_result_t *
  905. mysqlx_collection_add(mysqlx_collection_t *collection, ...);
  906. /**
  907. Remove documents from a collection.
  908. @param collection collection handle
  909. @param criteria criteria selecting documents to be removed; if this parameter
  910. is NULL, all documents are removed
  911. @return handle to the statement result.
  912. NULL is returned only in case of an error. The error details
  913. can be obtained using `mysqlx_error()` function
  914. @ingroup xapi_coll
  915. */
  916. PUBLIC_API mysqlx_result_t *
  917. mysqlx_collection_remove(mysqlx_collection_t *collection, const char*criteria);
  918. /**
  919. Modify documents in the collection.
  920. @param collection collection handle
  921. @param criteria criteria selecting documents to be modified; if this
  922. parameter is NULL then all documents are modified
  923. @param ... list of parameters that come as triplets
  924. <field_path, value_type, value>
  925. Each triplet specifies a field inside a document that should
  926. be modified (field_path) and the new value for that field.
  927. The value_type is the type identifier
  928. for the data type of value (see `mysqlx_data_type_t` enum)
  929. The list is terminated by `PARAM_END`.
  930. For `MYSQLX_TYPE_BYTES` there will be one extra parameter specifying
  931. the length of the binary data:
  932. <field_path, MYSQLX_TYPE_BYTES, value, length>
  933. The X DevAPI for C defines the convenience macros that help to specify
  934. the types and values: See `PARAM_SINT()`, `PARAM_UINT()`,
  935. `PARAM_FLOAT()`, `PARAM_DOUBLE()`, `PARAM_BYTES()`,
  936. `PARAM_STRING()`, `PARAM_EXPR()`:
  937. ..., "a_key", PARAM_STRING("New Text Value"),
  938. "b_key", PARAM_EXPR("b_key-1000"),
  939. PARAM_END
  940. @return handle to the statement result
  941. NULL is returned only in case of an error. The error details
  942. can be obtained using `mysqlx_error()` function
  943. @ingroup xapi_coll
  944. */
  945. PUBLIC_API mysqlx_result_t *
  946. mysqlx_collection_modify_set(mysqlx_collection_t *collection,
  947. const char *criteria, ...);
  948. /**
  949. Unset fields in documents from the collection.
  950. @param collection collection handle
  951. @param criteria criteria selecting documents to be modified; if this
  952. parameter is NULL then all documents are modified
  953. @param ... list of field paths that should be unset;
  954. The list end is marked using `PARAM_END`
  955. @return handle to the statement result.
  956. NULL is returned only in case of an error. The error details
  957. can be obtained using `mysqlx_error()` function
  958. @ingroup xapi_coll
  959. */
  960. PUBLIC_API mysqlx_result_t *
  961. mysqlx_collection_modify_unset(mysqlx_collection_t *collection,
  962. const char *criteria, ...);
  963. /**
  964. Apply a given patch to documents in a collection.
  965. @param collection collection handle
  966. @param criteria criteria selecting documents to be modified; if this
  967. parameter is NULL then all documents are modified
  968. @param patch_spec patch specification given as a character string and
  969. interpreted like a JSON documents, but values of fields are
  970. interpreted as expressions
  971. @return handle to the statement result.
  972. NULL is returned only in case of an error. The error details
  973. can be obtained using `mysqlx_error()` function
  974. @ingroup xapi_coll
  975. */
  976. PUBLIC_API mysqlx_result_t *
  977. mysqlx_collection_modify_patch(mysqlx_collection_t *collection,
  978. const char *criteria,
  979. const char *patch_spec);
  980. /**
  981. Set a given patch for a modify statement to be applied to
  982. documents in a collection after executing the statement.
  983. @param stmt modify statement
  984. @param patch_spec patch specification given as a character string and
  985. interpreted like a JSON documents, but values of fields are
  986. interpreted as expressions
  987. @return `RESULT_OK` - on success; `RESULT_ERR` - on error
  988. @ingroup xapi_coll
  989. */
  990. PUBLIC_API int
  991. mysqlx_set_modify_patch(mysqlx_stmt_t *stmt,
  992. const char *patch_spec);
  993. /*
  994. Deferred statement execution
  995. ----------------------------
  996. */
  997. /**
  998. Create a statement which finds documents in a collection
  999. @param collection collection handle
  1000. @return handle for the newly created FIND statement.
  1001. NULL can be returned only in case when there are problems
  1002. allocating memory, which normally should not happen.
  1003. It is very unlikely for this function to end with an error
  1004. because it does not do any parsing, parameter checking etc.
  1005. @note To actually execute the operation, use `mysqlx_execute()`.
  1006. @ingroup xapi_coll
  1007. */
  1008. PUBLIC_API mysqlx_stmt_t *
  1009. mysqlx_collection_find_new(mysqlx_collection_t *collection);
  1010. /**
  1011. Specify a projection for a collection find query
  1012. The projection, if present, specifies mapping from documents found by the
  1013. query to new documents returned in the final result.
  1014. @param stmt statement handle
  1015. @param proj projection specification describing JSON document projections as
  1016. "{ \"proj1\\": expr1, ..., \"projN\\": exprN }". Expressions used
  1017. in the projection can refer to fields in the original document
  1018. using `$.path.to.field` syntax.
  1019. @return `RESULT_OK` - on success; `RESULT_ERR` - on error
  1020. @note This function can be only called for the collection FIND statements
  1021. @see mysqlsx_collection_find_new()
  1022. @ingroup xapi_coll
  1023. */
  1024. PUBLIC_API int mysqlx_set_find_projection(mysqlx_stmt_t *stmt, const char *proj);
  1025. /**
  1026. A macro defining a function for setting criteria for FIND operation.
  1027. @see mysqlx_set_where()
  1028. @ingroup xapi_coll
  1029. */
  1030. #define mysqlx_set_find_criteria mysqlx_set_where
  1031. /*
  1032. A macro defining a function for setting HAVING for FIND operation.
  1033. @see mysqlx_set_having()
  1034. @ingroup xapi_tbl
  1035. */
  1036. #define mysqlx_set_find_having mysqlx_set_having
  1037. /**
  1038. A macro defining a function for setting GROUP BY for FIND operation.
  1039. @see mysqlx_set_group_by()
  1040. @ingroup xapi_tbl
  1041. */
  1042. #define mysqlx_set_find_group_by mysqlx_set_group_by
  1043. /**
  1044. A macro defining a function for setting LIMIT for DELETE operation.
  1045. @see mysqlx_set_limit_and_offset()
  1046. @ingroup xapi_coll
  1047. */
  1048. #define mysqlx_set_find_limit_and_offset(STMT, LIM, OFFS) mysqlx_set_limit_and_offset(STMT, LIM, OFFS)
  1049. /**
  1050. A macro defining a function for setting ORDER BY for SELECT operation.
  1051. @see mysqlx_set_order_by()
  1052. @ingroup xapi_coll
  1053. */
  1054. #define mysqlx_set_find_order_by mysqlx_set_order_by
  1055. /**
  1056. A macro defining a function for setting row locking mode
  1057. for FIND operation.
  1058. @see mysqlx_set_row_locking()
  1059. @ingroup xapi_coll
  1060. */
  1061. #define mysqlx_set_find_row_locking mysqlx_set_row_locking
  1062. /**
  1063. Create a statement which adds documents to a collection
  1064. @param collection collection handle
  1065. @return handle for the newly created ADD statement.
  1066. NULL can be returned only in case when there are problems
  1067. allocating memory, which normally should not happen.
  1068. It is very unlikely for this function to end with an error
  1069. because it does not do any parsing, parameter checking etc.
  1070. @note To actually execute the operation, use `mysqlx_execute()` after
  1071. specifying documents to be added.
  1072. @ingroup xapi_coll
  1073. */
  1074. PUBLIC_API mysqlx_stmt_t *
  1075. mysqlx_collection_add_new(mysqlx_collection_t *collection);
  1076. /**
  1077. Specify a document to be added to a collection.
  1078. The function provides the document data for the ADD statement as
  1079. a JSON string like "{ \"key_1\\": value_1, ..., \"key_N\\": value_N }"
  1080. User code must ensure the validity of the document because it is
  1081. not checked until receiving the query on the server side.
  1082. @note key names and string values in a JSON string must be given
  1083. in quotes and such quotes need to be escaped.
  1084. @param stmt statement handle
  1085. @param json_doc - the JSON string describing document to add
  1086. @return `RESULT_OK` - on success; `RESULT_ERR` - on error
  1087. @note Each new call provides the values for the new document, which
  1088. can be used for multi-document add operations.
  1089. @note User can provide document id as a value of `_id` field, otherwise
  1090. document id is generated by the add operation. Document id must be
  1091. a string - setting `_id` to a non-string value triggers
  1092. an error.
  1093. @ingroup xapi_coll
  1094. */
  1095. PUBLIC_API int
  1096. mysqlx_set_add_document(mysqlx_stmt_t *stmt, const char *json_doc);
  1097. /**
  1098. Create a statement which removes documents from a collection.
  1099. @param collection collection handle
  1100. @return handle for the newly created REMOVE statement.
  1101. NULL can be returned only in case when there are problems
  1102. allocating memory, which normally should not happen.
  1103. It is very unlikely for this function to end with an error
  1104. because it does not do any parsing, parameter checking etc.
  1105. @note To actually execute the statement, use `mysqlx_execute()`
  1106. @ingroup xapi_coll
  1107. */
  1108. PUBLIC_API mysqlx_stmt_t *
  1109. mysqlx_collection_remove_new(mysqlx_collection_t *collection);
  1110. /**
  1111. A macro defining a function for setting WHERE for REMOVE operation.
  1112. @see mysqlx_set_where()
  1113. @ingroup xapi_coll
  1114. */
  1115. #define mysqlx_set_remove_criteria mysqlx_set_where
  1116. /**
  1117. A macro defining a function for setting ORDER BY for REMOVE operation.
  1118. @see mysqlx_set_order_by()
  1119. @ingroup xapi_coll
  1120. */
  1121. #define mysqlx_set_remove_order_by mysqlx_set_order_by
  1122. /**
  1123. A macro defining a function for setting LIMIT for REMOVE operation.
  1124. @see mysqlx_set_limit_and_offset()
  1125. @ingroup xapi_coll
  1126. */
  1127. #define mysqlx_set_remove_limit_and_offset mysqlx_set_limit_and_offset
  1128. /**
  1129. Create a statement which modifies documents in a collection.
  1130. @param collection collection handle
  1131. @return handle for the newly created MODIFY statement.
  1132. NULL can be returned only in case when there are problems
  1133. allocating memory, which normally should not happen.
  1134. It is very unlikely for this function to end with an error
  1135. because it does not do any parsing, parameter checking etc.
  1136. @note To actually execute the statement, use `mysqlx_execute()` after
  1137. specifying modifications that should be performed.
  1138. @ingroup xapi_coll
  1139. */
  1140. PUBLIC_API mysqlx_stmt_t *
  1141. mysqlx_collection_modify_new(mysqlx_collection_t *collection);
  1142. /**
  1143. Set fields in a document to given values.
  1144. @param stmt handle to MODIFY statement
  1145. @param ... list of parameters that come as triplets
  1146. <field_path, value_type, value>
  1147. Each triplet represents a value inside a document that can
  1148. be located by field_path. The value_type is the type identifier
  1149. for the data type of value (see `mysqlx_data_type_t` enum)
  1150. The list is terminated by `PARAM_END`.
  1151. For `MYSQLX_TYPE_BYTES` there will be one extra parameter specifying
  1152. the length of the binary data:
  1153. <field_path, `MYSQLX_TYPE_BYTES`, value, length>
  1154. @note For the convenience the code can use `PARAM_TTT(val)` macros
  1155. instead of (`MYSQLX_TYPE_TTT`, value) pairs (see `mysqlx_stmt_bind()`).
  1156. @return `RESULT_OK` - on success; `RESULT_ERR` - on error
  1157. @ingroup xapi_coll
  1158. */
  1159. PUBLIC_API int
  1160. mysqlx_set_modify_set(mysqlx_stmt_t *stmt, ...);
  1161. /**
  1162. Unset fields in a document
  1163. @param stmt handle to MODIFY statement
  1164. @param ... list of paths to the documents fields that should be unset. Each
  1165. entry in this list is a character string.
  1166. The list is terminated by `PARAM_END`.
  1167. @return `RESULT_OK` - on success; `RESULT_ERR` - on error
  1168. @ingroup xapi_coll
  1169. */
  1170. PUBLIC_API int
  1171. mysqlx_set_modify_unset(mysqlx_stmt_t *stmt, ...);
  1172. /**
  1173. Insert elements into array fields in a document
  1174. @param stmt handle to MODIFY statement
  1175. @param ... list of parameters that come as triplets
  1176. <field_path, value_type, value>
  1177. Each triplet represents a position in an array field of a document,
  1178. given by field_path, and a value to be inserted in that position.
  1179. The value_type is the type identifier for the data type of value
  1180. (see `mysqlx_data_type_t` enum). The list is terminated by `PARAM_END`.
  1181. @note For the convenience the code can use `PARAM_TTT(val)` macros
  1182. instead of (`MYSQLX_TYPE_TTT`, value) pairs (see `mysqlx_stmt_bind()`).
  1183. @return `RESULT_OK` - on success; `RESULT_ERR` - on error
  1184. @ingroup xapi_coll
  1185. */
  1186. PUBLIC_API int
  1187. mysqlx_set_modify_array_insert(mysqlx_stmt_t *stmt, ...);
  1188. /**
  1189. Append to array fields in a document
  1190. @param stmt handle to MODIFY statement
  1191. @param ... list of parameters that come as triplets
  1192. <field_path, value_type, value>. Each triplet specifies an array
  1193. field in a document, given by field_path, and a value that should
  1194. be appended to that array. The value_type is the type identifier
  1195. for the data type of value (see `mysqlx_data_type_t` enum).
  1196. The list is terminated by `PARAM_END`.
  1197. @note For the convenience the code can use `PARAM_TTT(val)` macros
  1198. instead of (`MYSQLX_TYPE_TTT`, value) pairs (see `mysqlx_stmt_bind()`).
  1199. @return `RESULT_OK` - on success; `RESULT_ERR` - on error
  1200. @ingroup xapi_coll
  1201. */
  1202. PUBLIC_API int
  1203. mysqlx_set_modify_array_append(mysqlx_stmt_t *stmt, ...);
  1204. /**
  1205. Delete elements from array fields in a document
  1206. @param stmt handle to MODIFY statement
  1207. @param ... list of paths to array elements that should be deleted from their
  1208. arrays. The list is terminated by `PARAM_END`.
  1209. @return `RESULT_OK` - on success; `RESULT_ERR` - on error
  1210. @ingroup xapi_coll
  1211. */
  1212. PUBLIC_API int mysqlx_set_modify_array_delete(mysqlx_stmt_t *stmt, ...);
  1213. /**
  1214. A macro defining a function for setting WHERE for MODIFY operation.
  1215. @see mysqlx_set_where()
  1216. @ingroup xapi_coll
  1217. */
  1218. #define mysqlx_set_modify_criteria mysqlx_set_where
  1219. /*
  1220. ====================================================================
  1221. Table operations
  1222. ====================================================================
  1223. */
  1224. /**
  1225. Execute a table SELECT statement with a WHERE clause.
  1226. All columns will be selected.
  1227. @param table table handle
  1228. @param criteria row selection criteria (WHERE clause); if NULL then
  1229. all rows in the table are returned.
  1230. @return handle to the query results
  1231. NULL is returned only in case of an error. The error details
  1232. can be obtained using `mysqlx_error()` function
  1233. @ingroup xapi_tbl
  1234. */
  1235. PUBLIC_API mysqlx_result_t *
  1236. mysqlx_table_select(mysqlx_table_t *table, const char *criteria);
  1237. /**
  1238. Execute a table SELECT statement with a WHERE,
  1239. ORDER BY and LIMIT clauses
  1240. @param table table handle
  1241. @param criteria row selection criteria (WHERE clause); if NULL then all
  1242. rows in the table will be selected.
  1243. @param row_count a number of rows to return (LIMIT clause)
  1244. @param offset number of rows to skip (an offset for the LIMIT clause)
  1245. @param ... sorting specification - variable parameters list consisting of
  1246. (expression, direction) pairs terminated by `PARAM_END`: expr_1,
  1247. direction_1, ..., expr_n, direction_n, `PARAM_END`.
  1248. Each expression computes a value used to sort
  1249. the rows/documents in ascending or descending order,
  1250. as determined by direction constant
  1251. (TODO: list the direction enum names).
  1252. Special attention must be paid to the expression
  1253. strings because the empty string "" or NULL will be treated
  1254. as the end of sequence
  1255. @return handle to the query results.
  1256. NULL is returned only in case of an error. The error details
  1257. can be obtained using `mysqlx_error()` function
  1258. @ingroup xapi_tbl
  1259. */
  1260. PUBLIC_API mysqlx_result_t *
  1261. mysqlx_table_select_limit(mysqlx_table_t *table, const char *criteria,
  1262. uint64_t row_count, uint64_t offset, ...);
  1263. /**
  1264. Execute a table INSERT statement with one row.
  1265. @param table table handle
  1266. @param ... list of column-value specifications consisting of
  1267. <column_name, value_type, value> triplets. The list
  1268. should be terminated using `PARAM_END`.
  1269. Allowed value types are listed in `mysqlx_data_type_t` enum.
  1270. The X DevAPI for C defines the convenience macros that help
  1271. to specify the types and values: See `PARAM_SINT()`,
  1272. `PARAM_UINT()`, `PARAM_FLOAT()`, `PARAM_DOUBLE()`, `PARAM_BYTES()`,
  1273. `PARAM_STRING()`:
  1274. ..., "col_uint", PARAM_UINT(uint_val),
  1275. "col_blob", PARAM_BYTES(byte_buf, buf_len),
  1276. PARAM_END
  1277. @return handle to the query results.
  1278. NULL is returned only in case of an error. The error details
  1279. can be obtained using `mysqlx_error()` function
  1280. @ingroup xapi_tbl
  1281. */
  1282. PUBLIC_API mysqlx_result_t *
  1283. mysqlx_table_insert(mysqlx_table_t *table, ...);
  1284. /**
  1285. Execute a table DELETE statement with a WHERE clause.
  1286. @param table table handle
  1287. @param criteria expression selecting rows to be deleted; if this
  1288. parameter is NULL all rows are deleted
  1289. @return handle to the query results.
  1290. NULL is returned only in case of an error. The error details
  1291. can be obtained using `mysqlx_error()` function
  1292. @ingroup xapi_tbl
  1293. */
  1294. PUBLIC_API mysqlx_result_t *
  1295. mysqlx_table_delete(mysqlx_table_t *table, const char *criteria);
  1296. /**
  1297. Execute a table UPDATE statement.
  1298. @param table table handle
  1299. @param criteria expression selecting rows to be updated (WHERE clause)
  1300. @param ... list of column-value specifications consisting of
  1301. <column_name, value_type, value> triplets. The list
  1302. should be terminated using `PARAM_END`.
  1303. Allowed value types are listed in `mysqlx_data_type_t` enum.
  1304. The X DevAPI for C defines the convenience macros that help
  1305. to specify the types and values: See `PARAM_SINT()`,
  1306. `PARAM_UINT()`, `PARAM_FLOAT()`, `PARAM_DOUBLE()`, `PARAM_BYTES()`,
  1307. `PARAM_STRING()`, `PARAM_EXPR()`:
  1308. ..., "col_uint", PARAM_EXPR("col_uint * 100"),
  1309. "col_blob", PARAM_BYTES(byte_buf, buf_len),
  1310. PARAM_END
  1311. @return handle to the query results.
  1312. NULL is returned only in case of an error. The error details
  1313. can be obtained using `mysqlx_error()` function
  1314. @ingroup xapi_tbl
  1315. */
  1316. PUBLIC_API mysqlx_result_t *
  1317. mysqlx_table_update(mysqlx_table_t *table,
  1318. const char *criteria,
  1319. ...);
  1320. /*
  1321. Deferred statement execution
  1322. ----------------------------
  1323. */
  1324. /**
  1325. Create a statement which performs a table SELECT operation.
  1326. @param table table handle
  1327. @return handle to the newly created SELECT statement.
  1328. NULL can be returned only in case when there are problems
  1329. allocating memory, which normally should not happen.
  1330. It is very unlikely for this function to end with an error
  1331. because it does not do any parsing, parameter checking etc.
  1332. @note To actually execute the statement, the returned handle has to be
  1333. given to `mysqlx_execute()`.
  1334. @see mysqlx_set_insert_columns(), mysqlx_set_insert_row()
  1335. @ingroup xapi_tbl
  1336. */
  1337. PUBLIC_API mysqlx_stmt_t *
  1338. mysqlx_table_select_new(mysqlx_table_t *table);
  1339. /**
  1340. A macro defining a function for setting projections for SELECT operation.
  1341. @see mysqlx_set_items()
  1342. @ingroup xapi_tbl
  1343. */
  1344. #define mysqlx_set_select_items mysqlx_set_items
  1345. /**
  1346. A macro defining a function for setting WHERE for SELECT operation.
  1347. @see mysqlx_set_where()
  1348. @ingroup xapi_tbl
  1349. */
  1350. #define mysqlx_set_select_where mysqlx_set_where
  1351. /**
  1352. A macro defining a function for setting ORDER BY for SELECT
  1353. operation.
  1354. @see mysqlx_set_order_by()
  1355. @ingroup xapi_tbl
  1356. */
  1357. #define mysqlx_set_select_order_by mysqlx_set_order_by
  1358. /*
  1359. A macro defining a function for setting HAVING for SELECT operation.
  1360. @see mysqlx_set_having()
  1361. @ingroup xapi_tbl
  1362. */
  1363. #define mysqlx_set_select_having mysqlx_set_having
  1364. /**
  1365. A macro defining a function for setting GROUP BY for SELECT operation.
  1366. @see mysqlx_set_group_by()
  1367. @ingroup xapi_tbl
  1368. */
  1369. #define mysqlx_set_select_group_by mysqlx_set_group_by
  1370. /**
  1371. A macro defining a function for setting LIMIT for SELECT operation.
  1372. @see mysqlx_set_limit_and_offset()
  1373. @ingroup xapi_tbl
  1374. */
  1375. #define mysqlx_set_select_limit_and_offset mysqlx_set_limit_and_offset
  1376. /**
  1377. A macro defining a function for setting row locking mode
  1378. for SELECT operation.
  1379. @see mysqlx_set_row_locking()
  1380. @ingroup xapi_coll
  1381. */
  1382. #define mysqlx_set_select_row_locking mysqlx_set_row_locking
  1383. /**
  1384. Create a statement executing a table INSERT operation.
  1385. @param table table handle
  1386. @return statement handle for the newly created INSERT operation.
  1387. NULL can be returned only in case when there are problems
  1388. allocating memory, which normally should not happen.
  1389. It is very unlikely for this function to end with an error
  1390. because it does not do any parsing, parameter checking etc.
  1391. @note To actually execute the SQL query the returned Statement has to be
  1392. given to `mysqlx_execute()`
  1393. @ingroup xapi_tbl
  1394. */
  1395. PUBLIC_API mysqlx_stmt_t *
  1396. mysqlx_table_insert_new(mysqlx_table_t *table);
  1397. /**
  1398. Specify column names for an INSERT statement.
  1399. The function specifies the names of the columns into which the statement
  1400. will insert data. User code must ensure that the column values are correct
  1401. because the names are not validated until receiving the query on
  1402. the server side after executing with `mysqlx_execute()`.
  1403. @param stmt statement handle
  1404. @param ... variable parameters list consisting of column names; the list is
  1405. terminated by PARAM_END.
  1406. @return `RESULT_OK` - on success; `RESULT_ERR` - on error
  1407. @note Each new call clears the list of column for a given statement
  1408. if it was set earlier.
  1409. @note If column names are not specified for an insert statement, it will
  1410. insert data into all columns of the table.
  1411. @ingroup xapi_tbl
  1412. */
  1413. PUBLIC_API int
  1414. mysqlx_set_insert_columns(mysqlx_stmt_t *stmt, ...);
  1415. /**
  1416. Specify a row to be added by an INSERT statement.
  1417. The function provides the row data for an INSERT statement.
  1418. User code must ensure that the number of values and their order matches
  1419. the list of columns specified for the operation. If column names were not
  1420. explicitly specified, the values must match the columns of the table.
  1421. @param stmt statement handle
  1422. @param ... variable parameters list consisting of (type, value) pairs
  1423. terminated by PARAM_END. The pairs must be listed in the order they
  1424. appear in the list of columns
  1425. For MYSQLX_TYPE_BYTES the function will expect three parameters
  1426. instead of two as for all other types:
  1427. <MYSQLX_TYPE_BYTES, (void*)byte_data, (size_t)length>
  1428. @return `RESULT_OK` - on success; `RESULT_ERR` - on error
  1429. @note Each new call provides the row values for the new row, which
  1430. can be used for multi-row inserts
  1431. @ingroup xapi_stmt
  1432. */
  1433. PUBLIC_API int
  1434. mysqlx_set_insert_row(mysqlx_stmt_t *stmt, ...);
  1435. /**
  1436. Create a statement executing a table DELETE operation.
  1437. @param table table handle
  1438. @return handle for the newly created DELETE statement.
  1439. NULL can be returned only in case when there are problems
  1440. allocating memory, which normally should not happen.
  1441. It is very unlikely for this function to end with an error
  1442. because it does not do any parsing, parameter checking etc.
  1443. @note To actually execute the statement, use `mysqlx_execute()`.
  1444. @see mysqlx_set_delete_where(), mysqlx_set_delete_limit(),
  1445. mysqlx_set_delete_order_by()
  1446. @ingroup xapi_tbl
  1447. */
  1448. PUBLIC_API mysqlx_stmt_t *
  1449. mysqlx_table_delete_new(mysqlx_table_t *table);
  1450. /**
  1451. A macro defining a function for setting WHERE clause for DELETE operation.
  1452. @see mysqlx_set_where()
  1453. @ingroup xapi_tbl
  1454. */
  1455. #define mysqlx_set_delete_where mysqlx_set_where
  1456. /**
  1457. A macro defining a function for setting LIMIT for DELETE operation.
  1458. @see mysqlx_set_limit_and_offset()
  1459. @ingroup xapi_tbl
  1460. */
  1461. #define mysqlx_set_delete_limit(STMT, LIM) mysqlx_set_limit_and_offset(STMT, LIM, 0)
  1462. /**
  1463. A macro defining a function for setting ORDER BY for DELETE operation.
  1464. @see mysqlx_set_order_by()
  1465. @ingroup xapi_tbl
  1466. */
  1467. #define mysqlx_set_delete_order_by mysqlx_set_order_by
  1468. /**
  1469. Create a statement executing a table UPDATE operation.
  1470. @param table table handle
  1471. @return handle for the newly created UPDATE statement.
  1472. NULL can be returned only in case when there are problems
  1473. allocating memory, which normally should not happen.
  1474. It is very unlikely for this function to end with an error
  1475. because it does not do any parsing, parameter checking etc.
  1476. @note To actually execute the statement, use `mysqlx_execute()` after
  1477. specifying what updates should it perform.
  1478. @see mysqlx_set_update_values(), mysqlx_set_update_where(),
  1479. mysqlx_set_update_limit(), mysqlx_set_update_order_by()
  1480. @ingroup xapi_tbl
  1481. */
  1482. PUBLIC_API mysqlx_stmt_t *
  1483. mysqlx_table_update_new(mysqlx_table_t *table);
  1484. /**
  1485. Set values for the columns in the UPDATE statement.
  1486. @param stmt statement handle
  1487. @param ... variable parameters list consisting of triplets
  1488. <column_name, value_type, value_or_expression>
  1489. representing column names, value types and values as
  1490. expressions. The list is terminated by `PARAM_END`:
  1491. column_1, type_1, val_1, ..., column_n, type_n, val_n, `PARAM_END`.
  1492. The value type is defined in `mysqlx_data_type_t` enum.
  1493. If the value is to be computed on the server side the type
  1494. has to be set to `MYSQLX_TYPE_EXPR`. The value (expression)
  1495. should be specified as a character string expression.
  1496. For `MYSQLX_TYPE_BYTES` the function will expect four parameters
  1497. instead of three as for all other types:
  1498. <column_name, `MYSQLX_TYPE_BYTES`, (void*)byte_data, (size_t)length>
  1499. @return `RESULT_OK` - on success; `RESULT_ERR` - on error
  1500. @note The `param` list must be not empty, otherwise error is reported.
  1501. @note All fields and their corresponding expressions must be set in one call
  1502. otherwise the next call to this function will reset all parameters to
  1503. their new values.
  1504. @ingroup xapi_tbl
  1505. */
  1506. PUBLIC_API int mysqlx_set_update_values(mysqlx_stmt_t *stmt, ...);
  1507. /**
  1508. A macro defining a function for setting WHERE clause for UPDATE operation.
  1509. @see mysqlx_set_where()
  1510. @ingroup xapi_tbl
  1511. */
  1512. #define mysqlx_set_update_where mysqlx_set_where
  1513. /**
  1514. A macro defining a function for setting LIMIT for UPDATE operation.
  1515. @see mysqlx_set_limit_and_offset()
  1516. @ingroup xapi_tbl
  1517. */
  1518. #define mysqlx_set_update_limit(STMT, LIM) mysqlx_set_limit_and_offset(STMT, LIM, 0)
  1519. /**
  1520. A macro defining a function for setting ORDER BY clause for UPDATE
  1521. operation.
  1522. @see mysqlx_set_oder_by()
  1523. @ingroup xapi_tbl
  1524. */
  1525. #define mysqlx_set_update_order_by mysqlx_set_order_by
  1526. /*
  1527. ====================================================================
  1528. Statement execution
  1529. ====================================================================
  1530. */
  1531. /**
  1532. Execute a statement
  1533. Executes statement created by `mysqlx_table_select_new()`,
  1534. `mysqlx_table_insert_new()`, `mysqlx_table_update_new()`,
  1535. `mysqlx_table_delete_new()`, `mysqlx_sql_new()`, etc.
  1536. @param stmt statement handle
  1537. @return handle that can be used to access results
  1538. of the operation. Returned handle is valid until the statement
  1539. handle is freed (when session is closed or explicitly with
  1540. `mysqlx_free()`) or until another call to `mysqlx_execute()`
  1541. on the same statement handle is made. It is also possible to close
  1542. a result handle and free all resources used by it earlier with
  1543. `mysqlx_result_free()` call.
  1544. On error NULL is returned. The statement is set to an error state and
  1545. errors can be examined using the statement handle.
  1546. @ingroup xapi_stmt
  1547. */
  1548. PUBLIC_API mysqlx_result_t *
  1549. mysqlx_execute(mysqlx_stmt_t *stmt);
  1550. /**
  1551. Bind values for parametrized statements.
  1552. This function binds values of either `?` placeholders in an SQL statement
  1553. or of named parameters that can be used in other statements.
  1554. User code must ensure that the number of values in bind is the same
  1555. as the number of parameters in the query because this is not checked
  1556. until receiving the query on the server side.
  1557. @param stmt statement handle
  1558. @param ... variable parameters list, which has different structure for SQL
  1559. statements that use placeholders and for other statements that use
  1560. named parameters.
  1561. For SQL statements it is consisting of (type, value) pairs
  1562. terminated by `PARAM_END`: type_id1, value1, type_id2, value2, ...,
  1563. type_id_n, value_n, `PARAM_END`.
  1564. For SELECT, INSERT, UPDATE, DELETE, FIND, ADD, MODIFY and REMOVE
  1565. statements, the parameters come as triplets (param_name, type,
  1566. value): name1, type_id1, value1, name2, type_id2, value2, ...,
  1567. name_n, type_id_n, value_n, `PARAM_END` (`PARAM_END` marks the end
  1568. of the parameters list).
  1569. type_id is the numeric identifier, which helps to determine the type
  1570. of the value provided as the next parameter. The user code must
  1571. ensure that type_id corresponds to the actual value type. Otherwise,
  1572. the value along with and all sequential types and values are most
  1573. likely to be corrupted.
  1574. It is recommended to use `PARAM_TTT()` macros to keep the list
  1575. integrity: `PARAM_UINT()`, `PARAM_SINT()`, `PARAM_FLOAT()`,
  1576. `PARAM_DOUBLE()`, `PARAM_STRING()`, `PARAM_BYTES()`, `PARAM_EXPR()`
  1577. for different data types instead of (`MYSQLX_TYPE_TTT`, value) pairs.
  1578. @return `RESULT_OK` - on success; `RESULT_ERR` - on error
  1579. @note Each new call resets the binds set by the previous call to
  1580. `mysqlx_stmt_bind()`
  1581. @ingroup xapi_stmt
  1582. */
  1583. PUBLIC_API int mysqlx_stmt_bind(mysqlx_stmt_t *stmt, ...);
  1584. /**
  1585. Specify a table query projection.
  1586. Using projection, rows found by the query can be mapped to a new set of
  1587. rows which is returned in the final result. Projection is given by a list
  1588. of expressions determining values of fields in the resulting rows. These
  1589. expressions can refer to the fields in the original row (via column names
  1590. of the original table).
  1591. @param stmt handle to the statement for which the projection is set
  1592. @param ... variable parameters list consisting of character strings
  1593. containing expressions: proj_1, ..., proj_n, PARAM_END
  1594. (PARAM_END marks the end of projection's item list)
  1595. @return `RESULT_OK` - on success; `RESULT_ERR` - on error
  1596. @note This function can be only called for table SELECT statements
  1597. @see mysqlx_table_select_new()
  1598. @ingroup xapi_stmt
  1599. */
  1600. PUBLIC_API int mysqlx_set_items(mysqlx_stmt_t *stmt, ...);
  1601. /**
  1602. Specify selection criteria for a statement.
  1603. Restrict the statement to rows/documents that satisfy
  1604. given selection criteria:
  1605. - for select/find operations limit the returned rows/documents,
  1606. - for update/modify/delete/remove operations limit
  1607. the rows/documents affected by the operations.
  1608. Statements supported by this function: SELECT, FIND, UPDATE, MODIFY, DELETE,
  1609. REMOVE. Calling it for INSERT or ADD will result in an error
  1610. @param stmt statement handle
  1611. @param where_expr character string containing Boolean expression
  1612. like in SQL WHERE clause
  1613. @return `RESULT_OK` - on success; `RESULT_ERR` - on error
  1614. @note this function can be be used directly, but for the convenience
  1615. the code can use the specialized macros for a specific operation.
  1616. For SELECT operation the user code should use
  1617. `mysqlx_set_select_where()` macros that map the
  1618. corresponding `mysqlx_set_where()` function.
  1619. This way the unsupported operations will not be used.
  1620. @ingroup xapi_stmt
  1621. */
  1622. PUBLIC_API int mysqlx_set_where(mysqlx_stmt_t *stmt, const char *where_expr);
  1623. /**
  1624. Specify filter conditions for a group of rows/documents or aggregates
  1625. such as GROUP BY
  1626. Restrict the statement to rows/documents that satisfy
  1627. given selection criteria:
  1628. - for select/find operations limit the returned rows/documents,
  1629. Statements supported by this function: SELECT, FIND.
  1630. Calling it for UPDATE, MODIFY, DELETE, REMOVE, INSERT or ADD
  1631. will result in an error
  1632. @param stmt statement handle
  1633. @param having_expr character string containing Boolean expression
  1634. like in SQL HAVING clause
  1635. @return `RESULT_OK` - on success; `RESULT_ERR` - on error
  1636. @note this function can be be used directly, but for the convenience
  1637. the code can use the specialized macros for a specific operation.
  1638. For SELECT operation the user code should use
  1639. `mysqlx_set_select_having()` macros that map the
  1640. corresponding `mysqlx_set_having()` function.
  1641. This way the unsupported operations will not be used.
  1642. @ingroup xapi_stmt
  1643. */
  1644. PUBLIC_API int mysqlx_set_having(mysqlx_stmt_t *stmt, const char *having_expr);
  1645. /**
  1646. Specify one or more columns/values to group the result in conjunction
  1647. with the aggregate functions.
  1648. Statements supported by this function: SELECT, FIND.
  1649. Calling it for UPDATE, MODIFY, DELETE, REMOVE, INSERT or ADD
  1650. will result in an error
  1651. @param stmt statement handle
  1652. @param ... variable parameters list consisting of character strings
  1653. containing expressions specifying grouping:
  1654. expr_1, ..., expr_n, PARAM_END
  1655. (PARAM_END marks the end of projection's item list)
  1656. @return `RESULT_OK` - on success; `RESULT_ERR` - on error
  1657. @note this function can be be used directly, but for the convenience
  1658. the code can use the specialized macros for a specific operation.
  1659. For SELECT operation the user code should use
  1660. `mysqlx_set_select_group_by()` macros that map the
  1661. corresponding `mysqlx_set_group_by()` function.
  1662. This way the unsupported operations will not be used.
  1663. @ingroup xapi_stmt
  1664. */
  1665. PUBLIC_API int mysqlx_set_group_by(mysqlx_stmt_t *stmt, ...);
  1666. /**
  1667. Specify ordering for a statement.
  1668. Operations supported by this function:
  1669. SELECT, FIND, UPDATE, MODIFY, DELETE, REMOVE
  1670. Calling it for INSERT or ADD will result in an error
  1671. @param stmt statement handle
  1672. @param ... variable parameters list consisting of (expression, direction)
  1673. pairs terminated by `PARAM_END`: expr_1, direction_1, ..., expr_n,
  1674. direction_n, `PARAM_END`.
  1675. Each expression computes a value used to sort
  1676. the rows/documents in ascending or descending order,
  1677. as determined by direction constant
  1678. (list the direction enum names).
  1679. Special attention must be paid to the expression
  1680. strings because the empty string "" or NULL will be treated
  1681. as the end of sequence
  1682. @return `RESULT_OK` - on success; `RESULT_ERR` - on error
  1683. @note this function can be be used directly, but for the convenience
  1684. the code can use the specialized macros for a specific operation.
  1685. For SELECT operation the user code should use
  1686. `mysqlx_set_select_order_by()` macros that map the
  1687. corresponding `mysqlx_set_order_by()` function.
  1688. This way the unsupported operations will not be used.
  1689. @ingroup xapi_stmt
  1690. */
  1691. PUBLIC_API int mysqlx_set_order_by(mysqlx_stmt_t *stmt, ...);
  1692. /**
  1693. Set limit and offset information for a statement.
  1694. Set LIMIT and OFFSET for statement operations which work on ranges of
  1695. rows/documents: for select/find operations limit the number of returned
  1696. rows/documents, for update/delete limit the number of documents affected
  1697. by the operation.
  1698. Operations supported by this function:
  1699. SELECT, FIND - use both LIMIT and OFFSET
  1700. UPDATE, MODIFY, DELETE, REMOVE - use only LIMIT
  1701. Calling it for INSERT or ADD will result in an error
  1702. @param stmt statement handle
  1703. @param row_count the number of result rows to return
  1704. @param offset the number of rows to skip before starting counting
  1705. @return `RESULT_OK` - on success; `RESULT_ERR` - on error
  1706. @note this function can be be used directly, but for the convenience
  1707. the code can use the specialized macros for a specific operation.
  1708. For SELECT operation the user code should use
  1709. `mysqlx_set_select_limit_and_offset()` macros that map the
  1710. corresponding `mysqlx_set_limit_and_offset()` function.
  1711. This way the unsupported operations will not be used.
  1712. @note Each call to this function replaces previously set LIMIT
  1713. @ingroup xapi_stmt
  1714. */
  1715. PUBLIC_API int
  1716. mysqlx_set_limit_and_offset(mysqlx_stmt_t *stmt, uint64_t row_count,
  1717. uint64_t offset);
  1718. /**
  1719. Set row locking mode for a statement.
  1720. Set row locking mode for statement operations working on ranges of
  1721. rows/documents.
  1722. Operations supported by this function:
  1723. SELECT, FIND
  1724. Calling it for INSERT, UPDATE, DELETE, ADD, MODIFY and REMOVE
  1725. will result in an error.
  1726. @param stmt statement handle
  1727. @param locking the integer mode identifier (see ::mysqlx_row_locking_t).
  1728. @param contention the integer locking contention
  1729. (see ::mysqlx_lock_contention_t).
  1730. @return `RESULT_OK` - on success; `RESULT_ERR` - on error
  1731. @note this function can be be used directly, but for the convenience
  1732. the code can use the specialized macros for a specific operation.
  1733. For SELECT operation the user code should use
  1734. `mysqlx_set_select_row_locking()` macros that map the
  1735. corresponding `mysqlx_set_row_locking()` function.
  1736. This way the unsupported operations will not be used.
  1737. @note Each call to this function replaces previously set locking mode
  1738. @ingroup xapi_stmt
  1739. */
  1740. PUBLIC_API int
  1741. mysqlx_set_row_locking(mysqlx_stmt_t *stmt, int locking, int contention);
  1742. /**
  1743. Free the statement handle explicitly.
  1744. @note Statement handles are also freed automatically when
  1745. statement's session is closed.
  1746. @param stmt statement handle
  1747. @ingroup xapi_stmt
  1748. */
  1749. PUBLIC_API void mysqlx_free(mysqlx_stmt_t *stmt);
  1750. /*
  1751. ====================================================================
  1752. Result handling
  1753. ====================================================================
  1754. */
  1755. /**
  1756. Fetch one row from the result
  1757. The result is advanced to the next row (if any).
  1758. @param res result handle
  1759. @return row handle or NULL if no more rows left or if an error
  1760. occurred. In case of an error it can be retrieved from
  1761. the result using `mysqlx_error()` or `mysqlx_error_message()`.
  1762. @note The previously fetched row and its data will become invalid.
  1763. @ingroup xapi_res
  1764. */
  1765. PUBLIC_API mysqlx_row_t * mysqlx_row_fetch_one(mysqlx_result_t *res);
  1766. /**
  1767. Fetch one document as a JSON string
  1768. @param res result handle
  1769. @param[out] out_length the total number of bytes in the JSON string;
  1770. can be NULL, in that case nothing is returned through
  1771. this parameter and user must ensure the data is correctly
  1772. interpreted
  1773. @return pointer to character JSON string or NULL if no more documents left
  1774. in the result. No need to free this data as it is tied and freed
  1775. with the result handle.
  1776. @ingroup xapi_res
  1777. */
  1778. PUBLIC_API const char * mysqlx_json_fetch_one(mysqlx_result_t *res, size_t *out_length);
  1779. /**
  1780. Proceed to the next result set in the reply.
  1781. This function is used to process replies containing multiple result sets.
  1782. After a successful call to this function, given result handle will be moved
  1783. to access the next result set from the reply.
  1784. @note Any data from the previous result set that has not yet been fetched
  1785. is no more accessible after moving to the next result set.
  1786. @param res result handle
  1787. @return `RESULT_OK` - on success; `RESULT_NULL` when there is no more results;
  1788. `RESULT_ERR` - on error
  1789. @ingroup xapi_res
  1790. */
  1791. PUBLIC_API int mysqlx_next_result(mysqlx_result_t *res);
  1792. /**
  1793. Get number of rows affected by a statement.
  1794. @param res result handle
  1795. @return the number of rows affected by the statement that produced the result
  1796. @note The returned number is meaningful only for results of statements which
  1797. modify data stored in a table or collection.
  1798. @ingroup xapi_res
  1799. */
  1800. PUBLIC_API uint64_t
  1801. mysqlx_get_affected_count(mysqlx_result_t *res);
  1802. /**
  1803. Store result data in an internal buffer
  1804. Rows/documents contained in a result must be fetched in a timely fashion.
  1805. Failing to do that can result in an error and lost access to the
  1806. remaining part of the result. This function can store complete result
  1807. in memory so it can be accessed at any time, as long as the result
  1808. handle is valid.
  1809. @param result result handle
  1810. @param[out] num number of records buffered
  1811. @return `RESULT_OK` - on success; `RESULT_ERR` - on error. If the error
  1812. occurred it can be retrieved by `mysqlx_error()` function.
  1813. @note Even in case of an error some rows/documents might be buffered if they
  1814. were retrieved before the error occurred.
  1815. @ingroup xapi_res
  1816. */
  1817. PUBLIC_API int
  1818. mysqlx_store_result(mysqlx_result_t *result, size_t *num);
  1819. /**
  1820. Get identifiers of the documents added to the collection.
  1821. This function returns both generated document ids and document ids specified
  1822. by user in `_id` field.
  1823. The function can be used for the multi-document inserts. In this case each
  1824. call to `mysqlx_fetch_generated_id()` returns identifier of the next document,
  1825. until NULL is returned.
  1826. @param result handle to a result of a statement which adds documents to
  1827. a collection
  1828. @return character string containing an identifier of a document added by the
  1829. statement; NULL - if all UUIDs for all added documents have been
  1830. returned
  1831. @note The returned string is valid as long as the result handle is valid.
  1832. Starting a new operation will invalidate it.
  1833. @ingroup xapi_res
  1834. */
  1835. PUBLIC_API const char *
  1836. mysqlx_fetch_generated_id(mysqlx_result_t *result);
  1837. /**
  1838. Get auto increment value generated by a statement that inserts rows
  1839. into a table with auto increment column.
  1840. @param res handle to a result of INSERT statement
  1841. @return the generated auto increment value
  1842. @note with multi-row inserts the function returns the value generated
  1843. for the first row
  1844. @ingroup xapi_res
  1845. */
  1846. PUBLIC_API uint64_t
  1847. mysqlx_get_auto_increment_value(mysqlx_result_t *res);
  1848. /**
  1849. Read bytes stored in a row into a pre-allocated buffer
  1850. @param row row handle
  1851. @param col zero-based column number
  1852. @param offset the number of bytes to skip before reading them from source row
  1853. @param[out] buf the buffer allocated on the user side into which to write data
  1854. @param[in,out] buf_len pointer to a variable holding the length of the buffer
  1855. [IN], the number of bytes actually written into the
  1856. buffer [OUT]
  1857. @return `RESULT_OK` - on success; `RESULT_NULL` when the value in the
  1858. requested column is NULL; `RESULT_MORE_DATA` if not all data was
  1859. fetched after the last call to the function;
  1860. `RESULT_ERR` - on error
  1861. @ingroup xapi_res
  1862. */
  1863. PUBLIC_API int
  1864. mysqlx_get_bytes(mysqlx_row_t* row, uint32_t col,
  1865. uint64_t offset, void *buf, size_t *buf_len);
  1866. /**
  1867. Get an unsigned integer number from a row.
  1868. It is important to pay attention to the signed/unsigned type of the column.
  1869. Attempting to call this function for a column whose type is different from
  1870. `MYSQLX_TYPE_UINT` will result in wrong data being retrieved.
  1871. @param row row handle
  1872. @param col zero-based column number
  1873. @param[out] val the pointer to a variable of the 64-bit unsigned integer
  1874. type in which to write the data
  1875. @return `RESULT_OK` - on success; `RESULT_NULL` when the column is NULL;
  1876. `RESULT_ERR` - on error
  1877. @ingroup xapi_res
  1878. */
  1879. PUBLIC_API int
  1880. mysqlx_get_uint(mysqlx_row_t* row, uint32_t col, uint64_t* val);
  1881. /**
  1882. Get a signed integer number from a row.
  1883. It is important to pay attention to the signed/unsigned type of the column.
  1884. Attempting to call this function for a column whose type is different from
  1885. `MYSQLX_TYPE_SINT` will result in wrong data being retrieved.
  1886. @param row row handle
  1887. @param col zero-based column number
  1888. @param[out] val the pointer to a variable of the 64-bit signed integer
  1889. type in which to write the data
  1890. @return `RESULT_OK` - on success; `RESULT_NULL` when the column is NULL;
  1891. `RESULT_ERR` - on error
  1892. @ingroup xapi_res
  1893. */
  1894. PUBLIC_API int
  1895. mysqlx_get_sint(mysqlx_row_t* row, uint32_t col, int64_t* val);
  1896. /**
  1897. Get a float number from a row.
  1898. It is important to pay attention to the type of the column.
  1899. Attempting to call this function for a column whose type is different from
  1900. `MYSQLX_TYPE_FLOAT` will result in wrong data being retrieved.
  1901. @param row row handle
  1902. @param col zero-based column number
  1903. @param[out] val the pointer to a variable of the float
  1904. type in which to write the data
  1905. @return `RESULT_OK` - on success; `RESULT_NULL` when the column is NULL;
  1906. `RESULT_ERR` - on error
  1907. @ingroup xapi_res
  1908. */
  1909. PUBLIC_API int
  1910. mysqlx_get_float(mysqlx_row_t* row, uint32_t col, float* val);
  1911. /**
  1912. Get a double number from a row.
  1913. It is important to pay attention to the type of the column.
  1914. Attempting to call this function for a column whose type is different from
  1915. `MYSQLX_TYPE_DOUBLE` will result in wrong data being retrieved.
  1916. @param row row handle
  1917. @param col zero-based column number
  1918. @param[out] val the pointer to a variable of the double
  1919. type in which to write the data.
  1920. @return `RESULT_OK` - on success; `RESULT_NULL` when the column is NULL;
  1921. `RESULT_ERR` - on error
  1922. @ingroup xapi_res
  1923. */
  1924. PUBLIC_API int
  1925. mysqlx_get_double(mysqlx_row_t* row, uint32_t col, double *val);
  1926. /**
  1927. Free the result explicitly.
  1928. @note Results are also freed automatically when the corresponding
  1929. statement handle is freed.
  1930. @param res the result handle
  1931. @ingroup xapi_res
  1932. */
  1933. PUBLIC_API void mysqlx_result_free(mysqlx_result_t *res);
  1934. /*
  1935. Result metadata
  1936. ---------------
  1937. */
  1938. /**
  1939. Get column type identifier.
  1940. @param res result handle
  1941. @param pos zero-based column number
  1942. @return column type identifier (see `mysqlx_data_type_t` enum)
  1943. @ingroup xapi_md
  1944. */
  1945. PUBLIC_API uint16_t
  1946. mysqlx_column_get_type(mysqlx_result_t *res, uint32_t pos);
  1947. /**
  1948. Get column collation number.
  1949. @param res result handle
  1950. @param pos zero-based column number
  1951. @return column collation number. TODO: specify these
  1952. @ingroup xapi_md
  1953. */
  1954. PUBLIC_API uint16_t
  1955. mysqlx_column_get_collation(mysqlx_result_t *res, uint32_t pos);
  1956. /**
  1957. Get column length.
  1958. @param res result handle
  1959. @param pos zero-based column number
  1960. @return maximum length of data in the column in bytes
  1961. as reported by server.
  1962. @note because the column length is returned as byte length
  1963. it could be confusing with the multi-byte charsets.
  1964. For instance with UTF8MB4 the length of VARCHAR(100)
  1965. column is returned as 400 because each character is
  1966. 4 bytes long.
  1967. @ingroup xapi_md
  1968. */
  1969. PUBLIC_API uint32_t
  1970. mysqlx_column_get_length(mysqlx_result_t *res, uint32_t pos);
  1971. /**
  1972. Get column precision.
  1973. @param res result handle
  1974. @param pos zero-based column number
  1975. @return number of digits after the decimal point
  1976. @ingroup xapi_md
  1977. */
  1978. PUBLIC_API uint16_t
  1979. mysqlx_column_get_precision(mysqlx_result_t *res, uint32_t pos);
  1980. /*
  1981. Get column flags.
  1982. @param res result handle
  1983. @param pos zero-based column number
  1984. @return 32-bit unsigned integer containing column flags reported by
  1985. server. TODO: Document these
  1986. @ingroup xapi_md
  1987. */
  1988. //PUBLIC_API uint32_t
  1989. //mysqlx_column_get_flags(mysqlx_result_t *res, uint32_t pos);
  1990. /**
  1991. Get the number of columns in the result.
  1992. @param res result handle
  1993. @return the number of columns in the result
  1994. @note If the result does not contain rows, 0 columns are reported.
  1995. @note For a result with multiple result sets, the number of columns for
  1996. the current result set is reported (see `mysqlx_next_result()`).
  1997. @ingroup xapi_md
  1998. */
  1999. PUBLIC_API uint32_t
  2000. mysqlx_column_get_count(mysqlx_result_t *res);
  2001. /**
  2002. Get column name.
  2003. @param res result handle
  2004. @param pos zero-based column number
  2005. @return character string containing the column name
  2006. @ingroup xapi_md
  2007. */
  2008. PUBLIC_API const char *
  2009. mysqlx_column_get_name(mysqlx_result_t *res, uint32_t pos);
  2010. /**
  2011. Get column original name.
  2012. @param res result handle
  2013. @param pos zero-based column number
  2014. @return character string containing the column original name
  2015. @ingroup xapi_md
  2016. */
  2017. PUBLIC_API const char *
  2018. mysqlx_column_get_original_name(mysqlx_result_t *res, uint32_t pos);
  2019. /**
  2020. Get column's table name.
  2021. @param res result handle
  2022. @param pos zero-based column number
  2023. @return character string containing the column table name
  2024. @ingroup xapi_md
  2025. */
  2026. PUBLIC_API const char *
  2027. mysqlx_column_get_table(mysqlx_result_t *res, uint32_t pos);
  2028. /**
  2029. Get column's original table name.
  2030. @param res result handle
  2031. @param pos zero-based column number
  2032. @return character string containing the column original table
  2033. @ingroup xapi_md
  2034. */
  2035. PUBLIC_API const char *
  2036. mysqlx_column_get_original_table(mysqlx_result_t *res, uint32_t pos);
  2037. /**
  2038. Get column's schema name.
  2039. @param res result handle
  2040. @param pos zero-based column number
  2041. @return character string containing the column schema
  2042. @ingroup xapi_md
  2043. */
  2044. PUBLIC_API const char *
  2045. mysqlx_column_get_schema(mysqlx_result_t *res, uint32_t pos);
  2046. /**
  2047. Get column's catalog name.
  2048. @param res result handle
  2049. @param pos zero-based column number
  2050. @return character string containing the column name
  2051. @ingroup xapi_md
  2052. */
  2053. PUBLIC_API const char *
  2054. mysqlx_column_get_catalog(mysqlx_result_t *res, uint32_t pos);
  2055. /*
  2056. ====================================================================
  2057. DDL statements
  2058. ====================================================================
  2059. */
  2060. /**
  2061. Create a schema
  2062. @param sess session handle
  2063. @param schema the name of the schema to be created
  2064. @return `RESULT_OK` - on success; `RESULT_ERR` - on error
  2065. The error handle can be obtained from the session
  2066. using `mysqlx_error()` function.
  2067. @ingroup xapi_ddl
  2068. */
  2069. PUBLIC_API int
  2070. mysqlx_schema_create(mysqlx_session_t *sess, const char *schema);
  2071. /**
  2072. Drop a schema
  2073. @param sess session handle
  2074. @param schema the name of the schema to be dropped
  2075. @return `RESULT_OK` - on success; `RESULT_ERR` - on error
  2076. The error handle can be obtained from the session
  2077. using `mysqlx_error()` function.
  2078. @ingroup xapi_ddl
  2079. */
  2080. PUBLIC_API int
  2081. mysqlx_schema_drop(mysqlx_session_t *sess, const char *schema);
  2082. /**
  2083. Create a new collection in a specified schema
  2084. @param schema schema handle
  2085. @param collection collection name to create
  2086. @return `RESULT_OK` - on success; `RESULT_ERR` - on error
  2087. The error handle can be obtained from the session
  2088. using `mysqlx_error()` function.
  2089. @ingroup xapi_ddl
  2090. */
  2091. PUBLIC_API int
  2092. mysqlx_collection_create(mysqlx_schema_t *schema, const char *collection);
  2093. /**
  2094. Drop an existing collection in a specified schema
  2095. @param schema schema handle
  2096. @param collection collection name to drop
  2097. @return `RESULT_OK` - on success; `RESULT_ERR` - on error
  2098. The error handle can be obtained from the session
  2099. using `mysqlx_error()` function
  2100. @ingroup xapi_ddl
  2101. */
  2102. PUBLIC_API int
  2103. mysqlx_collection_drop(mysqlx_schema_t *schema, const char *collection);
  2104. /*
  2105. ====================================================================
  2106. Diagnostics
  2107. ====================================================================
  2108. */
  2109. /**
  2110. Get the last error from the object.
  2111. @param obj handle to the object to extract the error information from.
  2112. Supported handle types are `mysqlx_session_t`,
  2113. `mysqlx_session_options_t`, `mysqlx_schema_t`,
  2114. `mysqlx_collection_t`, `mysqlx_table_t`, `mysqlx_stmt_t`,
  2115. `mysqlx_result_t`, `mysqlx_row_t`, `mysqlx_error_t`
  2116. @return the error handle or NULL if there is no errors.
  2117. @ingroup xapi_diag
  2118. */
  2119. PUBLIC_API mysqlx_error_t * mysqlx_error(void *obj);
  2120. /**
  2121. Get the error message from the object.
  2122. @param obj handle to the object to extract the error information from.
  2123. Supported handle types are `mysqlx_session_t`,
  2124. `mysqlx_session_options_t`, `mysqlx_schema_t`,
  2125. `mysqlx_collection_t`, `mysqlx_table_t`, `mysqlx_stmt_t`,
  2126. `mysqlx_result_t`, `mysqlx_row_t`, `mysqlx_error_t`
  2127. @return the character string or NULL if there is no errors.
  2128. @ingroup xapi_diag
  2129. */
  2130. PUBLIC_API const char * mysqlx_error_message(void *obj);
  2131. /**
  2132. Get the error number from the object.
  2133. @param obj handle to the object to extract the error information from.
  2134. Supported handle types are `mysqlx_session_t`,
  2135. `mysqlx_session_options_t`, `mysqlx_schema_t`,
  2136. `mysqlx_collection_t`, `mysqlx_table_t`, `mysqlx_stmt_t`,
  2137. `mysqlx_result_t`, `mysqlx_row_t`, `mysqlx_error_t`
  2138. @return the error number or 0 if no error
  2139. @ingroup xapi_diag
  2140. */
  2141. PUBLIC_API unsigned int mysqlx_error_num(void *obj);
  2142. /**
  2143. Get the number of warnings generated by a statement.
  2144. @param res result handle
  2145. @return the number of warnings stored in the result
  2146. @ingroup xapi_diag
  2147. */
  2148. PUBLIC_API unsigned int mysqlx_result_warning_count(mysqlx_result_t *res);
  2149. /**
  2150. Get the next warning from the result.
  2151. This function returns a handle to a warning which can be examined using
  2152. the same functions used for errors: `mysqlx_error_num()` and
  2153. `mysqlx_error_message()`.
  2154. @param res result handle
  2155. @return handle to the next warning from the result or
  2156. NULL if there is no more warnings left to return.
  2157. @note The warning handle returned by a previous call is invalidated.
  2158. @ingroup xapi_diag
  2159. */
  2160. PUBLIC_API mysqlx_error_t *
  2161. mysqlx_result_next_warning(mysqlx_result_t *res);
  2162. /**
  2163. Create index for a collection.
  2164. This function creates a named index in the collection using a JSON index
  2165. specification.
  2166. @param coll collection to create the index for
  2167. @param name name for the index to be created
  2168. @param idx_spec index specification as a JSON string
  2169. @see @ref indexing for information on how to define document
  2170. collection indexes.
  2171. @return `RESULT_OK` - on success; `RESULT_ERR` - on error
  2172. The error handle can be obtained from the collection
  2173. using `mysqlx_error()` function.
  2174. @ingroup xapi_ddl
  2175. */
  2176. PUBLIC_API int
  2177. mysqlx_collection_create_index(mysqlx_collection_t *coll, const char *name,
  2178. const char *idx_spec);
  2179. /**
  2180. Drop index on a collection
  2181. This function drops an index in a collection
  2182. with a specific name
  2183. @param coll collection whose index should be dropped
  2184. @param name name of the index to be dropped
  2185. @return `RESULT_OK` - on success; `RESULT_ERR` - on error
  2186. The error handle can be obtained from the collection
  2187. using `mysqlx_error()` function.
  2188. @note The warning handle returned by a previous call is invalidated.
  2189. @ingroup xapi_ddl
  2190. */
  2191. PUBLIC_API int
  2192. mysqlx_collection_drop_index(mysqlx_collection_t *coll, const char *name);
  2193. #ifdef __cplusplus
  2194. }
  2195. #endif
  2196. /**@}*/
  2197. #endif /* __MYSQLX_H__*/