public MySqlEventList(MySqlCommand cmd) { try { string dbname = QueryExpress.ExecuteScalarStr(cmd, "SELECT DATABASE();"); _sqlShowEvents = string.Format("SHOW EVENTS WHERE UPPER(TRIM(Db))=UPPER(TRIM('{0}'));", dbname); DataTable dt = QueryExpress.GetTable(cmd, _sqlShowEvents); foreach (DataRow dr in dt.Rows) { var eventName = dr["Name"].ToString(); _lst.Add(eventName, new MySqlEvent(cmd, eventName, dr["Definer"].ToString())); } } catch (MySqlException myEx) { if (myEx.Message.ToLower().Contains("access denied")) { _allowAccess = false; } } catch { throw; } }
public MySqlTable(MySqlCommand cmd, string name) { _name = name; string sql = string.Format("SHOW CREATE TABLE `{0}`;", name); _createTableSql = QueryExpress.ExecuteScalarStr(cmd, sql, 1).Replace(Environment.NewLine, "^~~~~~~^").Replace("\r", "^~~~~~~^").Replace("\n", "^~~~~~~^").Replace("^~~~~~~^", Environment.NewLine).Replace("CREATE TABLE ", "CREATE TABLE IF NOT EXISTS ") + ";"; _createTableSqlWithoutAutoIncrement = RemoveAutoIncrement(_createTableSql); _lst = new MySqlColumnList(cmd, name); GetInsertStatementHeaders(); }
public void GetServerInfo(MySqlCommand cmd) { _edition = QueryExpress.ExecuteScalarStr(cmd, "SHOW variables LIKE 'version_comment';", 1); _versionNumber = QueryExpress.ExecuteScalarStr(cmd, "SHOW variables LIKE 'version';", 1); _characterSetServer = QueryExpress.ExecuteScalarStr(cmd, "SHOW variables LIKE 'character_set_server';", 1); _characterSetSystem = QueryExpress.ExecuteScalarStr(cmd, "SHOW variables LIKE 'character_set_system';", 1); _characterSetConnection = QueryExpress.ExecuteScalarStr(cmd, "SHOW variables LIKE 'character_set_connection';", 1); _characterSetDatabase = QueryExpress.ExecuteScalarStr(cmd, "SHOW variables LIKE 'character_set_database';", 1); _currentUserClientHost = QueryExpress.ExecuteScalarStr(cmd, "SELECT current_user;"); string[] ca = _currentUserClientHost.Split('@'); _currentUser = ca[0]; _currentClientHost = ca[1]; GetMajorVersionNumber(); }
public MySqlProcedure(MySqlCommand cmd, string procedureName, string definer) { _name = procedureName; string sql = string.Format("SHOW CREATE PROCEDURE `{0}`;", procedureName); _createProcedureSQL = QueryExpress.ExecuteScalarStr(cmd, sql, 2); _createProcedureSQL = _createProcedureSQL.Replace("\r\n", "^~~~~~~~~~~~~~~^"); _createProcedureSQL = _createProcedureSQL.Replace("\n", "^~~~~~~~~~~~~~~^"); _createProcedureSQL = _createProcedureSQL.Replace("\r", "^~~~~~~~~~~~~~~^"); _createProcedureSQL = _createProcedureSQL.Replace("^~~~~~~~~~~~~~~^", "\r\n"); string[] sa = definer.Split('@'); definer = string.Format(" DEFINER=`{0}`@`{1}`", sa[0], sa[1]); _createProcedureSQLWithoutDefiner = _createProcedureSQL.Replace(definer, string.Empty); }
public void GetDatabaseInfo(MySqlCommand cmd, GetTotalRowsMethod enumGetTotalRowsMode) { _name = QueryExpress.ExecuteScalarStr(cmd, "SELECT DATABASE();"); _defaultCharSet = QueryExpress.ExecuteScalarStr(cmd, "SHOW VARIABLES LIKE 'character_set_database';", 1); _createDatabaseSql = QueryExpress.ExecuteScalarStr(cmd, string.Format("SHOW CREATE DATABASE `{0}`;", _name), 1).Replace("CREATE DATABASE", "CREATE DATABASE IF NOT EXISTS") + ";"; _dropDatabaseSql = string.Format("DROP DATABASE IF EXISTS `{0}`;", _name); _listTable = new MySqlTableList(cmd); _listProcedure = new MySqlProcedureList(cmd); _listFunction = new MySqlFunctionList(cmd); _listTrigger = new MySqlTriggerList(cmd); _listEvent = new MySqlEventList(cmd); _listView = new MySqlViewList(cmd); if (enumGetTotalRowsMode != GetTotalRowsMethod.Skip) { GetTotalRows(cmd, enumGetTotalRowsMode); } }
/// <summary> /// Gets the list of document headers. /// </summary> /// <param name="cmd">The MySqlCommand that will be used to retrieve the database default character set.</param> /// <returns>List of document headers.</returns> public List <string> GetDocumentHeaders(MySqlCommand cmd) { if (_documentHeaders == null) { _documentHeaders = new List <string>(); string databaseCharSet = QueryExpress.ExecuteScalarStr(cmd, "SHOW variables LIKE 'character_set_database';", 1); _documentHeaders.Add("/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;"); _documentHeaders.Add("/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;"); _documentHeaders.Add("/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;"); _documentHeaders.Add(string.Format("/*!40101 SET NAMES {0} */;", databaseCharSet)); //_documentHeaders.Add("/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;"); //_documentHeaders.Add("/*!40103 SET TIME_ZONE='+00:00' */;"); _documentHeaders.Add("/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;"); _documentHeaders.Add("/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;"); _documentHeaders.Add("/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;"); _documentHeaders.Add("/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;"); } return(_documentHeaders); }