ODBC Driver for IBM Cloud Data Engine

Build 24.0.9060

Modifying Data

The following code examples show how to use data modification statements.

Procedure for Updates

Use SQLExecDirect to execute data manipulation statements and use the SQLRowCount function to obtain the affected rows.

INSERT

To insert updates:

SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv); 
SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0); 
SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc); 
SQLDriverConnect(hdbc, 0, (SQLCHAR*)"Dsn=CData IBMCloudSQLQuery Source;", SQL_NTS, 0, 0, 0, 0);
SQLExecDirect(hstmt, (SQLCHAR*)"INSERT INTO [CloudObjectStorage_1].[SampleBucket_1].Jobs (Status) VALUES ('Jon Doe')", SQL_NTS);  
SQLINTEGER  rowCount = 0;
SQLRowCount(hstmt, &rowCount);

UPDATE

To retrieve updates:

SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv); 
SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0); 
SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc); 
SQLDriverConnect(hdbc, 0, (SQLCHAR*)"Dsn=CData IBMCloudSQLQuery Source;", SQL_NTS, 0, 0, 0, 0);
SQLExecDirect(hstmt, (SQLCHAR*)"UPDATE [CloudObjectStorage_1].[SampleBucket_1].Jobs SET Status='Jon Doe' WHERE UserId='[email protected]')", SQL_NTS);  
SQLINTEGER  rowCount = 0;
SQLRowCount(hstmt, &rowCount); 

DELETE

To delete updates:

SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv); 
SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0); 
SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc); 
SQLDriverConnect(hdbc, 0, (SQLCHAR*)"Dsn=CData IBMCloudSQLQuery Source;", SQL_NTS, 0, 0, 0, 0);
SQLExecDirect(hstmt, (SQLCHAR*)"DELETE FROM [CloudObjectStorage_1].[SampleBucket_1].Jobs WHERE Id='215776c8-81e1-4f8a-90ad-c70fd395ab41')", SQL_NTS);  
SQLINTEGER  rowCount = 0;
SQLRowCount(hstmt, &rowCount); 

Copyright (c) 2024 CData Software, Inc. - All rights reserved.
Build 24.0.9060