MySQL Connector/C++
MySQL connector library for C and C++ applications
Functions
DDL statements

Functions

int mysqlx_schema_create (mysqlx_session_t *sess, const char *schema)
 Create a schema. More...
 
int mysqlx_schema_drop (mysqlx_session_t *sess, const char *schema)
 Drop a schema. More...
 
int mysqlx_collection_create (mysqlx_schema_t *schema, const char *collection)
 Create a new collection in a specified schema. More...
 
mysqlx_collection_options_tmysqlx_collection_options_new ()
 Allocate a new create/modify collection options data. More...
 
int mysqlx_collection_options_set (mysqlx_collection_options_t *options,...)
 Set collection options. More...
 
int mysqlx_collection_create_with_options (mysqlx_schema_t *schema, const char *collection, mysqlx_collection_options_t *options)
 Create a new collection in a specified schema. More...
 
int mysqlx_collection_create_with_json_options (mysqlx_schema_t *schema, const char *collection, const char *json_options)
 Create a new collection in a specified schema. More...
 
int mysqlx_collection_drop (mysqlx_schema_t *schema, const char *collection)
 Drop an existing collection in a specified schema. More...
 
int mysqlx_collection_create_index (mysqlx_collection_t *coll, const char *name, const char *idx_spec)
 Create index for a collection. More...
 
int mysqlx_collection_drop_index (mysqlx_collection_t *coll, const char *name)
 Drop index on a collection. More...
 

Detailed Description

Note
To create a table or a view, use reqular SQL statement.

Function Documentation

◆ mysqlx_schema_create()

int mysqlx_schema_create ( mysqlx_session_t sess,
const char *  schema 
)

Create a schema.

Parameters
sesssession handle
schemathe name of the schema to be created
Returns
RESULT_OK - on success; RESULT_ERROR - on error The error handle can be obtained from the session using mysqlx_error() function.

◆ mysqlx_schema_drop()

int mysqlx_schema_drop ( mysqlx_session_t sess,
const char *  schema 
)

Drop a schema.

Parameters
sesssession handle
schemathe name of the schema to be dropped
Returns
RESULT_OK - on success; RESULT_ERROR - on error The error handle can be obtained from the session using mysqlx_error() function.

◆ mysqlx_collection_create()

int mysqlx_collection_create ( mysqlx_schema_t schema,
const char *  collection 
)

Create a new collection in a specified schema.

Parameters
schemaschema handle
collectioncollection name to create
Returns
RESULT_OK - on success; RESULT_ERROR - on error The error handle can be obtained from the session using mysqlx_error() function.

◆ mysqlx_collection_options_new()

mysqlx_collection_options_t * mysqlx_collection_options_new ( )

Allocate a new create/modify collection options data.

Returns
collection create/modify options handle
Note
The session returned by the function must be properly freed using mysqlx_free().

◆ mysqlx_collection_options_set()

int mysqlx_collection_options_set ( mysqlx_collection_options_t options,
  ... 
)

Set collection options.

Parameters
optionshandle created by mysqlx_collection_options_new() function
...variable parameters list consisting of (option, value) pairs terminated by PARAM_END.
Returns
RESULT_OK - on success; RESULT_ERROR - on error The error handle can be obtained from the options using mysqlx_error() function.

The variable parameter list is of the form

OPT_COLLECTION_O1(val1), OPT_COLLECTION_O2(val2), ..., PARAM_END

or, equivalently,

MYSQLX_OPT_COLLECTION_O1, val1, MYSQLX_OPT_COLLECTION_02, val2,...,

PARAM_END

Possible options are defined by enumerations mysqlx_collection_opt_t and mysqlx_collection_validation_opt_t. Type of option value vali (number, string, etc.) must match the option MYSQLX_OPT_COLLECTION_Oi, otherwise this value along with all the sequential options and values are most likely to be corrupted.

◆ mysqlx_collection_create_with_options()

int mysqlx_collection_create_with_options ( mysqlx_schema_t schema,
const char *  collection,
mysqlx_collection_options_t options 
)

Create a new collection in a specified schema.

Parameters
schemaschema handle
collectioncollection name to create
optionshandle created by mysqlx_collection_options_new() function
Returns
RESULT_OK - on success; RESULT_ERROR - on error The error handle can be obtained from the session using mysqlx_error() function.

◆ mysqlx_collection_create_with_json_options()

int mysqlx_collection_create_with_json_options ( mysqlx_schema_t schema,
const char *  collection,
const char *  json_options 
)

Create a new collection in a specified schema.

Parameters
schemaschema handle
collectioncollection name to create
json_optionsjson with options:
{
"reuseExisting": true,
"validation":
{
"level": "Strict",
"schema":
{
"id": "http://json-schema.org/geo",
"$schema": "http://json-schema.org/draft-06/schema#",
"description": "A geographical coordinate",
"type": "object",
"properties":
{
"latitude":
{
"type": "number"
},
"longitude":
{
"type": "number"
}
},
"required": ["latitude", "longitude"]
}
}
}
}

Document keys:

Returns
RESULT_OK - on success; RESULT_ERROR - on error The error handle can be obtained from the session using mysqlx_error() function.

◆ mysqlx_collection_drop()

int mysqlx_collection_drop ( mysqlx_schema_t schema,
const char *  collection 
)

Drop an existing collection in a specified schema.

Parameters
schemaschema handle
collectioncollection name to drop
Returns
RESULT_OK - on success; RESULT_ERROR - on error The error handle can be obtained from the session using mysqlx_error() function

◆ mysqlx_collection_create_index()

int mysqlx_collection_create_index ( mysqlx_collection_t coll,
const char *  name,
const char *  idx_spec 
)

Create index for a collection.

This function creates a named index in the collection using a JSON index specification.

Parameters
collcollection to create the index for
namename for the index to be created
idx_specindex specification as a JSON string
See also
Indexing Document Collections for information on how to define document collection indexes.
Returns
RESULT_OK - on success; RESULT_ERROR - on error The error handle can be obtained from the collection using mysqlx_error() function.

◆ mysqlx_collection_drop_index()

int mysqlx_collection_drop_index ( mysqlx_collection_t coll,
const char *  name 
)

Drop index on a collection.

This function drops an index in a collection with a specific name

Parameters
collcollection whose index should be dropped
namename of the index to be dropped
Returns
RESULT_OK - on success; RESULT_ERROR - on error The error handle can be obtained from the collection using mysqlx_error() function.
Note
The warning handle returned by a previous call is invalidated.