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

Method PrepareSQL

storage/connect/odbconn.cpp:1666–1756  ·  view source on GitHub ↗

/ Prepare an SQL statement for insert. */ /

Source from the content-addressed store, hash-verified

1664/* Prepare an SQL statement for insert. */
1665/***********************************************************************/
1666int ODBConn::PrepareSQL(char *sql)
1667 {
1668 PGLOBAL& g = m_G;
1669 bool b;
1670 UINT txn = 0;
1671 SWORD nparm;
1672 RETCODE rc;
1673 HSTMT hstmt;
1674
1675 if (m_Tdb->GetMode() != MODE_READ) {
1676 // Does the data source support transactions
1677 rc = SQLGetInfo(m_hdbc, SQL_TXN_CAPABLE, &txn, 0, NULL);
1678
1679 if (Check(rc) && txn != SQL_TC_NONE) try {
1680 rc = SQLSetConnectAttr(m_hdbc, SQL_ATTR_AUTOCOMMIT,
1681 SQL_AUTOCOMMIT_OFF, SQL_IS_UINTEGER);
1682
1683 if (!Check(rc))
1684 ThrowDBX(SQL_INVALID_HANDLE, "SQLSetConnectAttr");
1685
1686 m_Transact = true;
1687 } catch(DBX *x) {
1688 if (trace(1))
1689 for (int i = 0; i < MAX_NUM_OF_MSG && x->m_ErrMsg[i]; i++)
1690 htrc(x->m_ErrMsg[i]);
1691
1692 snprintf(g->Message, sizeof(g->Message), "%s: %s", x->m_Msg, x->GetErrorMessage(0));
1693 } // end try/catch
1694
1695 } // endif Mode
1696
1697 try {
1698 b = false;
1699
1700 if (m_hstmt) {
1701 SQLFreeStmt(m_hstmt, SQL_CLOSE);
1702
1703 hstmt = m_hstmt;
1704 m_hstmt = NULL;
1705
1706 if (m_Tdb->GetAmType() != TYPE_AM_XDBC)
1707 ThrowDBX(MSG(SEQUENCE_ERROR));
1708
1709 } // endif m_hstmt
1710
1711 rc = SQLAllocStmt(m_hdbc, &hstmt);
1712
1713 if (!Check(rc))
1714 ThrowDBX(SQL_INVALID_HANDLE, "SQLAllocStmt");
1715
1716 OnSetOptions(hstmt);
1717 b = true;
1718
1719 if (trace(1))
1720 htrc("Prepare hstmt=%p %.64s\n", hstmt, sql);
1721
1722 do {
1723 rc = SQLPrepare(hstmt, (PUCHAR)sql, SQL_NTS);

Callers

nothing calls this directly

Calls 4

GetErrorMessageMethod · 0.80
htrcFunction · 0.70
CheckClass · 0.50
GetAmTypeMethod · 0.45

Tested by

no test coverage detected