Ejemplo n.º 1
0
		public static void DeriveParameters( MySqlCommand command ) {
			if( !command.Connection.driver.Version.isAtLeast( 5, 0, 0 ) ) {
				throw new MySqlException( "DeriveParameters is not supported on MySQL versions prior to 5.0" );
			}
			string commandText = command.CommandText;
			if( commandText.IndexOf( "." ) == -1 ) {
				commandText = command.Connection.Database + "." + commandText;
			}
			DataSet procedure = command.Connection.ProcedureCache.GetProcedure( command.Connection, commandText );
			DataTable table = procedure.Tables[ "Procedure Parameters" ];
			DataTable table2 = procedure.Tables[ "Procedures" ];
			command.Parameters.Clear();
			foreach( DataRow row in table.Rows ) {
				MySqlParameter parameter = new MySqlParameter();
				parameter.ParameterName = string.Format( "@{0}", row[ "PARAMETER_NAME" ] );
				parameter.Direction = GetDirection( row );
				bool unsigned = StoredProcedure.GetFlags( row[ "DTD_IDENTIFIER" ].ToString() ).IndexOf( "UNSIGNED" ) != -1;
				bool realAsFloat = table2.Rows[ 0 ][ "SQL_MODE" ].ToString().IndexOf( "REAL_AS_FLOAT" ) != -1;
				parameter.MySqlDbType = MetaData.NameToType( row[ "DATA_TYPE" ].ToString(), unsigned, realAsFloat, command.Connection );
				if( !row[ "CHARACTER_MAXIMUM_LENGTH" ].Equals( DBNull.Value ) ) {
					parameter.Size = (int)row[ "CHARACTER_MAXIMUM_LENGTH" ];
				}
				if( !row[ "NUMERIC_PRECISION" ].Equals( DBNull.Value ) ) {
					parameter.Precision = (byte)row[ "NUMERIC_PRECISION" ];
				}
				if( !row[ "NUMERIC_SCALE" ].Equals( DBNull.Value ) ) {
					parameter.Scale = (byte)( (int)row[ "NUMERIC_SCALE" ] );
				}
				command.Parameters.Add( parameter );
			}
		}
Ejemplo n.º 2
0
 public override void Close()
 {
     base.Close();
     if (this.outSelect.Length != 0)
     {
         MySqlCommand command = new MySqlCommand("SELECT " + this.outSelect, base.Connection);
         string parameterHash = base.command.parameterHash;
         command.parameterHash = parameterHash;
         using (MySqlDataReader reader = command.ExecuteReader())
         {
             for (int i = 0; i < reader.FieldCount; i++)
             {
                 string parameterName = reader.GetName(i).Remove(0, parameterHash.Length + 1);
                 MySqlParameter parameterFlexible = base.Parameters.GetParameterFlexible(parameterName, true);
                 reader.values[i] = MySqlField.GetIMySqlValue(parameterFlexible.MySqlDbType);
             }
             if (reader.Read())
             {
                 for (int j = 0; j < reader.FieldCount; j++)
                 {
                     string str3 = reader.GetName(j).Remove(0, parameterHash.Length + 1);
                     base.Parameters.GetParameterFlexible(str3, true).Value = reader.GetValue(j);
                 }
             }
         }
     }
 }
Ejemplo n.º 3
0
 internal static void InitCollections(MySqlConnection connection)
 {
     MySqlCommand command = new MySqlCommand("SHOW CHARSET", connection);
     using (MySqlDataReader reader = command.ExecuteReader())
     {
         while (reader.Read())
         {
             defaultCollations.Add(reader.GetString(0), reader.GetString(2));
             maxLengths.Add(reader.GetString(0), Convert.ToInt32(reader.GetValue(3)));
         }
     }
 }
Ejemplo n.º 4
0
 internal MySqlDataReader(MySqlCommand cmd, PreparableStatement statement, CommandBehavior behavior)
 {
     this.command = cmd;
     this.connection = this.command.Connection;
     this.commandBehavior = behavior;
     this.driver = this.connection.driver;
     this.affectedRows = -1L;
     this.statement = statement;
     this.nextResultDone = false;
     this.fieldHashCS = new Hashtable();
     this.fieldHashCI = new Hashtable(StringComparer.InvariantCultureIgnoreCase);
 }
