docs/en/14-reference/05-connector/10-cpp.md
C/C++ developers can use the TDengine client driver (i.e., C/C++ connector) to develop their own applications to connect to the TDengine cluster to complete data storage, query, and other functions. The API of the TDengine client driver is similar to the C API of MySQL. When using the application, it is necessary to include the TDengine header file, which lists the function prototypes of the provided API; the application must also link to the corresponding dynamic library on the platform.
The TDengine client driver provides the taos dynamic library, which supports two connection methods: WebSocket connection and native connection. The difference between the two connection methods is that WebSocket connection does not require the client and server versions to match completely, while native connection requires version matching; in terms of performance, the WebSocket connection method is close to the native connection.
:::tip
It is generally recommended to use the WebSocket connection method.
:::
Regardless of the connection method used, you need to import the taos.h header file and link the taos dynamic library:
#include "taos.h"
After installing the TDengine client or server, the taos.h header file is located at:
/usr/local/taos/includeC:\TDengine\include/usr/local/includeThe dynamic library of the TDengine client driver is located at:
/usr/local/taos/driver/libtaos.soC:\TDengine\driver\taos.dll/usr/local/lib/libtaos.dylibTDengine client driver supports two connection methods, developers can flexibly choose according to needs.
Native connection is the default connection method of TDengine. You can directly call taos_connect() to establish a connection:
// Native connection example
TAOS *taos = taos_connect(ip, user, password, database, port);
WebSocket connection requires setting the driver type first, and then calling taos_connect():
// WebSocket connection example
taos_options(TSDB_OPTION_DRIVER, "websocket");
TAOS *taos = taos_connect(ip, user, password, database, port);
:::warning Important Notes
taos_options(TSDB_OPTION_DRIVER, arg) must be called at the beginning of the program to set the driver type, and can only be called once. Once set, the configuration is valid for the entire program life cycle and cannot be changed.
:::
TDengine client driver supports multiple platforms. For a list of supported platforms, please refer to: Supported Platforms List
| TDengine Client Version | Major Changes | TDengine Version |
|---|---|---|
| 3.3.6.0 | Provides comprehensive support for SQL execution, parameter binding, schemaless writing, and data subscription. | 3.3.2.0 and higher |
The version number of the TDengine client driver strictly corresponds to the version number of the TDengine server. It is strongly recommended to use the client driver with the same version as the TDengine server. Although the lower version of the client driver can be compatible with the higher version of the server when the first three segments of the version number are the same (that is, only the fourth segment of the version number is different), this is not recommended. It is strongly not recommended to use the higher version of the client driver to access the lower version of the server.
Please refer to: Error Codes.
This section shows the example code of common access methods of TDengine cluster using client driver.
Synchronous query example: Synchronous Query
Asynchronous query example: Asynchronous Query
Parameter binding example: Parameter Binding
Schemaless write example: Schemaless Write
Subscription and consumption example: Subscription and Consumption
:::info For more example codes and downloads, please see GitHub. :::
Synchronous query example: Synchronous Query
Asynchronous query example: Asynchronous Query
Parameter binding example: Parameter Binding
Schemaless write example: Schemaless Write
Subscription and consumption example: Subscription and Consumption
:::info For more example codes and downloads, please see GitHub. :::
The following introduces the basic API, synchronous query API, asynchronous query API, parameter binding API, schemaless write API and data subscription API of TDengine client driver respectively.
Connection method compatibility description: TDengine client driver supports WebSocket connection and native connection. Most APIs have the same functions in both connection methods, but a few APIs have functional differences:
Native connection: All APIs provide full functional support.
WebSocket connection: Most APIs are fully functional, and a few APIs only return a success status but do not perform actual operations.
Usage:
taos_options(TSDB_OPTION_DRIVER, "websocket") to set the driver type first, and then call other APIs.WebSocket connection function difference description:
| API | Support Status | Interface Description | Usage Restrictions |
|---|---|---|---|
| taos_connect_auth | Not supported | MD5 encrypted password connection | Only returns a success status, no actual operation is performed |
| taos_set_notify_cb | Not supported | Set an event callback function | Only returns a success status, no actual operation is performed |
| tmq_get_connect | Not supported | Get a TMQ connection handle | Only returns a success status, no actual operation is performed |
| taos_options_connection | Partially supported | Set client connection options | Character set settings are not supported, and the UTF-8 character set is fixed |
These APIs are fully functional in native connection mode. If you need to use the above functions, it is recommended to choose native connection mode. Future versions will gradually improve the functional support of WebSocket connection.
Note: WebSocket connection requires calling taos_options(TSDB_OPTION_DRIVER, "websocket") to set the driver type at the beginning of the program, and it can only be called once. Once set, the configuration is valid for the entire program life cycle and cannot be changed.
The basic API is used to establish database connections and provide a runtime environment for other APIs.
int taos_init()
taos_connect() is invoked, so it is generally not necessary to call it manually.0: Success, non-0: Failure, you can call the function taos_errstr(NULL) for more detailed error information.void taos_cleanup()
int taos_options(TSDB_OPTION option, const void * arg, ...)
TSDB_OPTION_LOCALE), character set (TSDB_OPTION_CHARSET), timezone (TSDB_OPTION_TIMEZONE), configuration file path (TSDB_OPTION_CONFIGDIR), and driver type (TSDB_OPTION_DRIVER). Locale, character set, and timezone default to the current settings of the operating system. The driver type can be either the native interface(native) or the WebSocket interface(websocket), with the default being websocket.TSDB_OPTION_DRIVER) must be called at the beginning of the program and can only be called once.option: [Input] Setting item type.arg: [Input] Setting item value.0: Success, -1: Failure.int taos_options_connection(TAOS *taos, TSDB_OPTION_CONNECTION option, const void *arg, ...)
TSDB_OPTION_CONNECTION_CHARSET), time zone setting(TSDB_OPTION_CONNECTION_TIMEZONE), user IP setting(TSDB_OPTION_CONNECTION_USER_IP), and user APP setting(TSDB_OPTION_CONNECTION_USER_APP), and connector info setting(TSDB_OPTION_CONNECTION_CONNECTOR_INFO).taos: returned by taos_connect.option: option name.arg: option value.0: success.others: fail.char *taos_get_client_info()
TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port);
TSDB_CODE_MND_WRONG_TOTP_CODE, in which case the application should ask user for the TOTP code and call taos_connect_totp to try again.
:::TAOS *taos_connect_totp(const char *ip, const char *user, const char *pass, const char* totp, const char *db, uint16_t port);
taos_connect but support using TOTP as 2FA method.taos_connect.v3.4.0.0 and aboveTAOS *taos_connect_token(const char *ip, const char *token, const char *db, uint16_t port);
taos_connect but use token instead of user name and password for authentication.v3.4.0.0 and aboveTAOS *taos_connect_auth(const char *host, const char *user, const char *auth, const char *db, uint16_t port)
int taos_get_connection_info(TAOS *taos, TSDB_CONNECTION_INFO info, char* buffer, int* len);
Interface Description: Get connection information。
Parameter Description:
Supported Information Items:
| Key | Description |
|---|---|
| TSDB_CONNECTION_INFO_USER | The name of the user who create this connection |
| TSDB_CONNECTION_INFO_TOKEN | The name of the token which was used to create this connection (if the connection was created via a token) |
Return Value: Error code.
Supported Versions: v3.4.0.0 and above
void taos_set_option(OPTIONS *options, const char *key, const char *value)
Interface Description: Adds a connection configuration item (key-value pair) to the OPTIONS structure. This function constructs the connection configuration, which takes effect when taos_connect_with() is called.
Parameter Description:
options: [Input] A pointer to a valid OPTIONS structure used to store the connection configuration items.key: [Input] The key name (string) of the configuration item. Supported key names are listed in the table below.value: [Input] The value (string) of the configuration item, corresponding to the specific configuration content of key.Supported Configuration Items:
| Key | Applicable Connection Method | Description |
|---|---|---|
| ip | Native/WebSocket | FQDN or IP address of any node in the TDengine cluster |
| user | Native/WebSocket | Username |
| pass | Native/WebSocket | Password |
| db | Native/WebSocket | Database name |
| port | Native/WebSocket | Service port number. The default port for Native connections is 6030, and the default port for WebSocket connections is 6041. |
| charset | Native | Character set |
| timezone | Native/WebSocket | Time zone |
| userIp | Native/WebSocket | User IP address |
| userApp | Native/WebSocket | User app name |
| connectorInfo | Native | Connector information |
| adapterList | WebSocket | List of taosAdapter addresses, used for load balancing and failover. Multiple addresses are separated by commas, in the format host1:port1,host2:port2,.... They have higher priority than the ip parameter. |
| compression | WebSocket | Data compression switch. 0: Disabled, 1: Enabled. Default is 0. |
| connRetries | WebSocket | Maximum number of retries on connection failure. Default is 5. |
| retryBackoffMs | WebSocket | Initial wait time (milliseconds) on connection failure. This value increases exponentially with consecutive failures until the maximum wait time is reached. Default is 200. |
| retryBackoffMaxMs | WebSocket | Maximum wait time (milliseconds) on connection failure. Default is 2000. |
| token | WebSocket | Cloud service authentication token |
| wsTlsMode | WebSocket | TLS encryption modes: |
0: Disable TLS encryption. If the server enables TLS, the client will automatically upgrade the connection.
1: Enable TLS encryption, but do not verify the server certificate.
2: Enable TLS encryption and verify the server certificate, but not the hostname.
3: Enable TLS encryption and verify both the server certificate and hostname (the server certificate must include SAN; CN will be ignored). Default is 0. | | wsTlsVersion | WebSocket | List of TLS protocol versions, separated by commas. Optional values: TLSv1.2, TLSv1.3. The default value is TLSv1.3. | | wsTlsCa | WebSocket | The client uses the path to the CA certificate file or the certificate content in PEM format to verify the server certificate. This certificate should be the CA certificate that issued the server certificate. |
Important Notes:
Supported Versions: v3.3.8.12 and above
TAOS *taos_connect_with(const OPTIONS *options)
options: [Input] Points to a valid OPTIONS structure containing the connection configuration options added via taos_set_option(). If NULL or the configuration options are empty, default connection parameters will be used.v3.3.8.12 and abovechar *taos_get_server_info(TAOS *taos)
taos_connect() function.int taos_select_db(TAOS *taos, const char *db)
db.taos_connect() function.0: Success, non-0: Failure, refer to the error code page for details.int taos_get_current_db(TAOS *taos, char *database, int len, int *required)
taos_connect() function.0: Success, -1: Failure, detailed error information can be obtained by calling the function taos_errstr(NULL).
int taos_set_notify_cb(TAOS *taos, __taos_notify_fn_t fp, void *param, int type)
taos_connect() function.0: Success, -1: Failure, detailed error information can be obtained by calling the function taos_errstr(NULL).void taos_close(TAOS *taos)
taos_connect() function.This section introduces APIs that are all synchronous interfaces. After being called by the application, they will block and wait for a response until a result or error message is received.
TAOS_RES* taos_query(TAOS *taos, const char *sql)
taos_connect() function.NULL. Instead, the taos_errno() function must be called to parse the error code in the result set.
0: success, -1: failure, for details please call the taos_errstr function to get the error message.int taos_result_precision(TAOS_RES *res)
0: millisecond, 1: microsecond, 2: nanosecond.TAOS_ROW taos_fetch_row(TAOS_RES *res)
NULL: success, NULL: failure, you can call taos_errstr(NULL) for more detailed error information.int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows)
int taos_num_fields(TAOS_RES *res) and int taos_field_count(TAOS_RES *res)
int* taos_fetch_lengths(TAOS_RES *res)
int taos_affected_rows(TAOS_RES *res)
TAOS_FIELD *taos_fetch_fields(TAOS_RES *res)
taos_num_fields() to parse the data of a tuple (a row) returned by taos_fetch_row().NULL: successful, returns a pointer to a TAOS_FIELD structure, each element representing the metadata of a column. NULL: failure.TAOS_FIELD_E *taos_fetch_fields_e(TAOS_RES *res)
taos_num_fields(), it can be used to parse the data of a tuple (a row) returned by taos_fetch_row(). In addition to the basic information provided by TAOS_FIELD, TAOS_FIELD_E also includes precision and scale information for the data type.NULL: Success, returns a pointer to a TAOS_FIELD_E structure, where each element represents the metadata of a column. NULL: Failure.int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields)
str buffer for logging or debugging output.str: [Output] A user-provided character buffer that receives the entire line of formatted text. Ensure that the capacity meets the output requirements. If the result exceeds the buffer size, it will be truncated (possibly incomplete output).fields: [Input] An array of column metadata, returned by taos_fetch_fields(). Used to format each column according to its column type.num_fields: [Input] The number of columns, typically the return value of taos_num_fields().>=0 indicates the number of characters actually written to str (excluding the trailing '\0'); <0 indicates a failure error code.void taos_stop_query(TAOS_RES *res)
void taos_free_result(TAOS_RES *res)
taos_consume() or other functions to fetch query results after releasing resources, it will cause the application to crash.char *taos_errstr(TAOS_RES *res)
int taos_errno(TAOS_RES *res)
:::note
From version 2.0, TDengine recommends that each thread in a database application establishes its own connection, or builds a connection pool based on the thread, rather than sharing the connection (TAOS*) structure across different threads in the application. Operations such as queries and writes based on the TAOS structure are thread-safe, but stateful statements like "USE statement" may interfere with each other across threads. Additionally, the C language connector can dynamically establish new database-oriented connections as needed (this process is invisible to users), and it is recommended to call taos_close() to close the connection only when the program is about to exit.
Another point to note is that during the execution of the aforementioned synchronous APIs, APIs like pthread_cancel should not be used to forcibly terminate threads, as this involves synchronization operations of some modules and may cause issues including but not limited to deadlocks.
:::
TDengine also offers higher-performance asynchronous APIs for data insertion and query operations. Under the same hardware and software conditions, the asynchronous API processes data insertions 2 to 4 times faster than the synchronous API. Asynchronous APIs use a non-blocking call method, returning immediately before a specific database operation is actually completed. The calling thread can then handle other tasks, thereby enhancing the overall application performance. Asynchronous APIs are particularly advantageous under conditions of severe network latency.
Asynchronous APIs require the application to provide corresponding callback functions, with parameters set as follows: the first two parameters are consistent, the third depends on the specific API. The first parameter, param, is provided by the application during the asynchronous API call for use in the callback to retrieve the context of the operation, depending on the implementation. The second parameter is the result set of the SQL operation; if null, such as in an insert operation, it means no records are returned; if not null, such as in a select operation, it means records are returned.
Asynchronous APIs are relatively demanding for users, who may choose to use them based on specific application scenarios. Below are two important asynchronous APIs:
void taos_query_a(TAOS *taos, const char *sql, void (*fp)(void *param, TAOS_RES *, int code), void *param);
taos_connect() function.code indicates whether the operation was successful (0 for success, negative for failure; call taos_errstr() to get the reason for failure). The application should mainly handle the second parameter TAOS_RES *, which is the result set returned by the query.void taos_fetch_rows_a(TAOS_RES *res, void (*fp)(void *param, TAOS_RES *, int numOfRows), void *param);
taos_query_a().taos_query_a().param is a user-defined parameter structure passed to the callback function; numOfRows is the number of rows of data retrieved (not the function of the entire result set). In the callback function, the application can iterate forward through the batch records by calling taos_fetch_row(). After reading all the records in a block, the application needs to continue calling taos_fetch_rows_a() in the callback function to process the next batch of records until the returned number of rows numOfRows is zero (results are completely returned) or the number of rows is negative (query error).TDengine's asynchronous APIs all use a non-blocking call mode. Applications can open multiple tables simultaneously with multiple threads and can perform queries or insertions on each opened table at the same time. It should be noted that client applications must ensure that operations on the same table are completely serialized, meaning that a second insertion or query operation cannot be performed on the same table until the first operation is completed (has not returned).
In addition to directly calling taos_query() for queries, TDengine also offers a Prepare API that supports parameter binding, similar in style to MySQL, currently only supporting the use of a question mark ? to represent the parameter to be bound.
Starting from version 3.3.5.0, TDengine has significantly simplified the usage interface of the old parameter binding. This avoids the resource consumption of SQL syntax parsing when writing data through the parameter binding interface, and through batch binding, significantly improves writing performance in most cases. The typical operation steps are as follows:
taos_stmt2_init() to create a parameter binding object;taos_stmt2_prepare() to parse INSERT or SELECT statements;taos_stmt2_bind_param() to bind multiple subtables to a single supertable, with each subtable able to bind multiple rows of data;taos_stmt2_exec() to execute the prepared batch processing command;taos_stmt2_close() to release all resources.Note: If taos_stmt2_exec() executes successfully and there is no need to change the SQL statement, then it is possible to reuse the parsing result of taos_stmt2_prepare() and directly proceed to steps 3 to 4 to bind new data. However, if there is an error in execution, it is not recommended to continue working in the current context. Instead, it is advisable to release resources and start over from the taos_stmt2_init() step. You can check the specific error reason through taos_stmt2_error.
The difference between stmt2 and stmt is:
insert into stb(...tbname,...)values(?,?,?) syntax, while stmt does not support it.?.stmt upgrade stmt2 changes:
taos_stmt_init() to taos_stmt2_init(), add TAOS_STMT2_OPTION.taos_stmt_prepare() to taos_stmt2_prepare().taos_stmt_set_tbname_tags, taos_stmt_bind_param() and taos_stmt_add_batch to taos_stmt2_bind_param(), change TAOS_MULTI_BIND to TAOS_STMT2_BINDV.taos_stmt_execute() to taos_stmt2_exec(), add affected_rows parameter.taos_stmt_close() to taos_stmt2_close().The specific functions related to the interface are as follows (you can also refer to the stmt2_insert_demo.c file for how to use the corresponding functions):
TAOS_STMT2 *taos_stmt2_init(TAOS *taos, TAOS_STMT2_OPTION *option)
taos_connect() function.singleStbInsert and singleTableBindOnce need to be set to true; when selecting asynchronous execution, the callback function asyncExecFn and parameter userdata need to be set.NULL: Success, returns a pointer to a TAOS_STMT2 structure representing the precompiled SQL statement object. NULL: Failure, please call taos_stmt_errstr() function for error details.int taos_stmt2_prepare(TAOS_STMT2 *stmt, const char *sql, unsigned long length)
0: Success. Non-0: Failure, please refer to the error code page for details.int taos_stmt2_bind_param(TAOS_STMT2 *stmt, TAOS_STMT2_BINDV *bindv, int32_t col_idx)
count represents the number of tables to be bound, one tbnames can correspond to one set of tags and multiple sets of bind_cols; if it is a SELECT statement, only bind_cols needs to be bound.-1 means full column binding.0: Success. Non-0: Failure, please refer to the error code page for details.int taos_stmt2_exec(TAOS_STMT2 *stmt, int *affected_rows)
0: Success. Non-0: Failure, please refer to the error code page for details.int taos_stmt2_close(TAOS_STMT2 *stmt)
0: Success. Non-0: Failure, please refer to the error code page for details.int taos_stmt2_get_fields(TAOS_STMT2 *stmt, int *count, TAOS_FIELD_ALL **fields)
? order.? in the bound SQL.? order. If it is a SELECT statement, this structure returns NULL.0: Success. Non-0: Failure, please refer to the error code page for details.void taos_stmt2_free_fields(TAOS_STMT2 *stmt, TAOS_FIELD_ALL *fields)
TAOS_RES *taos_stmt2_result(TAOS_STMT2 *stmt)
char *taos_stmt2_error(TAOS_STMT2 *stmt)
Starting from versions 2.1.1.0 and 2.1.2.0, TDengine has significantly improved the parameter binding interface support for data writing (INSERT) scenarios. This avoids the resource consumption of SQL syntax parsing when writing data through the parameter binding interface, thereby significantly improving writing performance in most cases. The typical operation steps are as follows:
taos_stmt_init() to create a parameter binding object;taos_stmt_prepare() to parse the INSERT statement;taos_stmt_set_tbname() to set the table name;taos_stmt_set_tbname_tags() to set the values of the table name and TAGS;taos_stmt_bind_param_batch() to set the VALUES in a multi-row manner, or call taos_stmt_bind_param() to set the VALUES in a single-row manner;taos_stmt_add_batch() to add the currently bound parameters to the batch processing;taos_stmt_execute() to execute the prepared batch processing command;taos_stmt_close() to release all resources.Note: If taos_stmt_execute() is successful and there is no need to change the SQL statement, then it is possible to reuse the parsing result of taos_stmt_prepare() and directly proceed to steps 3 to 6 to bind new data. However, if there is an error in execution, it is not recommended to continue working in the current context. Instead, it is advisable to release resources and start over from the taos_stmt_init() step.
The specific functions related to the interface are as follows (you can also refer to the prepare.c file for how to use the corresponding functions):
TAOS_STMT* taos_stmt_init(TAOS *taos)
taos_connect() function.NULL: Success, returns a pointer to a TAOS_STMT structure representing the precompiled SQL statement object. NULL: Failure, please call taos_stmt_errstr() function for error details.int taos_stmt_prepare(TAOS_STMT *stmt, const char *sql, unsigned long length)
0: Success. Non-0: Failure, please refer to the error code page for details.int taos_stmt_bind_param(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind)
taos_stmt_bind_param_batch(), but can support non-INSERT type SQL statements.0: Success. Non-0: Failure, please refer to the error code page for details.int taos_stmt_set_tbname(TAOS_STMT* stmt, const char* name)
? placeholder, this function can be used to bind a specific table name.0: Success. Non-0: Failure, please refer to the error code page for details.int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_MULTI_BIND* tags)
? placeholders, this function can be used to bind specific table names and specific TAGS values. The most typical scenario is the INSERT statement that uses the auto-create table feature (the current version does not support specifying specific TAGS columns). The number of columns in the TAGS parameter must match exactly the number of TAGS required by the SQL statement.0: Success. Non-0: Failure, please refer to the error code page for details.int taos_stmt_bind_param_batch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind)
0: Success. Non-0: Failure, please refer to the error code page for details.int taos_stmt_add_batch(TAOS_STMT *stmt)
taos_stmt_bind_param() or taos_stmt_bind_param_batch() again to bind new parameters. Note that this function only supports INSERT/IMPORT statements; if it is a SELECT or other SQL statements, it will return an error.
0: Success. Non-0: Failure, please refer to the error code page for details.int taos_stmt_execute(TAOS_STMT *stmt)
0: Success. Non-0: Failure, please refer to the error code page for details.int taos_stmt_affected_rows(TAOS_STMT *stmt)
int taos_stmt_affected_rows_once(TAOS_STMT *stmt)
TAOS_RES* taos_stmt_use_result(TAOS_STMT *stmt)
taos_free_result() should be called to release resources after use.
NULL: Success, returns a pointer to the query result set. NULL: Failure, please call taos_stmt_errstr() function for error details.int taos_stmt_close(TAOS_STMT *stmt)
0: Success. Non-0: Failure, please refer to the error code page for details.char * taos_stmt_errstr(TAOS_STMT *stmt)
In addition to using SQL or parameter binding APIs to insert data, you can also use a Schemaless method for insertion. Schemaless allows you to insert data without having to pre-create the structure of supertables/subtables. The TDengine system will automatically create and maintain the required table structure based on the data content written. For more details on how to use Schemaless, see the Schemaless Insert section. Here, we introduce the accompanying C/C++ API.
TAOS_RES* taos_schemaless_insert(TAOS* taos, const char* lines[], int numLines, int protocol, int precision)
taos_connect() function.taos_errstr(), or get the error code using taos_errno(). In some cases, the returned TAOS_RES may be NULL, in which case taos_errno() can still be safely called to obtain the error code information.
The returned TAOS_RES must be managed by the caller to avoid memory leaks.Explanation
Protocol type is an enumeration type, including the following three formats:
The definition of timestamp resolution, defined in the taos.h file, is as follows:
Note that the timestamp resolution parameter only takes effect when the protocol type is SML_LINE_PROTOCOL.
For OpenTSDB's text protocols, timestamp parsing follows its official parsing rules — based on the number of characters contained in the timestamp to determine the time precision.
Other related schemaless interfaces
TAOS_RES *taos_schemaless_insert_with_reqid(TAOS *taos, char *lines[], int numLines, int protocol, int precision, int64_t reqid)
taos_connect() function.taos_errstr(), or get the error code using taos_errno(). In some cases, the returned TAOS_RES may be NULL, in which case taos_errno() can still be safely called to obtain the error code information.
The returned TAOS_RES must be managed by the caller to avoid memory leaks.TAOS_RES *taos_schemaless_insert_raw(TAOS *taos, char *lines, int len, int32_t *totalRows, int protocol, int precision)
lines pointer and its length len, addressing the issue where data containing '\0' gets truncated.
taos_connect() function.lines.taos_errstr(), and error codes with taos_errno(). In some cases, the returned TAOS_RES may be NULL, but taos_errno() can still be safely called to obtain error code information.
The returned TAOS_RES must be freed by the caller to avoid memory leaks.TAOS_RES *taos_schemaless_insert_raw_with_reqid(TAOS *taos, char *lines, int len, int32_t *totalRows, int protocol, int precision, int64_t reqid)
lines pointer and its length len, addressing the issue where data containing '\0' gets truncated. The reqid parameter is passed to track the entire function call chain.
taos_connect() function.lines.taos_errstr(), and error codes with taos_errno(). In some cases, the returned TAOS_RES may be NULL, but taos_errno() can still be safely called to obtain error code information.
The returned TAOS_RES must be freed by the caller to avoid memory leaks.TAOS_RES *taos_schemaless_insert_ttl(TAOS *taos, char *lines[], int numLines, int protocol, int precision, int32_t ttl)
ttl parameter is used to control the expiration time of the table's TTL.
taos_connect() function.taos_errstr(), and error codes with taos_errno(). In some cases, the returned TAOS_RES may be NULL, but taos_errno() can still be safely called to obtain error code information.
The returned TAOS_RES must be freed by the caller to avoid memory leaks.TAOS_RES *taos_schemaless_insert_ttl_with_reqid(TAOS *taos, char *lines[], int numLines, int protocol, int precision, int32_t ttl, int64_t reqid)
taos_connect() function.taos_errstr(), or get the error code using taos_errno(). In some cases, the returned TAOS_RES may be NULL, in which case taos_errno() can still be safely called to obtain error code information.
The returned TAOS_RES must be freed by the caller to avoid memory leaks.TAOS_RES *taos_schemaless_insert_raw_ttl(TAOS *taos, char *lines, int len, int32_t *totalRows, int protocol, int precision, int32_t ttl)
taos_connect() function.taos_errstr(), or get the error code using taos_errno(). In some cases, the returned TAOS_RES may be NULL, in which case taos_errno() can still be safely called to obtain error code information.
The returned TAOS_RES must be freed by the caller to avoid memory leaks.TAOS_RES *taos_schemaless_insert_raw_ttl_with_reqid(TAOS *taos, char *lines, int len, int32_t *totalRows, int protocol, int precision, int32_t ttl, int64_t reqid)
taos_connect() function.taos_errstr(), or get the error code using taos_errno(). In some cases, the returned TAOS_RES may be NULL, in which case taos_errno() can still be safely called to obtain error code information.
The returned TAOS_RES must be freed by the caller to avoid memory leaks.Description:
const char *tmq_err2str(int32_t code)
tmq_conf_t *tmq_conf_new()
NULL: Success, returns a pointer to a tmq_conf_t structure, which is used to configure the behavior and features of TMQ. NULL: Failure, you can call the function taos_errstr(NULL) for more detailed error information.tmq_conf_res_t tmq_conf_set(tmq_conf_t *conf, const char *key, const char *value)
Interface Description: Sets the configuration items in the TMQ configuration object, used to configure consumption parameters.
Return Value: Returns a tmq_conf_res_t enum value, indicating the result of the configuration setting. tmq_conf_res_t defined as follows:
typedef enum tmq_conf_res_t {
TMQ_CONF_UNKNOWN = -2, // invalid key
TMQ_CONF_INVALID = -1, // invalid value
TMQ_CONF_OK = 0, // success
} tmq_conf_res_t;
void tmq_conf_set_auto_commit_cb(tmq_conf_t *conf, tmq_commit_cb *cb, void *param)
The definition of the auto-commit callback function is as follows:
typedef void(tmq_commit_cb(tmq_t *tmq, int32_t code, void *param))
void tmq_conf_destroy(tmq_conf_t *conf)
tmq_list_t *tmq_list_new()
NULL: Success, returns a pointer to a tmq_list_t structure. NULL: Failure, you can call the function taos_errstr(NULL) for more detailed error information.int32_t tmq_list_append(tmq_list_t *list, const char* topic)
0: Success. Non 0: Failure, you can call the function char *tmq_err2str(int32_t code) for more detailed error information.void tmq_list_destroy(tmq_list_t *list)
int32_t tmq_list_get_size(const tmq_list_t *list)
>=0: Success, returns the number of topics in the tmq_list_t structure. -1: Failure, indicates the input parameter list is NULL.char **tmq_list_to_c_array(const tmq_list_t *list)
NULL: Success, returns a C array, each element is a string pointer representing a topic name. NULL: Failure, indicates the input parameter list is NULL.tmq_t *tmq_consumer_new(tmq_conf_t *conf, char *errstr, int32_t errstrLen)
NULL: Success, returns a pointer to a tmq_t structure representing a TMQ consumer object. NULL: Failure, error information stored in the errstr parameter.int32_t tmq_subscribe(tmq_t *tmq, const tmq_list_t *topic_list)
0: Success. Non-0: Failure, the function char *tmq_err2str(int32_t code) can be called for more detailed error information.int32_t tmq_unsubscribe(tmq_t *tmq)
0: Success. Non-0: Failure, the function char *tmq_err2str(int32_t code) can be called for more detailed error information.int32_t tmq_subscription(tmq_t *tmq, tmq_list_t **topic_list)
0: Success. Non-0: Failure, the function char *tmq_err2str(int32_t code) can be called for more detailed error information.TAOS_RES *tmq_consumer_poll(tmq_t *tmq, int64_t timeout)
NULL: Success, returns a pointer to a TAOS_RES structure containing the received messages. NULL: indicates no data, the error code can be obtained through taos_errno (NULL), please refer to the reference manual for specific error message. TAOS_RES results are consistent with taos_query results, and information in TAOS_RES can be obtained through various query interfaces, such as schema, etc.int32_t tmq_consumer_close(tmq_t *tmq)
0: Success. Non-0: Failure, you can call the function char *tmq_err2str(int32_t code) to get more detailed error information.int32_t tmq_get_topic_assignment(tmq_t *tmq, const char *pTopicName, tmq_topic_assignment **assignment, int32_t *numOfAssignment)
0: Success. Non-0: Failure, you can call the function char *tmq_err2str(int32_t code) to get more detailed error information.void tmq_free_assignment(tmq_topic_assignment* pAssignment)
int64_t tmq_committed(tmq_t *tmq, const char *pTopicName, int32_t vgId)
>=0: Success, returns an int64_t value representing the committed offset. <0: Failure, the return value is the error code, you can call the function char *tmq_err2str(int32_t code) to get more detailed error information.int32_t tmq_commit_sync(tmq_t *tmq, const TAOS_RES *msg)
0: Success, the offset has been successfully committed. Non-0: Failure, you can call the function char *tmq_err2str(int32_t code) to get more detailed error information.void tmq_commit_async(tmq_t *tmq, const TAOS_RES *msg, tmq_commit_cb *cb, void *param)
int32_t tmq_commit_offset_sync(tmq_t *tmq, const char *pTopicName, int32_t vgId, int64_t offset)
0: Success, the offset has been successfully committed. Non-0: Failure, you can call the function char *tmq_err2str(int32_t code) to get more detailed error information.void tmq_commit_offset_async(tmq_t *tmq, const char *pTopicName, int32_t vgId, int64_t offset, tmq_commit_cb *cb, void *param)
Description
int64_t tmq_position(tmq_t *tmq, const char *pTopicName, int32_t vgId)
>=0: Success, returns an int64_t type value representing the offset of the current position. <0: Failure, the return value is the error code, you can call the function char *tmq_err2str(int32_t code) to get more detailed error information.int32_t tmq_offset_seek(tmq_t *tmq, const char *pTopicName, int32_t vgId, int64_t offset)
0: Success, non-0: Failure, you can call the function char *tmq_err2str(int32_t code) to get more detailed error information.int64_t tmq_get_vgroup_offset(TAOS_RES* res)
>=0: Success, returns an int64_t type value representing the offset of the current consumption position. <0: Failure, the return value is the error code, you can call the function char *tmq_err2str(int32_t code) to get more detailed error information.int32_t tmq_get_vgroup_id(TAOS_RES *res)
>=0: Success, returns an int32_t type value representing the ID of the virtual group (vgroup). <0: Failure, the return value is the error code, you can call the function char *tmq_err2str(int32_t code) to get more detailed error information.TAOS *tmq_get_connect(tmq_t *tmq)
NULL: Success, returns a TAOS * type pointer pointing to the connection handle with the TDengine database. NULL: Failure, illegal input parameters.const char *tmq_get_table_name(TAOS_RES *res)
NULL: Success, returns a const char * type pointer pointing to the table name string. NULL: Failure, illegal input parameters.tmq_res_t tmq_get_res_type(TAOS_RES *res)
typedef enum tmq_res_t {
TMQ_RES_INVALID = -1, // Invalid
TMQ_RES_DATA = 1, // Data type
TMQ_RES_TABLE_META = 2, // Metadata type
TMQ_RES_METADATA = 3 // Both metadata and data types, i.e., automatic table creation
} tmq_res_t;
const char *tmq_get_topic_name(TAOS_RES *res)
NULL: Success, returns a const char * type pointer pointing to the topic name string. NULL: Failure, illegal input parameters.const char *tmq_get_db_name(TAOS_RES *res)
NULL: Success, returns a const char * type pointer pointing to the database name string. NULL: Failure, illegal input parameters.