Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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());
 }
Ejemplo n.º 3
0
 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);
     }
 }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
 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());
 }