Ejemplo n.º 5
0
 public static int ExecuteNonQuery(MySqlConnection connection, string commandText, params MySqlParameter[] commandParameters)
 {
     MySqlCommand command = new MySqlCommand();
     command.Connection = connection;
     command.CommandText = commandText;
     command.CommandType = CommandType.Text;
     if (commandParameters != null)
     {
         foreach (MySqlParameter parameter in commandParameters)
         {
             command.Parameters.Add(parameter);
         }
     }
     int num = command.ExecuteNonQuery();
     command.Parameters.Clear();
     return num;
 }
Ejemplo n.º 6
0
 public static DataSet ExecuteDataset(MySqlConnection connection, string commandText, params MySqlParameter[] commandParameters)
 {
     MySqlCommand selectCommand = new MySqlCommand();
     selectCommand.Connection = connection;
     selectCommand.CommandText = commandText;
     selectCommand.CommandType = CommandType.Text;
     if (commandParameters != null)
     {
         foreach (MySqlParameter parameter in commandParameters)
         {
             selectCommand.Parameters.Add(parameter);
         }
     }
     MySqlDataAdapter adapter = new MySqlDataAdapter(selectCommand);
     DataSet dataSet = new DataSet();
     adapter.Fill(dataSet);
     selectCommand.Parameters.Clear();
     return dataSet;
 }
Ejemplo n.º 7
0
 private void FindTables(DataTable schemaTable, string[] restrictions)
 {
     StringBuilder builder = new StringBuilder();
     StringBuilder builder2 = new StringBuilder();
     builder.AppendFormat(CultureInfo.InvariantCulture, "SHOW TABLE STATUS FROM `{0}`", new object[] { restrictions[1] });
     if (((restrictions != null) && (restrictions.Length >= 3)) && (restrictions[2] != null))
     {
         builder2.AppendFormat(CultureInfo.InvariantCulture, " LIKE '{0}'", new object[] { restrictions[2] });
     }
     builder.Append(builder2.ToString());
     string str = (restrictions[1].ToLower() == "information_schema") ? "SYSTEM VIEW" : "BASE TABLE";
     MySqlCommand command = new MySqlCommand(builder.ToString(), this.connection);
     using (MySqlDataReader reader = command.ExecuteReader())
     {
         while (reader.Read())
         {
             DataRow row = schemaTable.NewRow();
             row["TABLE_CATALOG"] = null;
             row["TABLE_SCHEMA"] = restrictions[1];
             row["TABLE_NAME"] = reader.GetString(0);
             row["TABLE_TYPE"] = str;
             row["ENGINE"] = GetString(reader, 1);
             row["VERSION"] = reader.GetValue(2);
             row["ROW_FORMAT"] = GetString(reader, 3);
             row["TABLE_ROWS"] = reader.GetValue(4);
             row["AVG_ROW_LENGTH"] = reader.GetValue(5);
             row["DATA_LENGTH"] = reader.GetValue(6);
             row["MAX_DATA_LENGTH"] = reader.GetValue(7);
             row["INDEX_LENGTH"] = reader.GetValue(8);
             row["DATA_FREE"] = reader.GetValue(9);
             row["AUTO_INCREMENT"] = reader.GetValue(10);
             row["CREATE_TIME"] = reader.GetValue(11);
             row["UPDATE_TIME"] = reader.GetValue(12);
             row["CHECK_TIME"] = reader.GetValue(13);
             row["TABLE_COLLATION"] = GetString(reader, 14);
             row["CHECKSUM"] = reader.GetValue(15);
             row["CREATE_OPTIONS"] = GetString(reader, 0x10);
             row["TABLE_COMMENT"] = GetString(reader, 0x11);
             schemaTable.Rows.Add(row);
         }
     }
 }
