public void dropTable(MysqlHandler connection, string tableName, bool backup) { bool disconnecting = false; if (!connection.isConnected()) { disconnecting = true; connection.connect(); } if (backup) { dropTable(connection, tableName + "_backup", false); copyTable(connection, tableName, tableName + "_backup"); } string sql = "DROP TABLE " + tableName; connection.sql_update(sql); if (disconnecting) { connection.disConnect(); } }
private void toolStripButton1_Click(object sender, EventArgs e) { Connection = new MysqlHandler(usedProfile); Connection.connect(); progress.Maximum = queryList.SelectedItems.Count; progress.Value = 0; for (int i = queryList.SelectedItems.Count - 1; i >= 0; i--) { state.Text = queryList.SelectedItems[i].SubItems[1].Text; Connection.sql_update(queryList.SelectedItems[i].SubItems[1].Text); if (Connection.lastSqlErrorMessage != "") { if (MessageBox.Show(this, Connection.lastSqlErrorMessage + "\n Abort ? ", "SQL Error", MessageBoxButtons.YesNo, MessageBoxIcon.Hand) == DialogResult.Yes) { break; } } queryList.SelectedItems[i].Remove(); progress.Value = progress.Maximum - i; Application.DoEvents(); } Connection.disConnect(); }
public bool copyCreationTable(MysqlHandler connection, string sourceTable, MysqlHandler targetConnection) { bool disconnecting = false; bool targetDisconnecting = false; if (!connection.isConnected()) { disconnecting = true; connection.connect(); } if (!targetConnection.isConnected()) { targetDisconnecting = true; targetConnection.connect(); } string createSql = connection.getTableCreationString(sourceTable); if (createSql != "") { targetConnection.sql_update(createSql); } if (disconnecting) { connection.disConnect(); } if (targetDisconnecting) { targetConnection.disConnect(); } targetConnection.resetTableList(); return(targetConnection.tableExists(sourceTable)); }
private void button1_Click(object sender, EventArgs e) { if (lastSelectedId != "") { MysqlHandler mysql = new MysqlHandler(watchProfil); mysql.connect(); string sql = "KILL " + lastSelectedId; mysql.sql_update(sql); mysql.disConnect(); kill_btn.Text = "KILL "; } }
public void copyTable(MysqlHandler connection, string sourceTable, MysqlHandler targetConnection) { bool disconnecting = false; bool targetDisconnecting = false; if (!connection.isConnected()) { disconnecting = true; connection.connect(); } if (!targetConnection.isConnected()) { targetDisconnecting = true; targetConnection.connect(); } targetConnection.lastSqlErrorMessage = ""; if (!targetConnection.tableExists(sourceTable)) { string createSql = connection.getTableCreationString(sourceTable); targetConnection.sql_update(createSql); if (targetConnection.lastSqlErrorMessage.Length > 0) { MessageBox.Show(createSql + "\n\n" + targetConnection.lastSqlErrorMessage); targetConnection.lastSqlErrorMessage = ""; } else { copyRows(connection, sourceTable, targetConnection); } } if (disconnecting) { connection.disConnect(); } if (targetDisconnecting) { targetConnection.disConnect(); } targetConnection.resetTableList(); }
public void copyTable(MysqlHandler connection, string sourceTable, string targetTable) { bool disconnecting = false; string sql = "CREATE TABLE " + targetTable + " SELECT * FROM " + sourceTable; if (!connection.isConnected()) { disconnecting = true; connection.connect(); } connection.sql_update(sql); if (disconnecting) { connection.disConnect(); } }
public Int64 copyValues(MysqlHandler connection, string sourceTable, Int64 start, MysqlHandler targetConnection) { Int64 count = 0; Int64 refresher = 0; List <MysqlStruct> Struct = connection.getAllFieldsStruct(sourceTable); string addToField = sourceTable + "."; if (showProgress && msg.Visible) { msg.progressBar.Maximum = (int)this.copyRowLimit + 1; } if (connection.isConnected()) { MySql.Data.MySqlClient.MySqlDataReader Reader = connection.sql_select("SELECT * FROM " + sourceTable + " LIMIT " + start + "," + this.copyRowLimit); if (Reader != null) { //if (Reader.RecordsAffected==-1) return 0; while (Reader.Read()) { count++; refresher++; string insertSql = "INSERT INTO " + sourceTable + " SET "; string add = ""; for (int i = 0; i < Reader.FieldCount; i++) { if (refresher > 1000) { if (showProgress && msg.Visible) { msg.msg.Text = "Copying Table " + sourceTable + " block: " + start + "/" + count; msg.progressBar.Value = (int)count; msg.progressBar.Refresh(); msg.Refresh(); msg.Focus(); } refresher = 0; } System.Type fType = Reader.GetFieldType(i); Object chk = null; try { chk = Reader.GetValue(i); } catch (Exception) { //throw; } if (chk != null) { int hash = chk.GetHashCode(); string dd = chk.ToString(); if (chk != null && dd != "") { switch (fType.Name) { case "Int32": case "UInt32": case "Int64": case "UInt64": Int64 val = Reader.GetInt64(i); insertSql += add + addToField + Struct[i].name + " = " + val; break; case "Single": case "Float": float fVal = Reader.GetFloat(i); insertSql += add + addToField + Struct[i].name + " = '" + fVal.ToString().Replace(',', '.') + "'"; break; case "Double": double dVal = Reader.GetDouble(i); insertSql += add + addToField + Struct[i].name + " = '" + dVal.ToString().Replace(',', '.') + "'"; break; case "DateTime": DateTime dt = Reader.GetDateTime(i); String dtValue = zeroVal(dt.Year) + "-" + zeroVal(dt.Month) + "-" + zeroVal(dt.Day) + " " + dt.TimeOfDay; insertSql += add + addToField + Struct[i].name + " = '" + dtValue + "'"; break; case "Boolean": bool bval = Reader.GetBoolean(i); if (bval) { insertSql += add + addToField + Struct[i].name + " = 1"; } else { insertSql += add + addToField + Struct[i].name + " = 0"; } break; default: string sval = Reader.GetString(i).Replace("'", @"\'"); insertSql += add + addToField + Struct[i].name + " = '" + sval + "'"; break; } add = ","; } } } //returnValue += insertSql + ";\n"; targetConnection.sql_update(insertSql); } Reader.Close(); } } return(count); }