/// <summary> /// Initializes a new instance of the <see cref="DbObjectSelectionPanel"/> class. /// </summary> public DbObjectSelectionPanel() { _excelSelectionContainsData = false; _wbConnection = null; Filter = string.Empty; LoadedProcedures = new List <DbProcedure>(); LoadedTables = new List <DbTable>(); LoadedViews = new List <DbView>(); InitializeComponent(); ConnectionNameLabel.Paint += Label_Paint; UserIPLabel.Paint += Label_Paint; SchemaLabel.Paint += Label_Paint; InheritFontToControlsExceptionList.AddRange(new[] { ExportToNewTableHotLabel.Name, SelectDatabaseObjectHotLabel.Name, ImportDataHotLabel.Name, EditDataHotLabel.Name, AppendDataHotLabel.Name, ImportMultiHotLabel.Name }); DBObjectList.AddHeaderNode("Tables"); DBObjectList.AddHeaderNode("Views"); DBObjectList.AddHeaderNode("Procedures"); }
/// <summary> /// Initializes a new instance of the <see cref="NewSchemaDialog"/> class. /// </summary> public NewSchemaDialog(MySqlWorkbenchConnection wbConnection) { _wbConnection = wbConnection ?? throw new ArgumentNullException(nameof(wbConnection)); InitializeComponent(); SchemaName = _wbConnection.GetSchemaNameAvoidingDuplicates(null); CollationComboBox.SetupCollations(_wbConnection, "Server Default"); }
/// <summary> /// Tests the current connection until the user enters a correct password. /// </summary> /// <param name="wbConnection">A <see cref="MySqlWorkbenchConnection"/> object representing the connection to a MySQL server instance selected by users.</param> /// <param name="tryConnectionBeforeAskingForPassword">Flag indicating whether a connection test is made with the connection as is before asking for a password</param> /// <returns>A <see cref="PasswordDialogFlags"/> containing data about the operation.</returns> public static PasswordDialogFlags TestConnectionAndRetryOnWrongPassword(this MySqlWorkbenchConnection wbConnection, bool tryConnectionBeforeAskingForPassword = true) { PasswordDialogFlags passwordFlags = new PasswordDialogFlags(wbConnection) { // Assume a wrong password at first so if the connection is not tested without a password we ensure to ask for one. ConnectionResult = TestConnectionResult.WrongPassword }; // First connection attempt with the connection exactly as loaded (maybe without a password). if (tryConnectionBeforeAskingForPassword) { passwordFlags.ConnectionResult = wbConnection.TestConnectionAndReturnResult(false); passwordFlags.Cancelled = passwordFlags.ConnectionResult == TestConnectionResult.PasswordExpired; // If on the first attempt a connection could not be made and not because of a bad password, exit. if (!passwordFlags.ConnectionSuccess && !passwordFlags.WrongPassword) { return(passwordFlags); } } // If the connection does not have a stored password or the stored password failed then ask for one and retry. while (!passwordFlags.ConnectionSuccess && passwordFlags.WrongPassword) { passwordFlags = PasswordDialog.ShowConnectionPasswordDialog(wbConnection, true); if (passwordFlags.Cancelled) { break; } wbConnection.Password = passwordFlags.NewPassword; } return(passwordFlags); }
/// <summary> /// Checks if a Workbench connection is being monitored already by a <see cref="MySqlService"/> in any of the <see cref="Machines"/>. /// </summary> /// <param name="connection">A Workbench connection to check for.</param> /// <returns><c>true</c> if the connection is already being monitored, <c>false</c> otherwise.</returns> public bool IsWorkbenchConnectionAlreadyMonitored(MySqlWorkbenchConnection connection) { if (connection == null) { return(false); } foreach (var machine in Machines) { foreach (var mySqlService in machine.Services) { if (mySqlService.WorkbenchConnections == null) { continue; } if (mySqlService.WorkbenchConnections.Exists(wbConn => wbConn.Id == connection.Id)) { return(true); } } } return(false); }
/// <summary> /// Initializes a new instance of the <see cref="EditDataDialog"/> class. /// </summary> /// <param name="parentTaskPane">The <see cref="ExcelAddInPane"/> from which the <see cref="EditDataDialog"/> is called.</param> /// <param name="parentWindow">The parent window assigned to the <see cref="EditDataDialog"/> to be opened as a dialog.</param> /// <param name="wbConnection">The connection to a MySQL server instance selected by users.</param> /// <param name="originalEditDataRange">The Excel cells range containing the MySQL table's data being edited.</param> /// <param name="importTable">The table containing the data imported from the MySQL table that will be edited.</param> /// <param name="editingWorksheet">The Excel worksheet tied to the current editing session.</param> public EditDataDialog(ExcelAddInPane parentTaskPane, IWin32Window parentWindow, MySqlWorkbenchConnection wbConnection, ExcelInterop.Range originalEditDataRange, MySqlDataTable importTable, ExcelInterop.Worksheet editingWorksheet) { _mouseDownPoint = Point.Empty; _neverBeenShown = true; _updatingUSeOptimisticUpdateSetting = false; InitializeComponent(); var existingProtectionKey = editingWorksheet.GetProtectionKey(); WorksheetProtectionKey = string.IsNullOrEmpty(existingProtectionKey) ? Guid.NewGuid().ToString() : existingProtectionKey; _parentTaskPane = parentTaskPane; _parentWindow = parentWindow; _wbConnection = wbConnection; _editDataRange = originalEditDataRange; _mySqlTable = importTable; EditingWorksheet = editingWorksheet; EditingWorksheet.SelectionChange += EditingWorksheet_SelectionChange; ResetToolTip(); Opacity = 0.60; AddNewRowToEditingRange(false); _useOptimisticUpdateForThisSession = Settings.Default.EditUseOptimisticUpdate; ForThisSessionToolStripMenuItem.Checked = _useOptimisticUpdateForThisSession; ForAllSessionsToolStripMenuItem.Checked = _useOptimisticUpdateForThisSession; UseOptimisticUpdateToolStripMenuItem.Checked = _useOptimisticUpdateForThisSession; Settings.Default.PropertyChanged += SettingsPropertyValueChanged; }
/// <summary> /// Returns the index of the image that corresponds to the <see cref="MySqlWorkbenchConnection.ConnectionMethodType"/> of the given <see cref="MySqlWorkbenchConnection"/>. /// </summary> /// <param name="connection">A <see cref="MySqlWorkbenchConnection"/> instance.</param> /// <returns>The index of the image that corresponds to the <see cref="MySqlWorkbenchConnection.ConnectionMethodType"/>.</returns> private int GetConnetionImageIndexFromType(MySqlWorkbenchConnection connection) { if (connection == null) { return(-1); } if (connection.IsFabricManaged) { return(0); } switch (connection.ConnectionMethod) { case MySqlWorkbenchConnection.ConnectionMethodType.FabricManaged: return(0); case MySqlWorkbenchConnection.ConnectionMethodType.LocalUnixSocketOrWindowsPipe: return(1); case MySqlWorkbenchConnection.ConnectionMethodType.Ssh: return(2); case MySqlWorkbenchConnection.ConnectionMethodType.Tcp: return(3); case MySqlWorkbenchConnection.ConnectionMethodType.XProtocol: return(4); default: return(-1); } }
/// <summary> /// Gets a schema name that is unique among the schemas in the current connection. /// </summary> /// <param name="connection">MySQL Workbench connection to a MySQL server instance selected by users.</param> /// <param name="proposedName">The proposed name for a new schema.</param> /// <returns>A unique schema name.</returns> public static string GetSchemaNameAvoidingDuplicates(this MySqlWorkbenchConnection connection, string proposedName) { if (connection == null) { return(null); } if (string.IsNullOrEmpty(proposedName)) { proposedName = DEFAULT_NEW_SCHEMA_NAME; } var schemas = connection.GetSchemaCollection("Databases", null); if (schemas == null || schemas.Rows.Count == 0) { return(proposedName); } int suffix = 2; string finalName = proposedName; while (schemas.Rows.Cast <DataRow>().Any(schemaRow => string.Equals(schemaRow["DATABASE_NAME"].ToString(), finalName, StringComparison.InvariantCultureIgnoreCase))) { finalName = proposedName + suffix++; } return(finalName); }
/// <summary> /// Initializes a new instance of the <see cref="DbObject"/> class. /// </summary> /// <param name="connection">The MySQL Workbench connection to a MySQL server instance selected by users.</param> /// <param name="name">The name of the MySQL database object.</param> protected DbObject(MySqlWorkbenchConnection connection, string name) { Connection = connection; Disposed = false; Excluded = false; Name = name; }
/// <summary> /// Gets the SQL statements needed to create a new schema in the MySQL server instance specified in the given connection. /// </summary> /// <param name="connection">MySQL Workbench connection to a MySQL server instance selected by users.</param> /// <param name="schemaName">The name of the new schema.</param> /// <param name="charset">The default character set assigned to the new schema. If <c>null</c> or empty the server's default character set is used.</param> /// <param name="collation">The collation of the character set, meaningful only if the <see cref="charset"/> parameter is not null or empty. If <c>null</c> or empty the default collation is used.</param> /// <param name="grantPrivileges">Flag indicating whether all privileges are granted to the user that opened the connection.</param> /// <returns>The SQL statement used to create the new schema.</returns> public static string GetCreateSchemaSql(this MySqlWorkbenchConnection connection, string schemaName, string charset, string collation, bool grantPrivileges) { if (connection == null && grantPrivileges) { return(null); } var sqlBuilder = new StringBuilder(100); sqlBuilder.Append(MySqlStatement.STATEMENT_CREATE_SCHEMA); sqlBuilder.AppendFormat(" `{0}`", schemaName); if (!string.IsNullOrEmpty(charset)) { sqlBuilder.AppendFormat(" {0} {1}", MySqlStatement.STATEMENT_DEFAULT_CHARSET, charset); if (!string.IsNullOrEmpty(collation)) { sqlBuilder.AppendFormat(" {0} {1}", MySqlStatement.STATEMENT_COLLATE, collation); } } if (!grantPrivileges) { return(sqlBuilder.ToString()); } sqlBuilder.Append(";"); sqlBuilder.Append(Environment.NewLine); sqlBuilder.AppendFormat("{0} `{1}`.* TO '{2}'.'{3}';", MySqlStatement.STATEMENT_GRANT_ALL, schemaName, connection.UserName, connection.Host); return(sqlBuilder.ToString()); }
/// <summary> /// Executes the given query and returns the result set in a <see cref="DataTable"/> object. /// </summary> /// <param name="connection">MySQL Workbench connection to a MySQL server instance selected by users.</param> /// <param name="query">Select query to be sent to the MySQL Server.</param> /// <param name="tableIndex">The index of the table in the <see cref="DataSet"/> to be returned.</param> /// <returns>Table containing the results of the query.</returns> public static DataTable GetDataFromSelectQuery(this MySqlWorkbenchConnection connection, string query, int tableIndex = 0) { if (connection == null) { return(null); } DataSet ds = null; try { var connectionBuilder = connection.GetConnectionStringBuilder(); connectionBuilder.AllowUserVariables = true; ds = MySqlHelper.ExecuteDataset(connectionBuilder.ConnectionString, query); } catch (Exception ex) { MiscUtilities.ShowCustomizedErrorDialog(string.Format(Resources.UnableToRetrieveData, "from query: ", query), ex.Message); MySqlSourceTrace.WriteAppErrorToLog(ex); } return(ds == null || ds.Tables.Count <= 0 || tableIndex < 0 || tableIndex >= ds.Tables.Count ? null : ds.Tables[tableIndex]); }
/// <summary> /// Adds a given connection to the corresponding connections group list depending on its connection type (local VS remote). /// </summary> /// <param name="conn">Object containing the data to open a connection, normally shared with Workbench.</param> private void AddConnectionToList(MySqlWorkbenchConnection conn) { if (conn == null || ConnectionsList.HeaderNodes.Count < 2) { return; } var headerNode = ConnectionsList.HeaderNodes[conn.IsLocalConnection ? 0 : 1]; var node = ConnectionsList.AddConnectionNode(headerNode, conn); node.Enable = true; switch (conn.ConnectionMethod) { case MySqlWorkbenchConnection.ConnectionMethodType.Tcp: node.ImageIndex = 0; break; case MySqlWorkbenchConnection.ConnectionMethodType.LocalUnixSocketOrWindowsPipe: node.ImageIndex = 1; break; case MySqlWorkbenchConnection.ConnectionMethodType.Ssh: node.ImageIndex = node.Enable ? 2 : 4; break; case MySqlWorkbenchConnection.ConnectionMethodType.XProtocol: // This connection is deprecated and code should not hit this case, but this is left as a safeguard. node.Enable = false; node.ImageIndex = node.Enable ? 3 : 5; break; } }
/// <summary> /// Initializes a new instance of the <see cref="PasswordDialogFlags"/> struct. /// </summary> /// <param name="wbConnection"></param> public PasswordDialogFlags(MySqlWorkbenchConnection wbConnection) { Cancelled = false; ConnectionResult = TestConnectionResult.None; NewPassword = null; OldPassword = wbConnection != null ? wbConnection.Password : null; }
/// <summary> /// Initializes a new instance of the <see cref="DbSchema"/> class. /// </summary> /// <param name="connection">The MySQL Workbench connection to a MySQL server instance selected by users.</param> /// <param name="name">The name of the MySQL database object.</param> /// <param name="characterSet">The default character set used for text encoding on this schema.</param> /// <param name="collation">The default collation used for text enconding on this schema.</param> /// <param name="displayCollation">Flag indicating whether the default collation of this schema is displayed below its name.</param> public DbSchema(MySqlWorkbenchConnection connection, string name, string characterSet, string collation, bool displayCollation) : base(connection, name) { CharacterSet = characterSet; Collation = collation; DisplayCollation = displayCollation; }
/// <summary> /// Executes the given query and returns the result set in a <see cref="DataTable"/> object. /// </summary> /// <param name="connection">MySQL Workbench connection to a MySQL server instance selected by users.</param> /// <param name="query">Select query to be sent to the MySQL Server.</param> /// <param name="tableIndex">The index of the table in the <see cref="DataSet"/> to be returned.</param> /// <returns>Table containing the results of the query.</returns> public static DataTable GetDataFromSelectQuery(this MySqlWorkbenchConnection connection, string query, int tableIndex = 0) { if (connection == null) { return(null); } DataSet ds = null; try { var connectionBuilder = connection.GetConnectionStringBuilder(); ds = MySqlHelper.ExecuteDataset(connectionBuilder.ConnectionString, query); } catch (Exception ex) { Logger.LogException(ex, true, string.Format(Resources.UnableToRetrieveData, "query: ", query)); } var dataTable = ds == null || ds.Tables.Count <= 0 || tableIndex < 0 || tableIndex >= ds.Tables.Count ? null : ds.Tables[tableIndex]; return(Settings.Default.ImportFloatingPointDataAsDecimal ? dataTable.ConvertApproximateFloatingPointDataTypeColumnsToExact() : dataTable); }
/// <summary> /// Event delegate method fired before the <see cref="MonitorMySqlServerInstancesDialog"/> dialog is closed. /// </summary> /// <param name="sender">Sender object.</param> /// <param name="e">Event arguments.</param> private void MonitorMySQLServerInstancesDialog_FormClosing(object sender, FormClosingEventArgs e) { if (DialogResult != DialogResult.OK || SelectedWorkbenchConnection == null || WorkbenchConnectionsListView.SelectedItems.Count <= 0 || WorkbenchConnectionsListView.SelectedItems[0].Checked) { ResetChangeCursorDelegate(false); return; } var infoProperties = InfoDialogProperties.GetYesNoDialogProperties( InfoDialog.InfoType.Info, Resources.ConnectionAlreadyInInstancesTitle, Resources.ConnectionAlreadyInInstancesDetail, Resources.ConnectionAlreadyInInstancesSubDetail); infoProperties.CommandAreaProperties.DefaultButton = InfoDialog.DefaultButtonType.Button2; infoProperties.CommandAreaProperties.DefaultButtonTimeout = 30; var infoResult = InfoDialog.ShowDialog(infoProperties); if (infoResult.DialogResult == DialogResult.Yes) { ResetChangeCursorDelegate(false); return; } SelectedWorkbenchConnection = null; e.Cancel = true; }
/// <summary> /// Initializes a new instance of the <see cref="ImportConnectionInfo" /> class. /// </summary> /// <param name="mySqlTable">MySqlDataTable object related to the <see cref="ImportConnectionInfo" />.</param> /// <param name="atCell">The top left Excel cell of the new <see cref="ExcelInterop.ListObject"/>.</param> /// <param name="addSummaryRow">Flag indicating whether to include a row with summary fields at the end of the data rows.</param> public ImportConnectionInfo(MySqlDataTable mySqlTable, ExcelInterop.Range atCell, bool addSummaryRow) : this() { if (mySqlTable == null) { throw new ArgumentNullException(nameof(mySqlTable)); } _connection = mySqlTable.WbConnection; MySqlTable = mySqlTable; SchemaName = mySqlTable.SchemaName; TableName = mySqlTable.TableName; ConnectionId = mySqlTable.WbConnection.Id; ImportColumnNames = mySqlTable.ImportColumnNames; OperationType = mySqlTable.OperationType; ProcedureResultSetIndex = mySqlTable.ProcedureResultSetIndex; SelectQuery = mySqlTable.SelectQuery; var activeWorkbook = Globals.ThisAddIn.ActiveWorkbook; WorkbookGuid = activeWorkbook.GetOrCreateId(); WorkbookName = activeWorkbook.Name; WorkbookFilePath = activeWorkbook.FullName; ExcelInterop.Worksheet worksheet = activeWorkbook.ActiveSheet; WorksheetName = worksheet.Name; InitializeConnectionObjects(atCell, addSummaryRow); }
/// <summary> /// Event delegate method fired when the <see cref="DialogOKButton"/> button is clicked. /// </summary> /// <param name="sender">Sender object.</param> /// <param name="e">Event arguments.</param> private void DialogOKButton_Click(object sender, EventArgs e) { if (WorkbenchConnectionsListView.SelectedItems.Count > 0) { SelectedWorkbenchConnection = WorkbenchConnectionsListView.SelectedItems[0].Tag as MySqlWorkbenchConnection; } }
/// <summary> /// Checks if the given connection may be using SSL. /// </summary> /// <param name="connection">MySQL Workbench connection to a MySQL server instance selected by users.</param> /// <returns><c>true</c> if the connection uses SSL, <c>false</c> otherwise.</returns> public static bool IsSsl(this MySqlWorkbenchConnection connection) { return(connection.UseSsl || !(string.IsNullOrWhiteSpace(connection.SslCa) && string.IsNullOrWhiteSpace(connection.SslCert) && string.IsNullOrWhiteSpace(connection.SslCipher) && string.IsNullOrWhiteSpace(connection.SslKey))); }
/// <summary> /// Initializes a new instance of the <see cref="MySqlListViewNode"/> class holding MySQL connection information. /// </summary> /// <param name="connection">The <see cref="MySqlWorkbenchConnection"/> associated to the node.</param> /// <param name="excludeFromMultiSelection">Flag indicating whether the tree node is skipped during a multiple selection.</param> public MySqlListViewNode(MySqlWorkbenchConnection connection, bool excludeFromMultiSelection = false) : this(connection.Name, string.Empty, MySqlNodeType.Connection, excludeFromMultiSelection) { string hostName = connection.GetHostNameForConnectionSubtitle(); Subtitle = string.Format("User: {0}, Host: {1}:{2}", connection.UserName, hostName, connection.Port); WbConnection = connection; }
/// <summary> /// Executes a routine and returns all result sets as tables within a <see cref="DataSet"/>. /// </summary> /// <param name="connection">MySQL Workbench connection to a MySQL server instance selected by users.</param> /// <param name="routineName">Qualified routine name (i.e. Schema.Routine).</param> /// <param name="routineParameters">Array of arguments passed to the routine parameters.</param> /// <returns><see cref="DataSet"/> where each table within it represents each of the result sets returned by the routine.</returns> public static DataSet ExecuteRoutine(this MySqlWorkbenchConnection connection, string routineName, params MySqlParameter[] routineParameters) { if (connection == null) { return(null); } // Create empty return DataSet var ds = new DataSet(); // Create & open a SqlConnection, and dispose of it after we are done. using (var baseConnection = new MySqlConnection(connection.GetConnectionStringBuilder().ConnectionString)) { baseConnection.Open(); // Create a command and prepare it for execution using (var cmd = new MySqlCommand { Connection = baseConnection, CommandText = routineName, CommandType = CommandType.StoredProcedure }) { if (routineParameters != null) { foreach (var p in routineParameters) { cmd.Parameters.Add(p); } } using (var reader = cmd.ExecuteReader()) { var resultSetTable = reader.ReadResultSet("ResultSet"); if (resultSetTable != null) { ds.Tables.Add(resultSetTable); } var resultSetIndex = 1; while (reader.NextResult()) { resultSetTable = reader.ReadResultSet("ResultSet" + resultSetIndex++); if (resultSetTable != null) { ds.Tables.Add(resultSetTable); } } } // Detach the MySqlParameters from the command object, so they can be used again. cmd.Parameters.Clear(); } // Return the data set return(ds); } }
/// <summary> /// Closes the current connection, editing dialogs and puts the welcome panel in focus. /// </summary> /// <param name="givePanelFocus">Flag indicating whether the <see cref="WelcomePanel"/> is given focus.</param> public void CloseConnection(bool givePanelFocus) { WbConnection = null; if (givePanelFocus) { WelcomePanel1.BringToFront(); } // Free up open Edit Dialogs WorkbookConnectionInfos.CloseWorkbookEditConnectionInfos(Globals.ThisAddIn.ActiveWorkbook); }
/// <summary> /// Sets additional properties used by each connection opened in MySQL for Excel that are not persisted in a <see cref="MySqlWorkbenchConnection"/>. /// </summary> /// <param name="connection">MySQL Workbench connection to a MySQL server instance selected by users.</param> public static void SetAdditionalConnectionProperties(this MySqlWorkbenchConnection connection) { if (connection == null) { return; } connection.AllowUserVariables = true; connection.AllowZeroDateTimeValues = true; connection.CharacterSet = "utf8"; connection.TreatTinyIntAsBoolean = false; }
/// <summary> /// DO NOT REMOVE. Default constructor required for serialization-deserialization. /// </summary> public ImportConnectionInfo() { _connection = null; _connectionId = null; _excelTable = null; _excelTableName = string.Empty; _schemaName = string.Empty; ConnectionInfoError = ConnectionInfoErrorType.None; LastAccess = DateTime.Now; MySqlTable = null; ToolsExcelTable = null; }
/// <summary> /// Checks if an index with the given name exists in the given schema and table. /// </summary> /// <param name="connection">MySQL Workbench connection to a MySQL server instance selected by users.</param> /// <param name="schemaName">Name of the database schema where the index resides.</param> /// <param name="tableName">Name of the database table where the index resides.</param> /// <param name="indexName">Name of the index to look for.</param> /// <returns><c>true</c> if the index exists, <c>false</c> otherwise.</returns> public static bool IndexExistsInSchema(this MySqlWorkbenchConnection connection, string schemaName, string tableName, string indexName) { if (string.IsNullOrEmpty(indexName)) { return(false); } schemaName = string.IsNullOrEmpty(schemaName) ? connection.Schema : schemaName; var dt = connection.GetSchemaCollection("Indexes", null, schemaName, tableName, indexName); return(dt != null && dt.Rows.Count > 0); }
/// <summary> /// Unlocks tables locked in the current session. /// </summary> /// <param name="connection">MySQL Workbench connection to a MySQL server instance selected by users.</param> public static void UnlockTablesInClientSession(this MySqlWorkbenchConnection connection) { try { const string SQL = "UNLOCK TABLES"; MySqlHelper.ExecuteNonQuery(connection.GetConnectionStringBuilder().ConnectionString, SQL); } catch (Exception ex) { Logger.LogException(ex, true, Resources.UnableToUnlockTablesError); } }
/// <summary> /// Initializes a new instance of the <see cref="PasswordDialog"/> class. /// </summary> /// <param name="wbConnection">A <see cref="MySqlWorkbenchConnection"/> object representing the connection to a MySQL server instance selected by users.</param> /// <param name="testConnection">Flag indicating whether the connection is tested after setting the password.</param> /// <param name="passwordExpired">Flag indicating if the dialog will be used to set a new password when an old one expired.</param> public PasswordDialog(MySqlWorkbenchConnection wbConnection, bool testConnection, bool passwordExpired) { _testConnection = testConnection; _passwordFlags = new PasswordDialogFlags(wbConnection); InitializeComponent(); PasswordExpiredDialog = passwordExpired; _wbConnection = wbConnection; UserValueLabel.Text = _wbConnection.UserName; ConnectionValueLabel.Text = _wbConnection.Name + @" - " + _wbConnection.HostIdentifier; PasswordTextBox.Text = _wbConnection.Password; SetDialogInterface(); }
/// <summary> /// Shows the connection password dialog to users and returns the entered password. /// </summary> /// <param name="wbConnection">A <see cref="MySqlWorkbenchConnection"/> object representing the connection to a MySQL server instance selected by users.</param> /// <param name="testConnection">Flag indicating whether the connection is tested after setting the password.</param> /// <returns>A <see cref="PasswordDialogFlags"/> containing data about the operation.</returns> public static PasswordDialogFlags ShowExpiredPasswordDialog(MySqlWorkbenchConnection wbConnection, bool testConnection) { PasswordDialogFlags flags; using (PasswordDialog connectionPasswordDialog = new PasswordDialog(wbConnection, testConnection, true)) { connectionPasswordDialog.ShowDialog(); flags = connectionPasswordDialog.PasswordFlags; } return(flags); }
/// <summary> /// Checks if a table with the given name has a primary key defined. /// </summary> /// <param name="connection">MySQL Workbench connection to a MySQL server instance selected by users.</param> /// <param name="tableName">Name of the table.</param> /// <returns><c>true</c> if the table has a primary key, <c>false</c> otherwise.</returns> public static bool TableHasPrimaryKey(this MySqlWorkbenchConnection connection, string tableName) { if (connection == null || string.IsNullOrEmpty(tableName)) { return(false); } string sql = string.Format("SHOW KEYS FROM `{0}` IN `{1}` WHERE Key_name = 'PRIMARY';", tableName, connection.Schema); DataTable dt = GetDataFromSelectQuery(connection, sql); return(dt != null && dt.Rows.Count > 0); }
/// <summary> /// Sets the current active connection used to query the database. /// </summary> /// <param name="connection">A <see cref="MySqlWorkbenchConnection"/> object representing the current connection to a MySQL server.</param> /// <param name="schema"></param> /// <returns><c>true</c> if schemas were loaded into the schemas list, <c>false</c> otherwise.</returns> public bool SetConnection(MySqlWorkbenchConnection connection, string schema) { _wbConnection = connection; _wbConnection.Schema = schema; ConnectionNameLabel.Text = _wbConnection.Name; UserIPLabel.Text = string.Format("User: {0}, IP: {1}", _wbConnection.UserName, _wbConnection.Host); SchemaLabel.Text = string.Format("Schema: {0}", _wbConnection.Schema); DBObjectsFilter.Width = DBObjectList.Width; bool schemasLoadedSuccessfully = RefreshDbObjectsList(true); RefreshActionLabelsEnabledStatus(null, false); return(schemasLoadedSuccessfully); }
/// <summary> /// Sets and opens the current active connection used to browse schemas and DB objects. /// </summary> /// <param name="connection">A <see cref="MySqlWorkbenchConnection"/> object representing the connection to a MySQL server instance selected by users.</param> /// <param name="givePanelFocus">Flag indicating whether the <see cref="SchemaSelectionPanel"/> is given focus.</param> public PasswordDialogFlags OpenConnection(MySqlWorkbenchConnection connection, bool givePanelFocus) { WbConnection = connection; var passwordFlags = WbConnection.TestConnectionAndRetryOnWrongPassword(); if (passwordFlags.ConnectionSuccess && SchemaSelectionPanel2.SetConnection(WbConnection) && givePanelFocus) { RefreshWbConnectionTimeouts(); SchemaSelectionPanel2.BringToFront(); } return(passwordFlags); }