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

Method ExecSQL

storage/connect/myconn.cpp:708–774  ·  view source on GitHub ↗

/ Exec the Select SQL command and get back the result size in rows. */ /

Source from the content-addressed store, hash-verified

706/* Exec the Select SQL command and get back the result size in rows. */
707/***********************************************************************/
708int MYSQLC::ExecSQL(PGLOBAL g, const char *query, int *w)
709 {
710 int rc = RC_OK;
711
712 if (!m_DB) {
713 strcpy(g->Message, "MySQL not connected");
714 return RC_FX;
715 } // endif m_DB
716
717 if (w)
718 *w = 0;
719
720 if (m_Rows >= 0)
721 return RC_OK; // Already done
722
723//if (mysql_query(m_DB, query) != 0) {
724 if (mysql_real_query(m_DB, query, strlen(query))) {
725 size_t msg_size = 512 + strlen(query);
726 char *msg = (char*)PlugSubAlloc(g, NULL, msg_size);
727
728 snprintf(msg, msg_size, "(%d) %s [%s]", mysql_errno(m_DB),
729 mysql_error(m_DB), query);
730 strncpy(g->Message, msg, sizeof(g->Message) - 1);
731 g->Message[sizeof(g->Message) - 1] = 0;
732 rc = RC_FX;
733//} else if (mysql_field_count(m_DB) > 0) {
734 } else if (m_DB->field_count > 0) {
735 if (m_Use)
736#if defined(MYSQL_PREPARED_STATEMENTS)
737 m_Res = mysql_use_result(m_DB);
738#else // !MYSQL_PREPARED_STATEMENTS)
739 m_Res = connect_use_result(m_DB);
740#endif // !MYSQL_PREPARED_STATEMENTS
741 else
742 m_Res = mysql_store_result(m_DB);
743
744 if (!m_Res) {
745 size_t msg_size = 512 + strlen(query);
746 char *msg = (char*)PlugSubAlloc(g, NULL, msg_size);
747
748 snprintf(msg, msg_size, "mysql_store_result failed: %s", mysql_error(m_DB));
749 strncpy(g->Message, msg, sizeof(g->Message) - 1);
750 g->Message[sizeof(g->Message) - 1] = 0;
751 rc = RC_FX;
752 } else {
753 m_Fields = mysql_num_fields(m_Res);
754 m_Rows = (!m_Use) ? (int)mysql_num_rows(m_Res) : 0;
755
756 if (trace(1))
757 htrc("ExecSQL: m_Res=%.4X size=%d m_Fields=%d m_Rows=%d\n",
758 m_Res, sizeof(*m_Res), m_Fields, m_Rows);
759
760 } // endif m_Res
761
762 } else {
763// m_Rows = (int)mysql_affected_rows(m_DB);
764 m_Rows = (int)m_DB->affected_rows;
765 snprintf(g->Message, sizeof(g->Message), "Affected rows: %d", m_Rows);

Callers 7

SrcColumnsFunction · 0.80
MakePivotColumnsMethod · 0.80
OpenDBMethod · 0.80
SendCommandMethod · 0.80
ReadKeyMethod · 0.80
WriteDBMethod · 0.80
ReadDBMethod · 0.80

Calls 8

mysql_real_queryFunction · 0.85
PlugSubAllocFunction · 0.85
mysql_errnoFunction · 0.85
mysql_errorFunction · 0.85
connect_use_resultFunction · 0.85
mysql_num_fieldsFunction · 0.85
mysql_num_rowsFunction · 0.85
htrcFunction · 0.70

Tested by

no test coverage detected