private string RepairTables(List <string> listTablesToRepair, ODProgressExtended progExtended) { string results = ""; for (int i = 0; i < listTablesToRepair.Count; i++) { DataTable table = GetTable("REPAIR TABLE " + listTablesToRepair[i]); for (int j = 0; j < table.Rows.Count; j++) { if (progExtended.IsPauseOrCancel()) { break; } string msg = "Repairing table " + listTablesToRepair[i]; textResults.AppendText(msg + "\r\n"); double percent = (100d * i) / listTablesToRepair.Count; progExtended.UpdateProgress(msg, "", percent.ToString("F") + "%", (int)percent, 100); progExtended.Fire(new ODEventArgs(ODEventType.Undefined, new ProgressBarHelper(msg, progressBarEventType: ProgBarEventType.TextMsg))); string line = ""; for (int k = 0; k < table.Columns.Count; k++) { line += table.Rows[j][k].ToString() + ", "; if (listTablesToRepair[i] == "patient") { if (line.Contains("Number of rows changed")) { string data = line.Substring(line.IndexOf("from") + 5).TrimEnd(); string num2 = data.Substring(data.IndexOf("to") + 3).TrimEnd(','); string num1 = data.Remove(data.IndexOf("to")).TrimEnd(); if ((Convert.ToInt32(num1)) > (Convert.ToInt32(num2))) { _patientRowsLost = true; } } } } results += line + "\r\n"; } } return(results); }
private void butCheck_Click(object sender, EventArgs e) { if (_isCheckRunning || _isRepairRunning) { return; } if (!OpenConnection()) { return; } _isCheckRunning = true; string command = "SHOW FULL TABLES WHERE Table_type='BASE TABLE'";//Tables, not views. Does not work in MySQL 4.1, however we test for MySQL version >= 5.0 in PrefL. ODProgressExtended progExtended = new ODProgressExtended(ODEventType.Undefined, new DatabaseIntegrityEvent(), this, tag: new ProgressBarHelper(("Check Initializing..."))); try { Cursor = Cursors.WaitCursor; DataTable tableAllTables = GetTable(command); List <string> listTableNames = tableAllTables.Rows.OfType <DataRow>().Select(x => x[0].ToString()).ToList(); _corruptTables = new List <string>(); List <string> listCheckFailed = new List <string>(); for (int i = 0; i < listTableNames.Count; i++) { string tableName = listTableNames[i]; if (progExtended.IsPauseOrCancel()) { break; } string msg = "Checking table " + tableName; textResults.AppendText(msg + "\r\n"); double percent = (100d * i) / listTableNames.Count; progExtended.UpdateProgress(msg, "", percent.ToString("F") + "%", (int)percent, 100); progExtended.Fire(new ODEventArgs(ODEventType.Undefined, new ProgressBarHelper(msg, progressBarEventType: ProgBarEventType.TextMsg))); try { command = "CHECK TABLE " + tableName; DataTable tableOneTable = GetTable(command); int lastRow = tableOneTable.Rows.Count - 1; int lastCol = tableOneTable.Columns.Count - 1; string lastcell = tableOneTable.Rows[lastRow][lastCol].ToString(); if (lastcell != "OK") { _corruptTables.Add(tableName); } } catch { listCheckFailed.Add(tableName); } } Cursor = Cursors.Default; if (listCheckFailed.Count > 0) { MessageBox.Show("Table check failed for some tables.\r\n" + "For these tables, we could not determine if repair is needed:\r\n\r\n" + string.Join(",", listCheckFailed)); } } catch (Exception ex) { MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); } finally { progExtended.Close(); Cursor = Cursors.Default; _con.Close(); _isCheckRunning = false; } if (_corruptTables.Count == 0) { textResults.AppendText("You have no corrupt tables.\r\n\r\n"); } else { string msgCorrupt = "You have the following corrupt tables:\r\n" + string.Join(",", _corruptTables) + "\r\n" + "Select 'Repair' while on the server to repair corrupt tables. A backup will be made for you."; MessageBox.Show(msgCorrupt); textResults.AppendText(msgCorrupt); } }