本文整理汇总了C#中MySql.Data.MySqlClient.MySqlConnection.Connected方法的典型用法代码示例。如果您正苦于以下问题:C# MySqlConnection.Connected方法的具体用法?C# MySqlConnection.Connected怎么用?C# MySqlConnection.Connected使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MySql.Data.MySqlClient.MySqlConnection
的用法示例。
在下文中一共展示了MySqlConnection.Connected方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main()
{
Console.Title = "Table Comparator V 2.0";
MySqlConnection connection = new MySqlConnection(Settings.Default.ConnectionString);
if (!connection.Connected())
return;
Console.WriteLine("-================================== Welcome ==================================-");
Console.WriteLine("==========||========================================================||=======||");
Console.WriteLine("Statistics|| Total: || Bad fields: || Table: || % ||");
Console.WriteLine("==========||========================================================||=======||");
DirectoryInfo info = new DirectoryInfo("tables");
FileInfo[] structures = info.GetFiles("*.xml", SearchOption.TopDirectoryOnly);
foreach (FileInfo document in structures)
{
XmlSerializer serializer = new XmlSerializer(typeof(Table));
Table table = (Table)serializer.Deserialize(document.OpenRead());
string key = table.Fields[0];
string prefix = table.Prefix;
string tableName = table.TableName;
StringBuilder cmdText = new StringBuilder(1024);
{
cmdText.Append("SELECT ");
foreach (string field in table.Fields)
cmdText.AppendFormat("{0}.{1}, ", tableName, field);
foreach (string field in table.Fields)
cmdText.AppendFormat("{0}_{1}.{2}, ", tableName, prefix, field);
cmdText.AppendFormat("FROM {0} INNER JOIN {0}_sniff ON {0}.{1} = {0}_sniff.{1} ORDER BY {0}.{1};", tableName, key).AppendLine().Replace(", FROM", " FROM");
}
List<List<object>> normalDataTemplates = new List<List<object>>(UInt16.MaxValue);
List<List<object>> sniffedDataTemplates = new List<List<object>>(UInt16.MaxValue);
try
{
using (MySqlCommand command = new MySqlCommand(cmdText.ToString(), connection))
using (MySqlDataReader reader = command.ExecuteReader())
{
int count = reader.FieldCount / 2;
while (reader.Read())
{
List<object> normalTemplate = new List<object>(count);
List<object> sniffTemplate = new List<object>(count);
for (int i = 0; i < count; ++i)
normalTemplate.Add(reader[i]);
for (int i = count; i < (count * 2); ++i)
sniffTemplate.Add(reader[i]);
normalDataTemplates.Add(normalTemplate);
sniffedDataTemplates.Add(sniffTemplate);
}
}
}
catch (Exception e)
{
Console.WriteLine("ERROR: {0}", e.Message);
continue;
}
int badFieldCount = 0;
StringBuilder content = new StringBuilder(UInt16.MaxValue);
for (int i = 0; i < normalDataTemplates.Count; ++i)
{
bool error = false;
StringBuilder contentInternal = new StringBuilder();
List<object> normalTemplate = normalDataTemplates[i];
List<object> sniffTemplate = sniffedDataTemplates[i];
object entry = normalTemplate[0];
if (!entry.Equals(sniffTemplate[0]))
continue;
contentInternal.AppendFormat("UPDATE `{0}` SET ", tableName);
for (int j = 1; j < normalTemplate.Count; ++j)
{
if (normalTemplate[j].Equals(sniffTemplate[j]))
continue;
contentInternal.AppendFormat(NumberFormatInfo.InvariantInfo, "`{0}` = '{1}', ", table.Fields[j], sniffTemplate[j]);
error = true;
}
contentInternal.Remove(contentInternal.Length - 2, 2);
contentInternal.AppendFormat(" WHERE `{0}` = {1};", key, entry).AppendLine();
if (!error)
continue;
content.Append(contentInternal);
++badFieldCount;
}
if (badFieldCount > 0)
//.........这里部分代码省略.........