The SingleStore ODBC Driver
On this page
The SingleStore ODBC driver ("the driver") provides a simple and optimized way to connect to your SingleStore databases with ODBC-based programs, like BI & analytics tools, ETL & data integration tools, and bespoke applications.
The SingleStore ODBC driver is compatible with SingleStore version 7.
Getting Started with the SingleStore ODBC Driver
The SingleStore ODBC driver supports both Unicode and ANSI modes.
Prerequisites
The SingleStore ODBC driver is compatible with the following 64-bit platforms:
-
macOS (tested on 10.
14. 4) -
Windows 10
-
CentOS 7 and 8 / Debian 10 and 11
Download the SingleStore ODBC Driver
Download the SingleStore ODBC driver binaries for each supported operating system from its GitHub repository.
Install the SingleStore ODBC Driver
The SingleStore ODBC driver has two versions: Unicode-enabled or ANSI.
Both versions of drivers are provided in each download package, and are both installed onto your system by the installation program or script that comes with the download package.w
(for “wide characters”) for the Unicode driver and a
for the ANSI driver, at the end of the library names.
Note
You must specify Unicode
or ANSI
in the driver name in the configuration.SingleStore ODBC Unicode Driver
for Unicode and SingleStore ODBC ANSI Driver
for ANSI.
Install on Windows
SingleStore provides an MSI package to install the SingleStore ODBC driver on Windows.
The SingleStore ODBC driver supports the built-in ODBC Driver Manager on Windows, so nothing else needs to be installed.
Install on macOS
SingleStore provides a PKG package to install SingleStore ODBC Driver on Mac OS X.
The driver library requires the latest versions of OpenSSL and libiodbc libraries, which are not available natively.
Install Homebrew.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
To install the OpenSSL and libiodbc
libraries, run the following command in the terminal:
brew install openssl@1.1 libiodbc
Configure the data source in the /Library/ODBC/odbc.
file in the following format:
[SingleStore-server]
Description=SingleStore server
Driver=SingleStore ODBC [Unicode|ANSI] Driver
SERVER=<ip_address_or_hostname_of_SingleStore_cluster>
USER=<username>
PASSWORD=<password>
DATABASE=<database>
PORT=<port>
Specify Unicode
or ANSI
in the value for Driver
option.
To verify that the SingleStore ODBC driver is installed and ready to use:
-
Run the following command in the terminal:
cat /Library/ODBC/odbcinst.ini -
Verify that the output contains the following lines:
[ODBC] [ODBC Drivers] SingleStore ODBC Unicode Driver = Installed SingleStore ODBC ANSI Driver = Installed [SingleStore ODBC Unicode Driver] Driver = /Library/SingleStore/SingleStore-Connector-ODBC/libssodbcw.dylib [SingleStore ODBC ANSI Driver] Driver = /Library/SingleStore/SingleStore-Connector-ODBC/libssodbca.dylib
Warning
If there is an error while registering the driver during the installation process, add the following lines to the /Library/ODBC/odbcinst.
file:
[ODBC Drivers]
SingleStore ODBC Unicode Driver = Installed
[SingleStore ODBC Unicode Driver]
Driver = /Library/SingleStore/SingleStore-Connector-ODBC/libssodbcw.dylib
Install on macOS - Apple Silicon
To install the SingleStore ODBC Driver on an Apple silicon Mac running macOS:
-
(Optional) To clean up a previous installation, remove all the sections related to the SingleStore ODBC Driver from the following files:
Library/ODBC/odbc.ini Library/ODBC/odbcinst.ini
-
Install the Homebrew (
brew
) package forx86_
.64 -
Start a shell in
x86
mode:arch -x86_64 zsh -
Run the following commands in the x86 shell to install Homebrew:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" -
Add Homebrew (
brew
) to yourPATH
.In the output of the commands in the previous step, find the ==> Next Steps section, and run the specified commands. For example (replace the <username>
with your username):(echo; echo 'eval "$(/usr/local/bin/brew shellenv)"') >> /Users/<username>/.zprofileeval "$(/usr/local/bin/brew shellenv)"
-
-
Install the OpenSSL and libiodbc libraries.
arch -x86_64 brew install openssl@1.1 libiodbc -
After running the command, confirm that the following file exists:
/usr/local/opt/openssl@1.1/lib/libssl.1.1.dylib
-
Download the SingleStore ODBC Driver
x86_
package, for example64 singlestore-connector-odbc-1.
, and install it.1. 4-osx-x86_ 64. pkg sudo installer -pkg /path/to/package/singlestore-connector-odbc-1.1.4-osx-x86_64.pkg -target /
To verify that the SingleStore ODBC Driver is now installed, perform the following tasks:
-
Run the following command on the terminal:
cat /Library/ODBC/odbcinst.ini -
Verify that the output contains the following lines:
[ODBC] [ODBC Drivers] SingleStore ODBC Unicode Driver = Installed SingleStore ODBC ANSI Driver = Installed [SingleStore ODBC Unicode Driver] Driver = /Library/SingleStore/SingleStore-Connector-ODBC/libssodbcw.dylib [SingleStore ODBC ANSI Driver] Driver = /Library/SingleStore/SingleStore-Connector-ODBC/libssodbca.dylib
Install on Linux
-
Install UnixODBC.
CentOS:
sudo yum updatesudo yum install unixODBCDebian:
sudo apt-get updatesudo apt-get install unixodbc -
Install the
libssl.
andso. 1. 1 libcrypto.
libraries.so. 1. 1 CentOS:
-
Install the required dependencies:
sudo yum -y groupinstall "Development Tools" -
Download and extract the source code of OpenSSL 1.
1: wget https://www.openssl.org/source/openssl-1.1.1w.tar.gztar xvf openssl-1.1.1w.tar.gz -
Navigate to the extracted directory, and run the following command:
sudo ./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl -
Build OpenSSL:
make -j $(nproc) -
Install OpenSSL:
sudo make install -
Run the following command to verify that OpenSSL 1.
1 is installed. openssl version
Debian:
sudo apt-get updatewget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/openssl_1.1.1f-1ubuntu2.20_amd64.debsudo dpkg -i openssl_1.1.1f-1ubuntu2.20_amd64.debwget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2_amd64.debsudo dpkg -i libssl1.1_1.1.1f-1ubuntu2_amd64.deb -
-
If you plan to compile an application from source against SingleStore ODBC driver and UnixODBC, then you also need the development header files that define the ODBC API function prototypes, ODBC data types, etc.
To install UnixODBC development files you can use the following command: CentOS:
sudo yum updatesudo yum install unixODBC-develDebian:
sudo apt-get updatesudo apt-get install unixodbc-dev -
Download the binary tarball and extract the files.
Run the following command to extract the files (update the name of the tarball with extension before executing the command): tar xzvf <singlestore-odbc-connector-tarball-name> -
Configure the SingleStore ODBC driver as a UnixODBC driver on Linux.
-
Create a template file similar to the following, and name it (for example, SingleStore_
odbc_ driver_ template. ini). [SingleStore ODBC [Unicode|ANSI] Driver] Description = SingleStore ODBC [Unicode|ANSI] Driver Driver = <your path>/libssodbc[a|w].so
Be sure to specify the correct path to the driver and specify the corresponding name (
Unicode
orANSI
) and corresponding driver (a
orw
) to use.For Unicode, use "SingleStore ODBC Unicode Driver" and libssodbcw.
.so For ANSI use "SingleStore ODBC ANSI Driver" and libssodbca.
.so -
Run the following command to install the template file to the system's global
/etc/odbcinst.
file:ini sudo odbcinst -i -d -f SingleStore_odbc_driver_template.ini
-
-
Configure a DSN with UnixODBC on Linux.
-
Create a template file similar to the following, and name it (for example, SingleStore_
odbc_ data_ source_ template. ini). [SingleStore-server] Description=SingleStore server Driver=SingleStore ODBC [Unicode|ANSI] Driver SERVER=<ip_address_or_hostname_of_SingleStore_cluster> USER=<username> PASSWORD=<password> DATABASE=<database> PORT=<port>
Specify
Unicode
orANSI
in the value forDriver=
. -
Run the following command to install the template file to the system's global
/etc/odbc.
file:ini sudo odbcinst -i -s -l -f SingleStore_odbc_data_source_template.ini
-
-
Use the
isql
utility to verify that the DSN is properly configured with UnixODBC on Linux.isql SingleStore-server
Authenticate via JWTs
Before using JWTs to authenticate your connection to the SingleStore cluster using the SingleStore ODBC driver, you must install (or reinstall) the glib*
and libsecret*
libraries.
Run the following commands:
-
Debian:
sudo apt-get install glib*sudo apt-get install libsecret* -
CentOS:
sudo yum install glib*sudo yum install libsecret*
Using JWTs
You may authenticate your connection to the SingleStore cluster using the SingleStore ODBC driver with a JWT.JWT
parameter.
Here’s a sample connection string that authenticates using JWT:
"DRIVER=SingleStore ODBC Unicode Driver;SERVER=<cluster_endpoint>;USER=root;JWT=<jwt_token>;SSLCA=<path_to>/singlestore_bundle.pem"
See Authenticate via JWTs for more information.
Authenticate via Kerberos
You can authenticate your connection to a SingleStore cluster via Kerberos-based authentication using the SingleStore ODBC driver.
On Windows
To configure Kerberos-based authentication on Windows:
-
Download and install the SingleStore ODBC driver.
Note that the installation directory (default "C:\Program Files (x86)\SingleStore\SingleStore ODBC Driver\plugin") contains the auth_
gssapi_ client. dll file. -
Configure SingleStore for Kerberos authentication.
Refer to Kerberos Authentication for more information. -
Log in to the Kerberos user.
-
Configure a data source to connect with SingleStore.
-
On the Start menu, select Control Panel > Administrative Tools > Data Sources (ODBC).
-
In the Create new Data Source dialog, select the SingleStore ODBC Driver, and then select Finish.
-
In the Create new Data Source to SingleStore dialog, enter a name for the data source in the Name box.
Select Next. -
In the Server Name box, enter the IP address or hostname for the server.
-
Select Test DSN to test the connectivity.
Use defaults for other configuration items. Note: Do not specify a username in the User name/Password field while configuring the data source.
-
On Linux
To configure Kerberos-based authentication on Linux:
-
Download and install the latest version of the SingleStore ODBC driver.
-
Create an odbc.
ini file for the current user to configure the data source, and add the following configuration: [server-name] Description = SingleStore Server Driver = SingleStore ODBC [Unicode|ANSI] Driver Database = <database-name> PLUGIN_DIR = <path_to_your_auth_gssapi_client.so_file> SERVER = <server-ip-address-or-hostname> USER = <username> PORT = 3306
Update the values in the file with the relevant data source parameters.
Once the singlestore-client
package is installed, the auth_gssapi_ client. so file is present in the /var/lib/memsql/memsql-client/lib/plugin directory. In this use case, we'll replace server-name
with SingleStore-server. -
Obtain a token for the user.
kinit <username> -
Test the data source SingleStore-server configured in the odbc.
ini file using the isql
command as follows:isql -v SingleStore-server
Configuring the SingleStore ODBC Driver
On Windows, you can use the ODBC Data Source Administrator to set the configuration parameters.
On Unix and macOS, use the parameter name and value as the keyword/value pair in the DSN configuration.InConnectionString
argument in the SQLDriverConnect()
call:
SQLCHAR conn[512];sprintf((char *)conn, "DRIVER=%s;SERVER=%s;DATABASE=%s;UID=%s;PASSWORD=%s;PORT=%d;NO_SSPS=%d;%s",my_drivername, my_servername, my_schema, my_uid, my_pwd, my_port, NoSsps, add_connstr);SQLRETURN result = SQLDriverConnect(hdbc1, NULL, conn, SQL_NTS, NULL, 0, NULL, SQL_DRIVER_NOPROMPT);
The SingleStore ODBC driver supports the following parameters.
DSN-Related Parameters
Parameter |
Description |
---|---|
|
Description of the data source. |
|
The name of the SingleStore ODBC Driver. |
|
Name of the DSN. |
General Connection Parameters
Parameter |
Windows GUI Option |
Default |
Description |
---|---|---|---|
|
User name |
The user name. |
|
|
Server name |
The host name of the SingleStore server. |
|
|
Database |
The default database. |
|
|
-- |
0 |
Options bitmask that specifies how driver/ODBC works (see Option parameters table below). |
|
Port |
0 |
The TCP/IP port to use. |
|
Statement(s) |
A SQL statement to execute when connecting to SingleStore. |
|
|
Password |
The password for the user account on server. |
|
|
Connection Character Set |
The character set to use for the connection. |
|
|
Prepare statements on the client side |
1 |
When this option is set to a non-zero value, prepared statements are emulated on the client side. |
|
Don’t prompt when connecting |
0 |
Do not prompt for questions even if the driver would like to prompt. |
|
Read ODBC section from |
0 |
Read parameters from the |
|
Enable automatic_ |
0 |
Enables the auto-reconnection functionality. |
|
Force use of forward-only cursors |
0 |
Force the use of the Forward-only cursor type. |
|
-- |
0 |
Force the use of the Forward-only cursor type. |
|
Don't cache results of forward-only cursors |
1 |
Do not cache the results locally in the driver, instead read from the server. |
|
-- |
Name of the application that uses the driver. |
TLS-Related Connection Parameters
Parameter |
Windows GUI Option |
Default |
Description |
---|---|---|---|
|
SSL Certificate |
The path to a file with a list of trusted SSL CAs. |
|
|
CA Path |
The path to a directory that contains trusted SSL CA certificates in PEM format. |
|
|
Certificate |
The name of the SSL certificate file to use for establishing a secure connection. |
|
|
Cipher |
The list of permissible ciphers for SSL encryption. |
|
|
Key |
The name of the SSL key file to use for establishing a secure connection. |
|
|
Verify Certificate |
0 |
If set to 1, the SSL certificate will be verified when used with the SingleStore connection. |
|
TLS Peer Fingerprint |
Specify the SHA1 fingerprint of a server certificate for validation during the TLS handshake. |
|
|
Fingerprint list file |
Specify a file which contains one or more SHA1 fingerprints of server certificates for validation during the TLS handshake. |
|
|
CRL File |
Defines a path to a PEM file that should contain one or more revoked X509 certificates to use for TLS. |
|
|
-- |
Defines a path to a directory that contains one or more PEM files that should each contain one revoked X509 certificate to use for TLS. |
|
|
Force TLS Use |
0 |
Whether to force TLS. |
|
-- |
Specify a passphrase for a passphrase-protected private key, as configured by the SSLKEY option. |
Option Parameters
You can pass these parameters via the OPTIONS
general connection parameter.
Note
If the OPTIONS
parameter is specified after a general parameter in the connection string, the value specified using the OPTIONS
parameter overrides the general parameter value.DSN=mu_
results in a connection that has NO_
disabled.
Parameter |
Windows GUI Option |
Constant Value |
Description |
---|---|---|---|
|
Found instead of affected rows |
2 (2^1) |
If this parameter is set, the server returns the number of matched rows to be updated instead of the number of actually changed rows. |
|
Don’t prompt when connecting |
16 (2^4) |
Do not prompt for questions even if the driver would like to prompt. |
|
Enable dynamic cursor |
32 (2^5) |
Enable or disable the dynamic cursor support. |
|
Read ODBC section from |
65536 (2^16) |
Read parameters from the |
|
Don’t cache result of forward only cursor |
1048576 (2^20) |
Do not cache the results locally in the driver, instead read from the server. |
|
Force use of forward-only cursor |
2097152 (2^21) |
Force the use of the Forward-only cursor type. |
|
Enable automatic_ |
4194304 (2^22) |
Enables auto-reconnection functionality. |
|
Allow multiple statements |
67108864 (2^26) |
Enables support for batched statements. |
|
Specifies a comma separated list of connection attributes in the This parameter has different identifiers depending on the application development tool/language that it is used with. |
Example Code
The following examples show how to use the SingleStore ODBC driver.
Read a Result Set
To read a large result set, use the NO_
option together with Forward-Only cursor
.SQLExecute
or SQLExecuteDirect
.
// Enable UTF8setlocale(LC_CTYPE, "");// Allocate environment handleSQLHANDLE Henv;SQLAllocHandle(SQL_HANDLE_ENV, NULL, &Henv);// Set odbc versionSQLSetEnvAttr(Henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, SQL_IS_INTEGER);// Allocate connection handleSQLHANDLE Hdbc;SQLAllocHandle(SQL_HANDLE_DBC, Henv, &Hdbc);// Connect to the data source// NO_CACHE option and Forward-Only cursor are enabled by defaultSQLDriverConnect(Hdbc,NULL,(SQLCHAR *)"DSN=my_dsn_name",SQL_NTS,NULL,0,NULL,SQL_DRIVER_NOPROMPT);// Allocate statement handleSQLHANDLE Hstmt;SQLAllocHandle(SQL_HANDLE_STMT, Hdbc, &Hstmt);// Create big tableSQLExecDirect(Hstmt, (SQLCHAR *)"CREATE TABLE big_table(a INT)", SQL_NTS);SQLExecDirect(Hstmt, (SQLCHAR *)"INSERT INTO big_table VALUES(1)", SQL_NTS);int i;for (i = 0; i < 20; i++){SQLExecDirect(Hstmt, (SQLCHAR *)"INSERT INTO big_table (SELECT (a+1) FROM big_table)", SQL_NTS);}// Select all data from big tableSQLExecDirect(Hstmt, (SQLCHAR *)"SELECT * FROM big_table", SQL_NTS);// Bind columnSQLINTEGER a;SQLBindCol(Hstmt, 1, SQL_C_LONG, &a, 0, NULL);// Fetch everything from the resultset// Data is not cached on the driver side after calling SQLExecDirect// and each row is retrieved during SQLFetchwhile(SQLFetch(Hstmt) != SQL_NO_DATA){printf("Fetched value: %d\n", a);}
Executing Multi-statement Queries
To execute multi-statement queries, the MULTI_
option should be enabled.OPTION=67108864
Also, execution of multi-statement queries is not supported with NO_
and Forward-Only cursor
.NO_
enabled.
// Allocate environment handleSQLHANDLE Henv;SQLAllocHandle(SQL_HANDLE_ENV, NULL, &Henv);// Set odbc versionSQLSetEnvAttr(Henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, SQL_IS_INTEGER);// Allocate connection handleSQLHANDLE Hdbc;SQLAllocHandle(SQL_HANDLE_DBC, Henv, &Hdbc);// Connect to the data source// Disable NO_CACHE and enable MULTI_STATEMENTS option// Disable NO_SSPS to be able to run queries that depends on each otherSQLDriverConnect(Hdbc,NULL,(SQLCHAR *)"DSN=my_dsn_name;NO_CACHE=0;OPTION=67108864;NO_SSPS=0",SQL_NTS,NULL,0,NULL,SQL_DRIVER_NOPROMPT);// Allocate statement handleSQLHANDLE Hstmt;SQLAllocHandle(SQL_HANDLE_STMT, Hdbc, &Hstmt);// Execute multi-statementSQLExecDirect(Hstmt, (SQLCHAR *)"CREATE TABLE multi_statement(a INT);""INSERT INTO multi_statement VALUES (1), (2), (3), (4);""SELECT a FROM multi_statement;""SELECT a+1 FROM multi_statement;", SQL_NTS);// Process the result of the second statement (INSERT INTO multi_statement VALUES(1))SQLMoreResults(Hstmt);printf("Processing the result of the second statement\n");// Get the number of inserted rowsSQLLEN rowCount;SQLRowCount(Hstmt, &rowCount);printf("Inserted %ld rows\n", rowCount);// Process the result of the third statement (SELECT a FROM multi_statement)SQLMoreResults(Hstmt);printf("Processing the result of the third statement\n");// Bind columnSQLINTEGER a;SQLBindCol(Hstmt, 1, SQL_C_LONG, &a, 0, NULL);// Fetch everything from the resultsetwhile(SQLFetch(Hstmt) != SQL_NO_DATA){printf("Fetched value: %d\n", a);}// Process the result of the fourth statement (SELECT a+1 FROM multi_statement)SQLMoreResults(Hstmt);printf("Processing the result of the fourth statement\n");// Fetch everything from the resultsetwhile(SQLFetch(Hstmt) != SQL_NO_DATA){printf("Fetched value: %d\n", a);}
Retrieve Information about the Result Set's Schema
To retrieve information about the schema of the result set after the SQL statement is prepared and before it is executed, NO_
should be disabled.
// Enable UTF8setlocale(LC_CTYPE, "");// Allocate environment handleSQLHANDLE Henv;SQLAllocHandle(SQL_HANDLE_ENV, NULL, &Henv);// Set odbc versionSQLSetEnvAttr(Henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, SQL_IS_INTEGER);// Allocate connection handleSQLHANDLE Hdbc;SQLAllocHandle(SQL_HANDLE_DBC, Henv, &Hdbc);// Connect to the data source// Disable NO_SSPS to be able to get number of columns before executing the statementSQLDriverConnect(Hdbc,NULL,(SQLCHAR *)"DSN=my_dsn_name;NO_SSPS=0",SQL_NTS,NULL,0,NULL,SQL_DRIVER_NOPROMPT);// Allocate statement handleSQLHANDLE Hstmt;SQLAllocHandle(SQL_HANDLE_STMT, Hdbc, &Hstmt);// Prepare statementSQLPrepare(Hstmt, (SQLCHAR *)"SELECT 1, 2", SQL_NTS);// Get number of columnsSQLSMALLINT colNum;SQLNumResultCols(Hstmt, &colNum);printf("Number of columns: %d\n", colNum);// Execute statementSQLExecute(Hstmt);
Using the Option Parameter
The following example shows how to pass multiple option parameters via a bitmask:
// Allocate environment handleSQLHANDLE Henv;SQLAllocHandle(SQL_HANDLE_ENV, NULL, &Henv);// Set odbc versionSQLSetEnvAttr(Henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, SQL_IS_INTEGER);// Allocate connection handleSQLHANDLE Hdbc;SQLAllocHandle(SQL_HANDLE_DBC, Henv, &Hdbc);// Connect to the data source// The following options are enabled// FOUND_ROWS - 2// NO_PROMPT - 16// DYNAMIC_CURSOR - 32// AUTO_RECONNECT - 4194304// 2 + 16 + 32 + 4194304 = 4194354SQLDriverConnect(Hdbc,NULL,(SQLCHAR *)"DSN=my_dsn_name;OPTIONS=4194354",SQL_NTS,NULL,0,NULL,SQL_DRIVER_NOPROMPT);
Specify Connection Attributes
Here are some examples that specify connection attribute identifiers and their usage in respective tools/languages.
C (MySQL API)
To specify the connection attributes, call the mysql_
function before the mysql_
function.mysql_
function call, specify MYSQL_
as the second argument and pass the attribute key and value as the third and fourth arguments, respectively.
MYSQL *con;con = mysql_init(NULL);mysql_options4(con, MYSQL_OPT_CONNECT_ATTR_ADD, "program_name", "Test C app");mysql_options4(con, MYSQL_OPT_CONNECT_ATTR_ADD, "program_version", "1.2.3");mysql_real_connect(con, "<hostname>", "<username>", "pa55w0rd", "<database>", 3306, NULL, 0);
C (ODBC)
You can specify a comma-separated list of key-value pairs using the CONN_
parameter in the connection string as follows:
SQLHENV env;SQLHDBC dbc;/* Allocate an environment handle */SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env);/* Allocate a connection handle */SQLAllocHandle(SQL_HANDLE_DBC, env, &dbc);/* Connect to the DSN */SQLCHAR conn[1024];const char *attrs = "CONN_ATTRS=program_name:My ODBC App,program_version:1.2.3";sprintf((char *)conn, "DRIVER=SingleStore ODBC Unicode Driver;SERVER=<hostname>;UID=<username>;PASSWORD=pa55w0rd;PORT=3306;%s", attrs);SQLRETURN result = SQLDriverConnect(dbc, NULL, conn, SQL_NTS, NULL, 0, NULL, SQL_DRIVER_NOPROMPT);
C++
Use the OPT_
option to pass the connection attributes.
#include <mysql_driver.h>#include <mysql_connection.h>#include <mysql_error.h>#include <cppconn/resultset.h>#include <cppconn/statement.h>int main(){sql::mysql::MySQL_Driver *driver;sql::Connection *con;sql::ConnectOptionsMap connection_properties;connection_properties["hostName"] = "<hostname>";connection_properties["userName"] = "<username>";connection_properties["password"] = "pa55w0rd";connection_properties["port"] = 3306;std::map<sql::SQLString, sql::SQLString> connect_attrs;connect_attrs["program_name"] = "My C++ App";connect_attrs["program_version"] = "1.2.3";connection_properties["OPT_CONNECT_ATTR_ADD"] = connect_attrs;driver = sql::mysql::get_mysql_driver_instance();con = driver->connect(connection_properties);// Create a statement objectauto stmt = con->createStatement();// Execute a simple queryauto res = stmt->executeQuery("SELECT 1");}
C#/. NET
You can specify the connection attributes using the connectionAttributes
parameter as follows:
using SingleStoreConnector;public static class Program{public static void Main(){string HOST = "<hostname>";int PORT = 3306;string USER = "<username>";string PASSWORD = "paw0rd";string DATABASE = "db";string CONN_ATTRS = "program_name:My .NET App,program_version:1.2.3";var connectionString = $"Server={HOST};Port={PORT};Uid={USER};Pwd={PASSWORD};Database={DATABASE};ConnectionAttributes={CONN_ATTRS}";var conn = new SingleStoreConnection(connectionString);conn.Open();}}
Python
You can specify a comma-separated list of key-value pairs using the conn_
parameter in the connection string as follows:
import singlestoredb as s2host = '<hostname>'user = '<username>'password = 'pa55w0rd'conn = s2.connect(user=user,host=host,password=password,conn_attrs={"program_name": "My Python App", "program_version": "1.2.3"})
Go
You can pass the connection attributes in key-value pairs using the connectionAttributes
parameter.Config
struct.
package mainimport ("database/sql""fmt"_ "github.com/go-sql-driver/mysql")func main() {user := "<username>"host := "<hostname>"password := "pa55w0rd"port := 3306connParams := "connectionAttributes=program_name:My Go App,program_version:1.2.3"dbName := "information_schema"connString := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?%s",user,password,host,port,dbName,connParams,)db, err := sql.Open("mysql", connString)fmt.Printf("Created connection to db, got error %v\n", err)fmt.Printf("Tested connection to db, got error %v\n", db.Ping())}
Node. js
You can specify the connection attributes in the createConnection
and createPool
functions using the connectAttributes
argument.connectAttributes
argument, the properties and their values represent the connection attributes and their values, respectively.
import mysql from 'mysql2/promise';const HOST = '<hostname>';const USER = '<username>';const PASSWORD = 'pa55w0rd';const DATABASE = 'testdb';async function main() {let singleStoreConnection = await mysql.createConnection({host: HOST,user: USER,password: PASSWORD,database: DATABASE,connectAttributes: {program_name: 'My NodeJS App',program_version: '1.2.3'},});singleStoreConnection.execute("SELECT 1");singleStoreConnection.end();}main()
Known Issues and Limitations
See the GitHub repository for more detailed information.
License
SINGLESTORE, INC.
APPLICABLE OPEN SOURCE LICENSE: GNU LESSER GENERAL PUBLIC LICENSE Version 2.
IF YOU OR YOUR COMPANY DO NOT AGREE TO THESE TERMS AND CONDITIONS, DO NOT CHECK THE ACCEPTANCE BOX, AND DO NOT DOWNLOAD, ACCESS, COPY, INSTALL OR USE THE SOFTWARE OR THE SERVICES.
Last modified: March 20, 2024