Пример #1
0
		new public MySqlDataReader ExecuteReader( CommandBehavior behavior ) {
			MySqlDataReader reader2;
			this.lastInsertedId = -1L;
			this.CheckState();
			if( ( this.cmdText == null ) || ( this.cmdText.Trim().Length == 0 ) ) {
				throw new InvalidOperationException( Resources.CommandTextNotInitialized );
			}
			string text = TrimSemicolons( this.cmdText );
			this.connection.IsExecutingBuggyQuery = false;
			if( !this.connection.driver.Version.isAtLeast( 5, 0, 0 ) && this.connection.driver.Version.isAtLeast( 4, 1, 0 ) ) {
				string str2 = text;
				if( str2.Length > 0x11 ) {
					str2 = text.Substring( 0, 0x11 );
				}
				str2 = str2.ToLower( CultureInfo.InvariantCulture );
				this.connection.IsExecutingBuggyQuery = str2.StartsWith( "describe" ) || str2.StartsWith( "show table status" );
			}
			if( ( this.statement == null ) || !this.statement.IsPrepared ) {
				if( this.CommandType == System.Data.CommandType.StoredProcedure ) {
					this.statement = new StoredProcedure( this, text );
				} else {
					this.statement = new PreparableStatement( this, text );
				}
			}
			this.statement.Resolve();
			this.HandleCommandBehaviors( behavior );
			this.updatedRowCount = -1L;
			System.Threading.Timer timer = null;
			try {
				MySqlDataReader reader = new MySqlDataReader( this, this.statement, behavior );
				this.timedOut = false;
				this.statement.Execute();
				if( this.connection.driver.Version.isAtLeast( 5, 0, 0 ) && ( this.commandTimeout > 0 ) ) {
					System.Threading.TimerCallback callback = new System.Threading.TimerCallback( this.TimeoutExpired );
					timer = new System.Threading.Timer( callback, this, this.CommandTimeout * 0x3e8, -1 );
				}
				reader.NextResult();
				this.connection.Reader = reader;
				reader2 = reader;
			} catch( MySqlException exception ) {
				if( exception.Number == 0x525 ) {
					if( this.TimedOut ) {
						throw new MySqlException( Resources.Timeout );
					}
					return null;
				}
				if( exception.IsFatal ) {
					this.Connection.Close();
				}
				if( exception.Number == 0 ) {
					throw new MySqlException( Resources.FatalErrorDuringExecute, exception );
				}
				throw;
			} finally {
				if( timer != null ) {
					timer.Dispose();
				}
			}
			return reader2;
		}
Пример #2
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;
		}
Пример #3
0
 private static string GetString(MySqlDataReader reader, int index)
 {
     if (reader.IsDBNull(index))
     {
         return null;
     }
     return reader.GetString(index);
 }