Beispiel #1
0
 public static void Read(this SQLiteConnection connection, string sql, Action <IReader> OnRead, CommandConfig config = null, params object[] parameters)
 {
     try
     {
         using (SQLiteConnection con = connection)
         {
             using (var cmd = connection.CreateCommand(sql, parameters))
             {
                 using (IReader reader = cmd.ExecuteReader())
                 {
                     if (config?.ManualRead ?? false)
                     {
                         OnRead.Invoke(reader);
                     }
                     else
                     {
                         while (reader.Read())
                         {
                             OnRead.Invoke(reader);
                         }
                     }
                 }
             }
             con.Close();
         }
     }
     catch (Exception ex)
     {
         Log.Logger.Error(ex, "Transaccion fallida reportada");
         Log.Logger.Error(sql);
     }
 }
Beispiel #2
0
 public static void Read(this SQLiteConnection connection, string sql, Action <IReader> OnRead, CommandConfig config = null, IEnumerable <object> parameters = null)
 {
     connection.Read(sql, OnRead, config, parameters?.ToArray());
 }
 public static void Read(this SqlConnection connection, string sql, Action <SqlDataReader> OnRead, CommandConfig config = null, params SqlParameter[] parameters)
 {
     try
     {
         using (SqlConnection con = connection)
         {
             con.Open();
             using (SqlCommand cmd = new SqlCommand(sql, connection))
             {
                 if (config is not null)
                 {
                     cmd.CommandType    = config.CommandType;
                     cmd.CommandTimeout = config.CommandTimeout;
                 }
                 if (parameters is not null)
                 {
                     cmd.Parameters.AddRange(parameters);
                 }
                 using (SqlDataReader reader = cmd.ExecuteReader())
                 {
                     if (config?.ManualRead ?? false)
                     {
                         OnRead.Invoke(reader);
                     }
                     else
                     {
                         while (reader.Read())
                         {
                             OnRead.Invoke(reader);
                         }
                     }
                 }
             }
             con.Close();
         }
     }
     catch (Exception ex)
     {
         Log.IsDBConnectionError(ex);
         Log.Logger.Error(ex, "Transaccion fallida reportada");
         Log.Logger.Error(sql);
     }
 }
        public static DataTable DataTable(this SqlConnection connection, string sql, string TableName = null, CommandConfig config = null, params SqlParameter[] parameters)
        {
            config = config ?? new CommandConfig();
            DataTable result = new DataTable(TableName);

            using (SqlConnection con = connection)
            {
                con.Open();
                using (SqlCommand cmd = new SqlCommand(sql, con)
                {
                    CommandType = config.CommandType
                })
                {
                    if (parameters != null)
                    {
                        cmd.Parameters.AddRange(parameters);
                    }
                    try
                    {
                        result.Load(cmd.ExecuteReader());
                    }
                    catch (Exception ex)
                    {
                        Log.Logger.Error(ex, "");
                        throw;
                    }
                }
                con.Close();
            }
            return(result);
        }
 public static void Read(this SqlConnection connection, string sql, Action <SqlDataReader> OnRead, CommandConfig config = null, IEnumerable <SqlParameter> parameters = null)
 {
     connection.Read(sql, OnRead, config, parameters?.ToArray());
 }