Ejemplo n.º 8
0
		new public MySqlTransaction BeginTransaction( System.Data.IsolationLevel iso ) {
			if( this.State != ConnectionState.Open ) {
				throw new InvalidOperationException( Resources.ConnectionNotOpen );
			}
			if( ( this.driver.ServerStatus & ServerStatusFlags.InTransaction ) != 0 ) {
				throw new InvalidOperationException( Resources.NoNestedTransactions );
			}
			MySqlTransaction transaction = new MySqlTransaction( this, iso );
			MySqlCommand command = new MySqlCommand( "", this );
			command.CommandText = "SET SESSION TRANSACTION ISOLATION LEVEL ";
			switch( iso ) {
				case System.Data.IsolationLevel.Chaos:
					throw new NotSupportedException( Resources.ChaosNotSupported );

				case System.Data.IsolationLevel.ReadUncommitted:
					command.CommandText = command.CommandText + "READ UNCOMMITTED";
					goto Label_00F1;

				case System.Data.IsolationLevel.ReadCommitted:
					command.CommandText = command.CommandText + "READ COMMITTED";
					break;

				case System.Data.IsolationLevel.RepeatableRead:
					command.CommandText = command.CommandText + "REPEATABLE READ";
					break;

				case System.Data.IsolationLevel.Serializable:
					command.CommandText = command.CommandText + "SERIALIZABLE";
					break;
			}
Label_00F1:
			command.ExecuteNonQuery();
			command.CommandText = "BEGIN";
			command.ExecuteNonQuery();
			return transaction;
		}
Ejemplo n.º 9
0
 public override void Close()
 {
     if (this.isOpen)
     {
         bool flag = (this.commandBehavior & CommandBehavior.CloseConnection) != CommandBehavior.Default;
         this.commandBehavior = CommandBehavior.Default;
         this.connection.Reader = null;
         if (!this.nextResultDone)
         {
             while (this.NextResult())
             {
             }
         }
         this.command.Close();
         if (flag)
         {
             this.connection.Close();
         }
         this.command = null;
         this.connection = null;
         this.isOpen = false;
     }
 }
Ejemplo n.º 10
0
 public virtual DataTable GetIndexColumns(string[] restrictions)
 {
     DataTable table = new DataTable("IndexColumns");
     table.Columns.Add("INDEX_CATALOG", typeof(string));
     table.Columns.Add("INDEX_SCHEMA", typeof(string));
     table.Columns.Add("INDEX_NAME", typeof(string));
     table.Columns.Add("TABLE_NAME", typeof(string));
     table.Columns.Add("COLUMN_NAME", typeof(string));
     table.Columns.Add("ORDINAL_POSITION", typeof(int));
     string[] array = new string[Math.Max(restrictions.Length, 4)];
     restrictions.CopyTo(array, 0);
     array[3] = "BASE TABLE";
     foreach (DataRow row in this.GetTables(array).Rows)
     {
         MySqlCommand command = new MySqlCommand(string.Format("SHOW INDEX FROM `{0}`.`{1}`", row["TABLE_SCHEMA"], row["TABLE_NAME"]), this.connection);
         using (MySqlDataReader reader = command.ExecuteReader())
         {
             while (reader.Read())
             {
                 string str2 = GetString(reader, reader.GetOrdinal("KEY_NAME"));
                 string str3 = GetString(reader, reader.GetOrdinal("COLUMN_NAME"));
                 if ((restrictions == null) || ((((restrictions.Length != 4) || (restrictions[3] == null)) || (str2 == restrictions[3])) && (((restrictions.Length != 5) || (restrictions[4] == null)) || (str3 == restrictions[4]))))
                 {
                     DataRow row2 = table.NewRow();
                     row2["INDEX_CATALOG"] = null;
                     row2["INDEX_SCHEMA"] = row["TABLE_SCHEMA"];
                     row2["INDEX_NAME"] = str2;
                     row2["TABLE_NAME"] = GetString(reader, reader.GetOrdinal("TABLE"));
                     row2["COLUMN_NAME"] = str3;
                     row2["ORDINAL_POSITION"] = reader.GetValue(reader.GetOrdinal("SEQ_IN_INDEX"));
                     table.Rows.Add(row2);
                 }
             }
             continue;
         }
     }
     return table;
 }
Ejemplo n.º 11
0
 private string GetSqlMode()
 {
     MySqlCommand command = new MySqlCommand("SELECT @@SQL_MODE", this.connection);
     return command.ExecuteScalar().ToString();
 }
