MCPcopy Create free account
hub / github.com/MariaDB/server / ExecSQLcommand

Method ExecSQLcommand

storage/connect/odbconn.cpp:1863–1964  ·  view source on GitHub ↗

/ Execute an SQL command. */ /

Source from the content-addressed store, hash-verified

1861/* Execute an SQL command. */
1862/***********************************************************************/
1863bool ODBConn::ExecSQLcommand(char *sql)
1864 {
1865 char cmd[16];
1866 bool b, rcd = false;
1867 UINT txn = 0;
1868 PGLOBAL& g = m_G;
1869 SWORD ncol = 0;
1870 SQLLEN afrw;
1871 RETCODE rc;
1872 HSTMT hstmt;
1873
1874 try {
1875 b = FALSE;
1876
1877 // Check whether we should use transaction
1878 if (sscanf(sql, " %15s ", cmd) == 1) {
1879 if (!stricmp(cmd, "INSERT") || !stricmp(cmd, "UPDATE") ||
1880 !stricmp(cmd, "DELETE") || !stricmp(cmd, "REPLACE")) {
1881 // Does the data source support transactions
1882 rc = SQLGetInfo(m_hdbc, SQL_TXN_CAPABLE, &txn, 0, NULL);
1883
1884 if (Check(rc) && txn != SQL_TC_NONE) {
1885 rc = SQLSetConnectAttr(m_hdbc, SQL_ATTR_AUTOCOMMIT,
1886 SQL_AUTOCOMMIT_OFF, SQL_IS_UINTEGER);
1887
1888 if (!Check(rc))
1889 ThrowDBX(SQL_INVALID_HANDLE, "SQLSetConnectAttr");
1890
1891 m_Transact = TRUE;
1892 } // endif txn
1893
1894 } // endif cmd
1895
1896 } // endif sql
1897
1898 // Allocate the statement handle
1899 rc = SQLAllocStmt(m_hdbc, &hstmt);
1900
1901 if (!Check(rc))
1902 ThrowDBX(SQL_INVALID_HANDLE, "SQLAllocStmt");
1903
1904 OnSetOptions(hstmt);
1905 b = true;
1906
1907 if (trace(1))
1908 htrc("ExecSQLcommand hstmt=%p %.64s\n", hstmt, sql);
1909
1910 // Proceed with command execution
1911 do {
1912 rc = SQLExecDirect(hstmt, (PUCHAR)sql, SQL_NTS);
1913 } while (rc == SQL_STILL_EXECUTING);
1914
1915 if (!Check(rc))
1916 ThrowDBX(rc, "SQLExecDirect", hstmt);
1917
1918 // Check whether this is a query returning a result set
1919 if (!Check(rc = SQLNumResultCols(hstmt, &ncol)))
1920 ThrowDBX(rc, "SQLNumResultCols", hstmt);

Callers 2

ReadDBMethod · 0.80
DeleteDBMethod · 0.80

Calls 3

GetErrorMessageMethod · 0.80
htrcFunction · 0.70
CheckClass · 0.50

Tested by

no test coverage detected