// Note that this file has bits that are specific to the // CircleMUD based system it ran in, and will likely not // compile standalone. // Not also that the jelos98@yahoo.com address is also mine, // and I while I do still check it, it currently receives 99.9% // spam. /******************* SQLMUD HEADER FILE ******************* *** Originally by Jelos (jelos98@yahoo.com) *** *********************************************************/ #ifndef _MUD_SQL_LIB__H_ #define _MUD_SQL_LIB__H_ #include/***************************************************************************** * mysql_result_set * * A mysql_result_set consists of a set of mysql_result's. It is the return * type for the selectf function. It buffers the entirety of the data, * such that you can make a second selectf call without finishing the first. * (You can't do that with their base API) * * To clean up a mysql_result_set, call free_mysql_result_set(set) * ****************************************************************************/ struct mysql_result_set { int num_rows; struct mysql_result** results; }; /***************************************************************************** * mysql_result * * A mysql_result is made up of a set of char* fields, corresponding to the * fields returned by the select query. This struct is the return type of * select_first, and is also used in the mysql_result_set struct. * * To clean up a mysql_result, call free_mysql_result, unless it is part of * a mysql_result_set, in which case the call to free_mysql_result_set on * the set will suffice. ****************************************************************************/ struct mysql_result { int num_fields; char** values; }; /***************************************************************************** * initialize_mysql * * This function must be called before any of the other functions in this * header. It does the work of allocating a MYSQL struct, initializing it, * and opening a connection to the local MySQL server. * * A corresponding call to cleanup_mysql() will free allocated memory and * close the connection for you. ****************************************************************************/ bool initialize_mysql(); /***************************************************************************** * cleanup_mysql * * No other function in this file may be called after a call to this * function. It closes the active connection (and presumes that such a * connection exists.) and cleans up allocated memory. ****************************************************************************/ bool cleanup_mysql(); /***************************************************************************** * free_mysql_result * * Once you are finished with the result of a select_first, you should call * this function, which takes care to deallocate the memory in the struct. * No further action is necessary, and you may not then try to access the * result, obviously. * * Parameters * freeme - The mysql_result* to deallocate ****************************************************************************/ void free_mysql_result(struct mysql_result* freeme); /***************************************************************************** * free_mysql_result_set * * Once you are finished with the result of a selectf, you should call * this function, which takes care to deallocate the memory in the struct. * No further action is necessary, and you may not then try to access the * results, obviously. * * Parameters * freeme - The mysql_result_set* to deallocate ****************************************************************************/ void free_mysql_result_set(struct mysql_result_set* freeme); /***************************************************************************** * select_first * selectf * modify * * These functions take a sprintf style format string and parameter list, * and parse it, forming a SQL query. It then executes the query, and: * * select_first - returns a mysql_result* corresponding to the first row * returned * selectf - returns a mysql_result_set* corresponding to the entire * set of data returned by the query * modify - returns true on success * * Parameters * format - The printf style format string to use. * ... - The printf style arguments ****************************************************************************/ struct mysql_result* select_first(char* format, ...); struct mysql_result_set* selectf(char* format, ...); bool modify(char* format, ...); #endif