Ejemplo n.º 12
0
 private void LoadTableColumns(DataTable dt, string schema, string tableName, string columnRestriction)
 {
     MySqlCommand command = new MySqlCommand(string.Format("SHOW FULL COLUMNS FROM `{0}`.`{1}`", schema, tableName), this.connection);
     int num = 1;
     using (MySqlDataReader reader = command.ExecuteReader())
     {
         while (reader.Read())
         {
             string str2 = reader.GetString(0);
             if ((columnRestriction == null) || (str2 == columnRestriction))
             {
                 DataRow row = dt.NewRow();
                 row["TABLE_CATALOG"] = DBNull.Value;
                 row["TABLE_SCHEMA"] = schema;
                 row["TABLE_NAME"] = tableName;
                 row["COLUMN_NAME"] = str2;
                 row["ORDINAL_POSITION"] = num++;
                 row["COLUMN_DEFAULT"] = reader.GetValue(5);
                 row["IS_NULLABLE"] = reader.GetString(3);
                 row["DATA_TYPE"] = reader.GetString(1);
                 row["CHARACTER_MAXIMUM_LENGTH"] = DBNull.Value;
                 row["NUMERIC_PRECISION"] = DBNull.Value;
                 row["NUMERIC_SCALE"] = DBNull.Value;
                 row["CHARACTER_SET_NAME"] = reader.GetValue(2);
                 row["COLLATION_NAME"] = row["CHARACTER_SET_NAME"];
                 row["COLUMN_TYPE"] = reader.GetString(1);
                 row["COLUMN_KEY"] = reader.GetString(4);
                 row["EXTRA"] = reader.GetString(6);
                 row["PRIVILEGES"] = reader.GetString(7);
                 row["COLUMN_COMMENT"] = reader.GetString(8);
                 ParseColumnRow(row);
                 dt.Rows.Add(row);
             }
         }
     }
 }
Ejemplo n.º 13
0
 private string GetProcedureParameterLine(DataRow isRow)
 {
     string format = "SHOW CREATE {0} `{1}`.`{2}`";
     MySqlCommand command = new MySqlCommand(string.Format(format, isRow["ROUTINE_TYPE"], isRow["ROUTINE_SCHEMA"], isRow["ROUTINE_NAME"]), base.connection);
     using (MySqlDataReader reader = command.ExecuteReader())
     {
         string str4;
         reader.Read();
         if (reader.IsDBNull(2))
         {
             return null;
         }
         string str2 = reader.GetString(1);
         string input = reader.GetString(2);
         SqlTokenizer tokenizer = new SqlTokenizer(input);
         tokenizer.AnsiQuotes = str2.IndexOf("ANSI_QUOTES") != -1;
         tokenizer.BackslashEscapes = str2.IndexOf("NO_BACKSLASH_ESCAPES") == -1;
         for (str4 = tokenizer.NextToken(); str4 != "("; str4 = tokenizer.NextToken())
         {
         }
         int startIndex = tokenizer.Index + 1;
         str4 = tokenizer.NextToken();
         while ((str4 != ")") || tokenizer.Quoted)
         {
             str4 = tokenizer.NextToken();
             if ((str4 == "(") && !tokenizer.Quoted)
             {
                 while ((str4 != ")") || tokenizer.Quoted)
                 {
                     str4 = tokenizer.NextToken();
                 }
                 str4 = tokenizer.NextToken();
             }
         }
         return input.Substring(startIndex, tokenizer.Index - startIndex);
     }
 }
Ejemplo n.º 14
0
		internal string CurrentDatabase() {
			if( ( this.Database != null ) && ( this.Database.Length > 0 ) ) {
				return this.Database;
			}
			MySqlCommand command = new MySqlCommand( "SELECT database()", this );
			return command.ExecuteScalar().ToString();
		}
Ejemplo n.º 15
0
		object ICloneable.Clone() {
			MySqlCommand command = new MySqlCommand( this.cmdText, this.connection, this.curTransaction );
			command.CommandType = this.CommandType;
			command.CommandTimeout = this.CommandTimeout;
			command.batchableCommandText = this.batchableCommandText;
			foreach( MySqlParameter parameter in this.parameters ) {
				command.Parameters.Add( ( (ICloneable)parameter ).Clone() );
			}
			return command;
		}
Ejemplo n.º 16
0
 public StoredProcedure(MySqlCommand cmd, string text) : base(cmd, text)
 {
     cmd.parameterHash = ((uint) DateTime.Now.GetHashCode()).ToString();
 }
