/// <summary> /// Raw SQL Select Implementation with Parameters for Prepared Query /// </summary> /// <param name="SQLCommand">Command for reading</param> /// <param name="parameters">Collection of Parameters for Single/Multiple Read</param> /// <param name="Reader">Reader Method</param> /// <param name="Isolation">Transaction Isolation</param> protected override void ExecuteSelectImpl(string SQLCommand, IEnumerable <IEnumerable <QueryParameter> > parameters, Action <IDataReader> Reader, IsolationLevel Isolation) { if (log.IsDebugEnabled) { log.DebugFormat("ExecuteSelectImpl: {0}", SQLCommand); } var repeat = false; var current = 0; do { repeat = false; using (var conn = new SQLiteConnection(ConnectionString)) { using (var cmd = new SQLiteCommand(SQLCommand, conn)) { try { conn.Open(); cmd.Prepare(); long start = (DateTime.UtcNow.Ticks / 10000); // Register Parameter foreach (var keys in parameters.First().Select(kv => kv.Name)) { cmd.Parameters.Add(new SQLiteParameter(keys)); } foreach (var parameter in parameters.Skip(current)) { FillSQLParameter(parameter, cmd.Parameters); using (var reader = cmd.ExecuteReader()) { try { Reader(reader); } catch (Exception es) { if (log.IsWarnEnabled) { log.WarnFormat("ExecuteSelectImpl: Exception in Select Callback : {2}{0}{2}{1}", es, Environment.StackTrace, Environment.NewLine); } } finally { reader.Close(); } } current++; } if (log.IsDebugEnabled) { log.DebugFormat("ExecuteSelectImpl: SQL Select ({0}) exec time {1}ms", Isolation, ((DateTime.UtcNow.Ticks / 10000) - start)); } else if (log.IsWarnEnabled && (DateTime.UtcNow.Ticks / 10000) - start > 500) { log.WarnFormat("ExecuteSelectImpl: SQL Select ({0}) took {1}ms!\n{2}", Isolation, ((DateTime.UtcNow.Ticks / 10000) - start), SQLCommand); } } catch (Exception e) { if (!HandleException(e)) { if (log.IsErrorEnabled) { log.ErrorFormat("ExecuteSelectImpl: UnHandled Exception for Select Query \"{0}\"\n{1}", SQLCommand, e); } throw; } repeat = true; } finally { conn.Close(); } } } }while (repeat); }
/// <summary> /// Raw SQL Select Implementation with Parameters for Prepared Query /// </summary> /// <param name="SQLCommand">Command for reading</param> /// <param name="parameters">Collection of Parameters for Single/Multiple Read</param> /// <param name="Reader">Reader Method</param> /// <param name="Isolation">Transaction Isolation</param> protected override void ExecuteSelectImpl(string SQLCommand, IEnumerable<IEnumerable<QueryParameter>> parameters, Action<IDataReader> Reader, IsolationLevel Isolation) { if (log.IsDebugEnabled) log.DebugFormat("ExecuteSelectImpl: {0}", SQLCommand); var repeat = false; var current = 0; do { repeat = false; using (var conn = new SQLiteConnection(ConnectionString)) { using (var cmd = new SQLiteCommand(SQLCommand, conn)) { try { conn.Open(); cmd.Prepare(); long start = (DateTime.UtcNow.Ticks / 10000); // Register Parameter foreach(var keys in parameters.First().Select(kv => kv.Name)) cmd.Parameters.Add(new SQLiteParameter(keys)); foreach(var parameter in parameters.Skip(current)) { FillSQLParameter(parameter, cmd.Parameters); using (var reader = cmd.ExecuteReader()) { try { Reader(reader); } catch (Exception es) { if(log.IsWarnEnabled) log.WarnFormat("ExecuteSelectImpl: Exception in Select Callback : {2}{0}{2}{1}", es, Environment.StackTrace, Environment.NewLine); } finally { reader.Close(); } } current++; } if (log.IsDebugEnabled) log.DebugFormat("ExecuteSelectImpl: SQL Select ({0}) exec time {1}ms", Isolation, ((DateTime.UtcNow.Ticks / 10000) - start)); else if (log.IsWarnEnabled && (DateTime.UtcNow.Ticks / 10000) - start > 500) log.WarnFormat("ExecuteSelectImpl: SQL Select ({0}) took {1}ms!\n{2}", Isolation, ((DateTime.UtcNow.Ticks / 10000) - start), SQLCommand); } catch (Exception e) { if (!HandleException(e)) { if (log.IsErrorEnabled) log.ErrorFormat("ExecuteSelectImpl: UnHandled Exception for Select Query \"{0}\"\n{1}", SQLCommand, e); throw; } repeat = true; } finally { conn.Close(); } } } } while (repeat); }