private static void Enqueue <T>(T obj) { if (!_Updating) { OnAbort(); return; } IDictionary <string, SimpleType> data = null; LegendState state = ObjectStates.FirstOrDefault(s => s.Compile(obj, out data)); if (state != null && data != null && data.Count > 0) { ExportQueue.GetOrAdd(state.TableName, new ConcurrentStack <QueuedData>()).Push( new QueuedData { RawData = data, SqlData = data.Select(kd => new MySQLData(kd.Key, SQL.Encode(kd.Value, true))).ToArray() }); } }
public virtual bool CanConnect() { return(!IsDisposed && MySQL.CanConnect(this)); }
/// <summary> /// Attempts to connect to the specified MySQL Server with the given settings. /// </summary> /// <param name="retries">Retry connection attempts this many times if the initial connection fails.</param> /// <param name="createDB">If a database name is specified, should it try to create it if it doesn't exist?</param> /// <returns>True if connection successful</returns> public bool Connect(int retries = 0, bool createDB = false) { if (IsDisposed) { return(false); } if (Connected) { return(true); } if (Connecting) { return(false); } if (!CanConnect()) { return(false); } var conStr = Credentials.GetConnectionString(); //MySQL.CSOptions.ToConsole("{0}", conStr); var connected = VitaNexCore.TryCatchGet( () => { if (Instance == null) { MySQL.CSOptions.ToConsole("Connection Attempt."); Instance = new OdbcConnection(conStr); Instance.InfoMessage += OnMessage; Instance.Open(); VitaNexCore.WaitWhile(() => Instance.State == ConnectionState.Connecting, TimeSpan.FromSeconds(3)); if (Instance.State == ConnectionState.Broken) { Instance.Close(); } if (Instance.State == ConnectionState.Open) { MySQL.CSOptions.ToConsole("Connection Successful."); MySQL.Connected(this); if (!String.IsNullOrWhiteSpace(Credentials.Database)) { if (createDB) { NonQuery( @"CREATE DATABASE IF NOT EXISTS `{0}` DEFAULT CHARSET `utf8` DEFAULT COLLATE `utf8_bin`", Credentials.Database); } Instance.ChangeDatabase(Credentials.Database); } return(true); } } if (Instance == null) { return(false); } if (Instance.State != ConnectionState.Open) { Instance.Close(); for (var i = 1; i <= retries; i++) { MySQL.CSOptions.ToConsole("Connection Attempt {0}.", i); Instance.Open(); VitaNexCore.WaitWhile(() => Instance.State == ConnectionState.Connecting, TimeSpan.FromSeconds(3)); if (Instance.State != ConnectionState.Open) { Instance.Close(); continue; } MySQL.CSOptions.ToConsole("Connection Successful."); OnConnected(); if (!String.IsNullOrWhiteSpace(Credentials.Database)) { if (createDB) { NonQuery( @"CREATE DATABASE IF NOT EXISTS `{0}` DEFAULT CHARSET `utf8` DEFAULT COLLATE `utf8_bin` DEFAULT ENGINE `INNODB`", Credentials.Database); } Instance.ChangeDatabase(Credentials.Database); } return(true); } } if (Instance.State != ConnectionState.Open) { Instance.Close(); } return(false); }, MySQL.CSOptions.ToConsole); if (!connected) { MySQL.CSOptions.ToConsole("Connection Failed."); Close(); } return(connected); }
protected virtual void OnConnected() { MySQL.Connected(this); }
private static void AppendWhere(StringBuilder query, params MySQLCondition[] conditions) { if (query == null || query.Length == 0 || conditions == null || conditions.Length == 0) { return; } query.Append(" WHERE "); for (int x = 0; x < conditions.Length; x++) { if (x > 0) { query.AppendFormat(" {0} ", conditions[x].QueryJoin); } query.AppendFormat( "`{0}` {1} '{2}'", conditions[x].Key, conditions[x].GetOperation(), MySQL.Escape(conditions[x].ValueString)); } }