Ejemplo n.º 17
0
 public virtual DataTable GetProcedures(string[] restrictions)
 {
     DataTable table = new DataTable("Procedures");
     table.Columns.Add(new DataColumn("SPECIFIC_NAME", typeof(string)));
     table.Columns.Add(new DataColumn("ROUTINE_CATALOG", typeof(string)));
     table.Columns.Add(new DataColumn("ROUTINE_SCHEMA", typeof(string)));
     table.Columns.Add(new DataColumn("ROUTINE_NAME", typeof(string)));
     table.Columns.Add(new DataColumn("ROUTINE_TYPE", typeof(string)));
     table.Columns.Add(new DataColumn("DTD_IDENTIFIER", typeof(string)));
     table.Columns.Add(new DataColumn("ROUTINE_BODY", typeof(string)));
     table.Columns.Add(new DataColumn("ROUTINE_DEFINITION", typeof(string)));
     table.Columns.Add(new DataColumn("EXTERNAL_NAME", typeof(string)));
     table.Columns.Add(new DataColumn("EXTERNAL_LANGUAGE", typeof(string)));
     table.Columns.Add(new DataColumn("PARAMETER_STYLE", typeof(string)));
     table.Columns.Add(new DataColumn("IS_DETERMINISTIC", typeof(string)));
     table.Columns.Add(new DataColumn("SQL_DATA_ACCESS", typeof(string)));
     table.Columns.Add(new DataColumn("SQL_PATH", typeof(string)));
     table.Columns.Add(new DataColumn("SECURITY_TYPE", typeof(string)));
     table.Columns.Add(new DataColumn("CREATED", typeof(DateTime)));
     table.Columns.Add(new DataColumn("LAST_ALTERED", typeof(DateTime)));
     table.Columns.Add(new DataColumn("SQL_MODE", typeof(string)));
     table.Columns.Add(new DataColumn("ROUTINE_COMMENT", typeof(string)));
     table.Columns.Add(new DataColumn("DEFINER", typeof(string)));
     StringBuilder builder = new StringBuilder("SELECT * FROM mysql.proc WHERE 1=1");
     if (restrictions != null)
     {
         if ((restrictions.Length >= 2) && (restrictions[1] != null))
         {
             builder.AppendFormat(CultureInfo.InvariantCulture, " AND db LIKE '{0}'", new object[] { restrictions[1] });
         }
         if ((restrictions.Length >= 3) && (restrictions[2] != null))
         {
             builder.AppendFormat(CultureInfo.InvariantCulture, " AND name LIKE '{0}'", new object[] { restrictions[2] });
         }
         if ((restrictions.Length >= 4) && (restrictions[3] != null))
         {
             builder.AppendFormat(CultureInfo.InvariantCulture, " AND type LIKE '{0}'", new object[] { restrictions[3] });
         }
     }
     MySqlCommand command = new MySqlCommand(builder.ToString(), this.connection);
     using (MySqlDataReader reader = command.ExecuteReader())
     {
         while (reader.Read())
         {
             DataRow row = table.NewRow();
             row["SPECIFIC_NAME"] = reader.GetString("specific_name");
             row["ROUTINE_CATALOG"] = DBNull.Value;
             row["ROUTINE_SCHEMA"] = reader.GetString("db");
             row["ROUTINE_NAME"] = reader.GetString("name");
             string str = reader.GetString("type");
             row["ROUTINE_TYPE"] = str;
             row["DTD_IDENTIFIER"] = (str.ToLower(CultureInfo.InvariantCulture) == "function") ? ((object) reader.GetString("returns")) : ((object) DBNull.Value);
             row["ROUTINE_BODY"] = "SQL";
             row["ROUTINE_DEFINITION"] = reader.GetString("body");
             row["EXTERNAL_NAME"] = DBNull.Value;
             row["EXTERNAL_LANGUAGE"] = DBNull.Value;
             row["PARAMETER_STYLE"] = "SQL";
             row["IS_DETERMINISTIC"] = reader.GetString("is_deterministic");
             row["SQL_DATA_ACCESS"] = reader.GetString("sql_data_access");
             row["SQL_PATH"] = DBNull.Value;
             row["SECURITY_TYPE"] = reader.GetString("security_type");
             row["CREATED"] = reader.GetDateTime("created");
             row["LAST_ALTERED"] = reader.GetDateTime("modified");
             row["SQL_MODE"] = reader.GetString("sql_mode");
             row["ROUTINE_COMMENT"] = reader.GetString("comment");
             row["DEFINER"] = reader.GetString("definer");
             table.Rows.Add(row);
         }
     }
     return table;
 }
