int SQLDisconnect(int sqlNum) {
/* check that we are connected? */
if (! conn[sqlNum].connected) {
ShowMsg("sql disconnect; not connected.");
return 0;
}
mysql_close(&conn[sqlNum].mysql);
conn[sqlNum].connected = 0;
return 1;
}
/*******************************************************************/
/* sql general commands */
/*******************************************************************/
int SQLSelectDB(int sqlNum, char *database) {
/* check that we are connected to a mysql server */
if (!conn[sqlNum].connected) {
ShowMsg("sql query statement; you are not connected to a mysql server yet (sql connect).");
return 0;
}
int SQLQuery(int sqlNum, char *query) {
if (! conn[sqlNum].connected) {
ShowMsg("sql query statement; you are not connected to a mysql server yet");
return 0;
}
/* check there is no other active query? */
if (conn[sqlNum].qFlag) {
ShowMsg("Another query cannot be made until the current query has been finished with \"sql endquery\".");
return 0;
}
/* execute the sql query statement */
if (mysql_query(&conn[sqlNum].mysql, query)) {
OutputError(sqlNum);
return 0;
}
/* if no results were found and none expected then all ok */
/* otherwise we assume the query worked ok, now get the results */
if (conn[sqlNum].res == NULL) {
if (conn[sqlNum].nFields) {
OutputError(sqlNum);
return 0;
}
// ShowMsg("sql startquery; query executed ok but returned no results.");
return 2;
}
/* return all ok now, see fetchrow & endquery for more details */
conn[sqlNum].qFlag = 1;
return 1;
}
MYSQL_FIELD* SQLFetchField(int sqlNum)
{
/* check we are connected? */
if (! conn[sqlNum].connected) {
ShowMsg("Not connected to a server.");
return NULL;
}
/* check we had a query started? */
if (! conn[sqlNum].qFlag) {
ShowMsg("No query has been started.");
return NULL;
}
return mysql_fetch_field(conn[sqlNum].res);
}
MYSQL_ROW SQLFetchRow(int sqlNum)
{
/* check we are connected? */
if (! conn[sqlNum].connected) {
ShowMsg("Not connected to a server.");
return NULL;
}
/* check we had a query started? */
if (! conn[sqlNum].qFlag) {
ShowMsg("No query has been started.");
return NULL;
}
return mysql_fetch_row(conn[sqlNum].res);
}
int SQLEndQuery(int sqlNum) {
/* check we are connected? */
if (! conn[sqlNum].connected) {
ShowMsg("Not connected to a server.");
return 0;
}
/* check we had a query started? */
if (! conn[sqlNum].qFlag) {
ShowMsg("No query has been started.");
return 0;
}