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 MYOB Source;", SQL_NTS, 0, 0, 0, 0);
SQLExecDirect(hstmt, (SQLCHAR*)"INSERT INTO Accounts (Name) 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 MYOB Source;", SQL_NTS, 0, 0, 0, 0);
SQLExecDirect(hstmt, (SQLCHAR*)"UPDATE Accounts SET Name='Jon Doe' WHERE Type='Bank')", 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 MYOB Source;", SQL_NTS, 0, 0, 0, 0);
SQLExecDirect(hstmt, (SQLCHAR*)"DELETE FROM Accounts WHERE Id='6186169c-6540-4d72-8bfe-ecc706e500ee')", SQL_NTS);
SQLINTEGER rowCount = 0;
SQLRowCount(hstmt, &rowCount);