Ejemplo n.º 18
0
		/// <summary>
		/// Executes a simple Query and Reads the first <see cref="Int32"/> Value!
		/// </summary>
		/// <param name="Query"></param>
		/// <returns>the first <see cref="Int32"/> Value ( Value > 0 )</returns>
		public bool QueryBool( string Query ) {
			bool result = false;
			mLastError = null;
			if( Query.Length == 0 )
				return result;
			
			try {
				Open();
				mCommand = mConnection.CreateCommand();
				mCommand.CommandText = Query;

				mReader = mCommand.ExecuteReader();
				while( mReader.Read() ) {
					result = ( mReader.GetInt32( 0 ) > 0 );
				}
				mReader.Close();
			} catch( Exception ex ) {
				System.Diagnostics.Debug.WriteLine( ex );
				mLastError = ex;
				return false;
			}

			return result;
		}
Ejemplo n.º 19
0
 private Statement(MySqlCommand cmd)
 {
     this.command = cmd;
     this.buffers = new ArrayList();
 }
Ejemplo n.º 20
0
		/// <summary>
		/// Executes a simple Query and returns the Affected Rows
		/// </summary>
		/// <param name="Query"></param>
		/// <returns></returns>
		public int QuerySimple( string Query ) {
			int result = 0;
			mLastError = null;
			if( Query.Length == 0 )
				return result;

			try {
				Open();
				mCommand = mConnection.CreateCommand();
				mCommand.CommandText = Query;

				result = mCommand.ExecuteNonQuery();
			} catch( Exception ex ) {
				System.Diagnostics.Debug.WriteLine( ex );
				mLastError = ex;
				return 0;
			}

			return result;
		}
Ejemplo n.º 21
0
		public MySqlDataAdapter( MySqlCommand selectCommand )
			: this() {
			this.SelectCommand = selectCommand;
		}
Ejemplo n.º 22
0
		internal void AddToBatch( MySqlCommand command ) {
			if( this.batch == null ) {
				this.batch = new List<MySqlCommand>();
			}
			this.batch.Add( command );
		}
Ejemplo n.º 23
0
 public int Execute()
 {
     int num2;
     bool flag = false;
     if (this.connection == null)
     {
         throw new InvalidOperationException(Resources.ConnectionNotSet);
     }
     if ((this.query == null) || (this.query.Length == 0))
     {
         return 0;
     }
     if (this.connection.State != ConnectionState.Open)
     {
         flag = true;
         this.connection.Open();
     }
     bool allowUserVariables = this.connection.Settings.AllowUserVariables;
     this.connection.Settings.AllowUserVariables = true;
     try
     {
         string str = this.connection.driver.Property("sql_mode").ToLower(CultureInfo.InvariantCulture);
         bool ansiQuotes = str.IndexOf("ansi_quotes") != -1;
         bool noBackslashEscapes = str.IndexOf("no_backslash_escpaes") != -1;
         List<ScriptStatement> list = this.BreakIntoStatements(ansiQuotes, noBackslashEscapes);
         int num = 0;
         MySqlCommand command = new MySqlCommand(null, this.connection);
         foreach (ScriptStatement statement in list)
         {
             command.CommandText = statement.text;
             try
             {
                 command.ExecuteNonQuery();
                 num++;
                 this.OnQueryExecuted(statement);
                 continue;
             }
             catch (Exception exception)
             {
                 if (this.Error == null)
                 {
                     throw;
                 }
                 if (this.OnScriptError(exception))
                 {
                     continue;
                 }
                 break;
             }
         }
         this.OnScriptCompleted();
         num2 = num;
     }
     finally
     {
         this.connection.Settings.AllowUserVariables = allowUserVariables;
         if (flag)
         {
             this.connection.Close();
         }
     }
     return num2;
 }
Ejemplo n.º 24
0
 public static object ExecuteScalar(MySqlConnection connection, string commandText, params MySqlParameter[] commandParameters)
 {
     MySqlCommand command = new MySqlCommand();
     command.Connection = connection;
     command.CommandText = commandText;
     command.CommandType = CommandType.Text;
     if (commandParameters != null)
     {
         foreach (MySqlParameter parameter in commandParameters)
         {
             command.Parameters.Add(parameter);
         }
     }
     object obj2 = command.ExecuteScalar();
     command.Parameters.Clear();
     return obj2;
 }
Ejemplo n.º 25
0
		new public MySqlCommand CreateCommand() {
			MySqlCommand command = new MySqlCommand();
			command.Connection = this;
			return command;
		}
