00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00029 #include "pch.h"
00030 #include "MyMySQLPPConnection.h"
00031
00032
00034 CMyMySQLPPConnection::CMyMySQLPPConnection(void)
00035 {
00036 m_con = NULL;
00037 }
00038
00040 CMyMySQLPPConnection::~CMyMySQLPPConnection(void)
00041 {
00042 Close();
00043 }
00044
00055 BOOL CMyMySQLPPConnection::Connect(const char* host, const char* user, const char* password,
00056 const char* database, unsigned int port, const char* unix_socket,
00057 unsigned int client_flag)
00058 {
00059 m_con = mysql_init(NULL);
00060 if(mysql_real_connect(m_con, host, user, password, database, port, unix_socket, client_flag) != m_con)
00061 {
00062 mysql_close(m_con);
00063 m_con = NULL;
00064 return FALSE;
00065 }
00066 return TRUE;
00067 }
00068
00070 void CMyMySQLPPConnection::Close(void)
00071 {
00072 if(m_con != NULL)
00073 mysql_close(m_con);
00074 m_con = NULL;
00075 }
00076
00080 BOOL CMyMySQLPPConnection::Ping(void)
00081 {
00082 if(m_con == NULL)
00083 return FALSE;
00084 return (mysql_ping(m_con) == 0);
00085 }
00086
00090 char* CMyMySQLPPConnection::GetClientInfo(void)
00091 {
00092 return mysql_get_client_info();
00093 }
00094
00098 char* CMyMySQLPPConnection::GetHostInfo(void)
00099 {
00100 if(m_con == NULL)
00101 return NULL;
00102 return mysql_get_host_info(m_con);
00103 }
00104
00108 unsigned int CMyMySQLPPConnection::GetProtocolInfo(void)
00109 {
00110 if(m_con == NULL)
00111 return NULL;
00112 return mysql_get_proto_info(m_con);
00113 }
00114
00118 char* CMyMySQLPPConnection::GetServerInfo(void)
00119 {
00120 if(m_con == NULL)
00121 return NULL;
00122 return mysql_get_server_info(m_con);
00123 }
00124
00128 __int64 CMyMySQLPPConnection::AffectedRows(void)
00129 {
00130 if(m_con == NULL)
00131 return 0;
00132 return mysql_affected_rows(m_con);
00133 }
00134
00141 BOOL CMyMySQLPPConnection::ChangeUser(const char* user, const char* password, const char* db)
00142 {
00143 if(m_con == NULL)
00144 return FALSE;
00145 return (mysql_change_user(m_con, user, password, db) == 0);
00146 }
00147
00151 const char* CMyMySQLPPConnection::CharacterSetName(void)
00152 {
00153 if(m_con == NULL)
00154 return NULL;
00155 return mysql_character_set_name(m_con);
00156 }
00157
00161 unsigned int CMyMySQLPPConnection::ErrorNumber(void)
00162 {
00163 if(m_con == NULL)
00164 return 0;
00165 return mysql_errno(m_con);
00166 }
00167
00171 char* CMyMySQLPPConnection::Error(void)
00172 {
00173 if(m_con == NULL)
00174 return 0;
00175 return mysql_error(m_con);
00176 }
00177
00181 __int64 CMyMySQLPPConnection::InsertID(void)
00182 {
00183 if(m_con == NULL)
00184 return 0;
00185 return mysql_insert_id(m_con);
00186 }
00187
00191 char* CMyMySQLPPConnection::Info(void)
00192 {
00193 if(m_con == NULL)
00194 return 0;
00195 return mysql_info(m_con);
00196 }
00197
00202 BOOL CMyMySQLPPConnection::Kill(unsigned long pid)
00203 {
00204 if(m_con == NULL)
00205 return FALSE;
00206 return mysql_kill(m_con, pid);
00207 }
00208
00214 BOOL CMyMySQLPPConnection::ListDatabases(CMyMySQLPPResult* result, const char* wild)
00215 {
00216 result->Free();
00217 if(m_con == NULL)
00218 return FALSE;
00219 MYSQL_RES *res = mysql_list_dbs(m_con, wild);
00220 if(res == NULL)
00221 return FALSE;
00222 result->Attach(res);
00223 return TRUE;
00224 }
00225
00232 BOOL CMyMySQLPPConnection::ListFields(CMyMySQLPPResult* result, const char* table, const char* wild)
00233 {
00234 result->Free();
00235 if(m_con == NULL)
00236 return FALSE;
00237 MYSQL_RES *res = mysql_list_fields(m_con, table, wild);
00238 if(res == NULL)
00239 return FALSE;
00240 result->Attach(res);
00241 return TRUE;
00242 }
00243
00248 BOOL CMyMySQLPPConnection::DropDatabase(const char* db)
00249 {
00250 if(m_con == NULL)
00251 return FALSE;
00252 return (mysql_drop_db(m_con, db) == 0);
00253 }
00254
00259 BOOL CMyMySQLPPConnection::ListProcesses(CMyMySQLPPResult* result)
00260 {
00261 result->Free();
00262 if(m_con == NULL)
00263 return FALSE;
00264 MYSQL_RES *res = mysql_list_processes(m_con);
00265 if(res == NULL)
00266 return FALSE;
00267 result->Attach(res);
00268 return TRUE;
00269 }
00270
00276 BOOL CMyMySQLPPConnection::ListTables(CMyMySQLPPResult* result, const char* wild)
00277 {
00278 result->Free();
00279 if(m_con == NULL)
00280 return FALSE;
00281 MYSQL_RES *res = mysql_list_tables(m_con, wild);
00282 if(res == NULL)
00283 return FALSE;
00284 result->Attach(res);
00285 return TRUE;
00286 }
00287
00293 BOOL CMyMySQLPPConnection::Options(enum mysql_option option, const char* arg)
00294 {
00295 if(m_con == NULL)
00296 return FALSE;
00297 return (mysql_options(m_con, option, arg) == 0);
00298 }
00299
00304 BOOL CMyMySQLPPConnection::Query(const char* query)
00305 {
00306 if(m_con == NULL)
00307 return FALSE;
00308 return (mysql_query(m_con, query) == 0);
00309 }
00310
00317 unsigned long CMyMySQLPPConnection::RealEscape(char* to, char* from, unsigned long length)
00318 {
00319 if(m_con == NULL)
00320 return 0;
00321 return mysql_real_escape_string(m_con, to, from, length);
00322 }
00323
00329 BOOL CMyMySQLPPConnection::RealQuery(const char* query, unsigned long length)
00330 {
00331 if(m_con == NULL)
00332 return FALSE;
00333 return (mysql_real_query(m_con, query, length) == 0);
00334 }
00335
00339 BOOL CMyMySQLPPConnection::Reload(void)
00340 {
00341 if(m_con == NULL)
00342 return FALSE;
00343 return (mysql_reload(m_con) == 0);
00344 }
00345
00350 BOOL CMyMySQLPPConnection::SelectDatabase(const char* db)
00351 {
00352 if(m_con == NULL)
00353 return FALSE;
00354 return (mysql_select_db(m_con, db) == 0);
00355 }
00356
00360 BOOL CMyMySQLPPConnection::Shutdown(void)
00361 {
00362 if(m_con == NULL)
00363 return FALSE;
00364 return (mysql_shutdown(m_con) == 0);
00365 }
00366
00370 char* CMyMySQLPPConnection::Status(void)
00371 {
00372 if(m_con == NULL)
00373 return NULL;
00374 return mysql_stat(m_con);
00375 }
00376
00381 BOOL CMyMySQLPPConnection::StoreResult(CMyMySQLPPResult* result)
00382 {
00383 result->Free();
00384 if(m_con == NULL)
00385 return FALSE;
00386 MYSQL_RES *res = mysql_store_result(m_con);
00387 if((res == NULL) && (ErrorNumber() > 0))
00388 return FALSE;
00389
00390 if(res != NULL)
00391 result->Attach(res);
00392 return TRUE;
00393 }
00394
00398 unsigned long CMyMySQLPPConnection::ThreadID(void)
00399 {
00400 if(m_con == NULL)
00401 return FALSE;
00402 return mysql_thread_id(m_con);
00403 }
00404
00409 BOOL CMyMySQLPPConnection::UseResult(CMyMySQLPPResult* result)
00410 {
00411 result->Free();
00412 if(m_con == NULL)
00413 return FALSE;
00414 MYSQL_RES *res = mysql_use_result(m_con);
00415 if(res == NULL)
00416 return FALSE;
00417 result->Attach(res);
00418 return TRUE;
00419 }