public static void Close() { if (MySQL1.SQL != IntPtr.Zero) { MySQL1.mysql_close(MySQL1.SQL); } MySQL1.IsConnected = false; }
public static void Disconnect() { if (!(MySQL1.SQL == IntPtr.Zero)) { MySQL1.QueueThread = null; MySQL1.mysql_close(MySQL1.SQL); MySQL1.IsConnected = false; } }
private static void ProcessQueue() { if (MySQL1.QueueThread != null) { if (MySQL1.Queue.Count > 0 && MySQL1.IsReady && MySQL1.Query(MySQL1.Queue[0], true) != null) { MySQL1.Queue.RemoveAt(0); } } }
public static string Error() { string result; if (MySQL1.SQL == IntPtr.Zero) { result = null; } else { result = Marshal.PtrToStringAnsi(MySQL1.mysql_error(MySQL1.SQL)); } return(result); }
public static string GetCharacterSet() { string result; if (MySQL1.SQL == IntPtr.Zero) { result = null; } else { result = Marshal.PtrToStringAnsi(MySQL1.mysql_character_set_name(MySQL1.SQL)); } return(result); }
public static bool Initialize() { MySQL1.SQL = MySQL1.mysql_init(IntPtr.Zero); bool result; if (MySQL1.Initialized = (MySQL1.SQL != IntPtr.Zero)) { MySQL1.VersionId = MySQL1.mysql_get_client_version(); MySQL1.Version = new Version(MySQL1.mysql_get_client_version().ToString("#-##-##").Replace("-", ".")); if (MySQL1.VersionId < MySQL1.MinVersion || MySQL1.VersionId > MySQL1.MaxVersion) { result = (MySQL1.Initialized = false); return(result); } } result = MySQL1.Initialized; return(result); }
public static bool Connect() { bool result; if (!MySQL1.Initialized || MySQL1.SQL == IntPtr.Zero) { result = false; } else if (MySQL1.mysql_real_connect(MySQL1.SQL, MySQL1.HostName, MySQL1.Username, MySQL1.Password, MySQL1.Database, MySQL1.HostPort, MySQL1.UnixSocket, MySQL1.ConnectFlags) == IntPtr.Zero) { result = false; } else { MySQL1.ServerVersion = new Version(MySQL1.mysql_get_server_version(MySQL1.SQL).ToString("#-##-##").Replace("-", ".")); result = (MySQL1.IsReady = true); } return(result); }
public static List <string> Databases(string wild = null) { IntPtr intPtr = MySQL1.mysql_list_dbs(MySQL1.SQL, wild); List <string> result; if (intPtr == IntPtr.Zero) { result = null; } else { List <string> list = new List <string>(); for (ulong num = 0uL; num < MySQL1.mysql_num_rows(intPtr); num += 1uL) { IntPtr ptr = MySQL1.mysql_fetch_row(intPtr); list.Add(Marshal.PtrToStringAnsi(Marshal.ReadIntPtr(ptr))); } result = list; } return(result); }
public static bool Connect(string host, string username, string password, string db_name, uint port, string unix_socket = null, MySQL1.ClientFlags flags = (MySQL1.ClientFlags) 0uL) { if (!MySQL1.Initialized) { MySQL1.Initialize(); } MySQL1.HostName = host; MySQL1.HostPort = port; MySQL1.Username = username; MySQL1.Password = password; MySQL1.Database = db_name; MySQL1.UnixSocket = unix_socket; MySQL1.ConnectFlags = (int)(flags | MySQL1.ClientFlags.CLIENT_MULTI_STATEMENTS); MySQL1.mysql_options(MySQL1.SQL, MySQL1.MySqlOption.MYSQL_OPT_CONNECT_TIMEOUT, Marshal.StringToCoTaskMemAnsi(MySQL1.ConnectTimeout.ToString())); MySQL1.mysql_options(MySQL1.SQL, MySQL1.MySqlOption.MYSQL_OPT_RECONNECT, Marshal.StringToCoTaskMemAnsi(MySQL1.Reconnect ? "1" : "0")); if (MySQL1.Charset.Equals("UTF8", StringComparison.OrdinalIgnoreCase)) { MySQL1.mysql_options(MySQL1.SQL, MySQL1.MySqlOption.MYSQL_SET_CHARSET_NAME, Marshal.StringToCoTaskMemAnsi(MySQL1.Charset)); MySQL1.mysql_options(MySQL1.SQL, MySQL1.MySqlOption.MYSQL_INIT_COMMAND, Marshal.StringToCoTaskMemAnsi("SET NAMES utf8")); } return(MySQL1.Connect()); }
public static void Update(string query) { if (MySQL1.IsReady) { try { MySQL1.IsReady = false; int num; if (Core.MySQL_UTF8) { num = MySQL1.mysql_query(MySQL1.SQL, query); } else { num = MySQL1.mysql_real_query(MySQL1.SQL, query, query.Length); } if (MySQL1.LogLevel > MySQL1.LogLevelType.ERRORS) { Helper.LogSQL(query, false); } if (num != 0 || MySQL1.ErrorCode != 0u) { if (MySQL1.LogLevel > MySQL1.LogLevelType.NONE) { Helper.LogSQLError(MySQL1.Error(), true); } MySQL1.mysql_ping(MySQL1.SQL); MySQL1.IsReady = true; return; } } catch (Exception ex) { Helper.LogSQLError(query, false); Helper.LogSQLError(ex.Message.ToString(), true); } MySQL1.IsReady = true; } }
public static bool SelectDB(string db_name) { return(MySQL1.Initialized && !(MySQL1.SQL == IntPtr.Zero) && MySQL1.mysql_select_db(MySQL1.SQL, db_name) == 0); }
public static MySQL1.Result Query(string query, bool skip = false) { MySQL1.Result result = null; MySQL1.Result result3; try { if (!MySQL1.IsReady && skip) { MySQL1.Result result2 = result; result3 = result2; return(result3); } MySQL1.IsReady = false; int num; if (Core.MySQL_UTF8) { num = MySQL1.mysql_query(MySQL1.SQL, query); } else { num = MySQL1.mysql_real_query(MySQL1.SQL, query, query.Length); } if (num != 0 || MySQL1.ErrorCode != 0u) { if (MySQL1.LogLevel > MySQL1.LogLevelType.NONE) { Helper.LogSQLError(MySQL1.Error(), true); } MySQL1.mysql_ping(MySQL1.SQL); MySQL1.IsReady = true; MySQL1.Result result2 = null; result3 = result2; return(result3); } if (MySQL1.LogLevel > MySQL1.LogLevelType.ERRORS) { Helper.LogSQL(query, false); } IntPtr intPtr = MySQL1.mysql_store_result(MySQL1.SQL); if (MySQL1.ErrorCode == 0u && !(intPtr == IntPtr.Zero)) { result = new MySQL1.Result(); result.Fields = MySQL1.mysql_num_fields(intPtr); result.Rows = MySQL1.mysql_num_rows(intPtr); int num2 = 0; while ((long)num2 < (long)((ulong)result.Fields)) { result.Field.Add((MySQL1.Field)Marshal.PtrToStructure(MySQL1.mysql_fetch_field(intPtr), typeof(MySQL1.Field))); num2++; } IntPtr value; while ((value = MySQL1.mysql_fetch_row(intPtr)) != IntPtr.Zero) { result.Row.Add(new MySQL1.Row(result, value)); } MySQL1.mysql_free_result(intPtr); } else { result = null; } } catch (Exception ex) { result = null; Helper.LogSQLError(query, false); Helper.LogSQLError(ex.Message.ToString(), true); } MySQL1.IsReady = true; result3 = result; return(result3); }