Ejemplo n.º 26
0
 public PreparableStatement(MySqlCommand command, string text) : base(command, text)
 {
 }
Ejemplo n.º 27
0
 private void GetForeignKeysOnTable(DataTable fkTable, DataRow tableToParse, string filterName, bool includeColumns)
 {
     string sqlMode = this.GetSqlMode();
     if (filterName != null)
     {
         filterName = filterName.ToLower(CultureInfo.InvariantCulture);
     }
     string cmdText = string.Format("SHOW CREATE TABLE `{0}`.`{1}`", tableToParse["TABLE_SCHEMA"], tableToParse["TABLE_NAME"]);
     string input = null;
     MySqlCommand command = new MySqlCommand(cmdText, this.connection);
     using (MySqlDataReader reader = command.ExecuteReader())
     {
         reader.Read();
         input = reader.GetString(1).ToLower(CultureInfo.InvariantCulture);
     }
     SqlTokenizer tokenizer = new SqlTokenizer(input);
     tokenizer.AnsiQuotes = sqlMode.IndexOf("ANSI_QUOTES") != -1;
     tokenizer.BackslashEscapes = sqlMode.IndexOf("NO_BACKSLASH_ESCAPES") != -1;
     while (true)
     {
         string str5 = tokenizer.NextToken();
         while ((str5 != null) && ((str5 != "constraint") || tokenizer.Quoted))
         {
             str5 = tokenizer.NextToken();
         }
         if (str5 == null)
         {
             return;
         }
         this.ParseConstraint(fkTable, tableToParse, tokenizer, includeColumns);
     }
 }
Ejemplo n.º 28
0
		internal string GetCommandTextForBatching() {
			if( this.batchableCommandText == null ) {
				if( string.Compare( this.CommandText.Substring( 0, 6 ), "INSERT", true ) == 0 ) {
					MySqlCommand command = new MySqlCommand( "SELECT @@sql_mode", this.Connection );
					string str = command.ExecuteScalar().ToString().ToLower( CultureInfo.InvariantCulture );
					SqlTokenizer tokenizer = new SqlTokenizer( this.CommandText );
					tokenizer.AnsiQuotes = str.IndexOf( "ansi_quotes" ) != -1;
					tokenizer.BackslashEscapes = str.IndexOf( "no_backslash_escapes" ) == -1;
					for( string str2 = tokenizer.NextToken().ToLower( CultureInfo.InvariantCulture ); str2 != null; str2 = tokenizer.NextToken() ) {
						if( ( str2.ToLower( CultureInfo.InvariantCulture ) == "values" ) && !tokenizer.Quoted ) {
							str2 = tokenizer.NextToken();
							while( ( str2 != null ) && ( str2 != ")" ) ) {
								this.batchableCommandText = this.batchableCommandText + str2;
								str2 = tokenizer.NextToken();
							}
							if( str2 != null ) {
								this.batchableCommandText = this.batchableCommandText + str2;
							}
							str2 = tokenizer.NextToken();
							if( ( str2 != null ) && ( ( str2 == "," ) || ( str2.ToLower( CultureInfo.InvariantCulture ) == "on" ) ) ) {
								this.batchableCommandText = null;
								break;
							}
						}
					}
				}
				if( this.batchableCommandText == null ) {
					this.batchableCommandText = this.CommandText;
				}
			}
			return this.batchableCommandText;
		}
Ejemplo n.º 29
0
 public Statement(MySqlCommand cmd, string text) : this(cmd)
 {
     this.commandText = text;
 }
Ejemplo n.º 30
0
 private static MySqlDataReader ExecuteReader(MySqlConnection connection, MySqlTransaction transaction, string commandText, MySqlParameter[] commandParameters, bool ExternalConn)
 {
     MySqlDataReader reader;
     MySqlCommand command = new MySqlCommand();
     command.Connection = connection;
     command.Transaction = transaction;
     command.CommandText = commandText;
     command.CommandType = CommandType.Text;
     if (commandParameters != null)
     {
         foreach (MySqlParameter parameter in commandParameters)
         {
             command.Parameters.Add(parameter);
         }
     }
     if (ExternalConn)
     {
         reader = command.ExecuteReader();
     }
     else
     {
         reader = command.ExecuteReader(CommandBehavior.CloseConnection);
     }
     command.Parameters.Clear();
     return reader;
 }