Querying and Modifying Data
Connect to a GridGain 9 cluster with the ODBC driver and run SQL to create tables, query, insert, update, and delete data.
Overview
This page describes how to connect to a cluster and execute a variety of SQL queries by using the ODBC driver.
The ODBC driver supports DML (Data Modification Layer), which means that you can modify your data using an ODBC connection.
Creating Tables
The simplest way to create tables by using ODBC Driver is to use DDL statements:
SQLHENV env;
// Allocate an environment handle
SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env);
// Use ODBC ver 3.8
SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, reinterpret_cast<void*>(SQL_OV_ODBC3_80), 0);
SQLHDBC dbc;
// Allocate a connection handle
SQLAllocHandle(SQL_HANDLE_DBC, env, &dbc);
// Prepare the connection string
SQLCHAR connectStr[] = "Driver={Apache Ignite 3};ADDRESS=localhost:10800;SCHEMA=PUBLIC;";
// Connecting to the Cluster.
SQLDriverConnect(dbc, NULL, connectStr, SQL_NTS, NULL, 0, NULL, SQL_DRIVER_COMPLETE);
SQLHSTMT stmt;
// Allocate a statement handle
SQLAllocHandle(SQL_HANDLE_STMT, dbc, &stmt);
SQLCHAR query1[] = "CREATE TABLE Person ( "
"id LONG PRIMARY KEY, "
"firstName VARCHAR, "
"lastName VARCHAR, "
"salary FLOAT) "";
SQLExecDirect(stmt, query1, SQL_NTS);
SQLCHAR query2[] = "CREATE TABLE Organization ( "
"id LONG PRIMARY KEY, "
"name VARCHAR) "";
SQLExecDirect(stmt, query2, SQL_NTS);
SQLCHAR query3[] = "CREATE INDEX idx_organization_name ON Organization (name)";
SQLExecDirect(stmt, query3, SQL_NTS);As you can see, we defined two tables that will contain the data of Person and Organization types. For both types, we listed specific fields and indexes that will be read or updated using SQL.
Handling Errors
The section below covers how you can handle possible errors when working with ODBC. In this example we handle an issue with connecting to the cluste
Querying Data
After everything is up and running, we're ready to execute SQL SELECT queries using the ODBC API.
Inserting Data
To insert new data into the cluster, SQL INSERT statements can be used from the ODBC side.
Next, we are going to insert additional organizations without the usage of prepared statements.
Error Checking
For simplicity the example code above does not check for an error return code. You will want to do error checking in production.
Updating Data
Let's now update the salary for some of the persons stored in the cluster using SQL UPDATE statement.
Deleting Data
Finally, let's remove a few records with the help of SQL DELETE statement.
Last updated
Was this helpful?

