Esempio n. 1
0
        public static void CleanTable <T>() where T : new()
        {
            var table           = GetTableNameWithQuotes <T>();
            var cleanTableQuery = $"TRUNCATE {table}";

            DataBaseDataReader.ExecuteNonQuery(new ConfigurationSettings().ConnectionString, cleanTableQuery);
        }
Esempio n. 2
0
        public static void InsertMultiples <T>(string connectionString, IList <T> entities, bool getLastId = true) where T : new()
        {
            var query = new StringBuilder();

            entities.ToList().ForEach(entity =>
            {
                var insertBuilder = new InsertQueryBuilder()
                                    .WithFields(EntityFactory.GetFieldsWithValues(entity, true));

                query.Append(insertBuilder.Build <T>());
                query.Append(";");
            });

            if (getLastId && KeyAttribute.HasEntityAutoIncremenetalKey <T>())
            {
                query.Append("SELECT LAST_INSERT_ID()");
                using var exe = new DataBaseExecuteReader(connectionString, query.ToString());
                if (exe.DataReader.Read())
                {
                    var keyProperty = KeyAttribute.GetAutoIncrementKeyProperty <T>();
                    var lastId      = (int)exe.DataReader.GetULong(0) - entities.Count();
                    entities.ToList().ForEach(entity =>
                    {
                        keyProperty.SetValue(entity, Convert.ChangeType(++lastId, keyProperty.PropertyType));
                    });
                }
            }
            else
            {
                DataBaseDataReader.ExecuteNonQuery(connectionString, query.ToString());
            }
        }
Esempio n. 3
0
        public static void Replace <T>(string connectionString, T entity) where T : new()
        {
            var replaceBuilder = new ReplaceQueryBuilder()
                                 .WithFields(EntityFactory.GetFieldsWithValues(entity, false));

            var query = replaceBuilder.Build <T>();

            DataBaseDataReader.ExecuteNonQuery(connectionString, query);
        }
Esempio n. 4
0
        public static void Delete <T>(string connectionString, T entity) where T : new()
        {
            var(condition, wheres) = KeyAttribute.GetKeysQueryWhere(entity);

            var deleteQueryBuilder = new DeleteQueryBuilder()
                                     .WithWhere(condition, wheres.ToArray());

            var query = deleteQueryBuilder.Build <T>();

            DataBaseDataReader.ExecuteNonQuery(connectionString, query);
        }
Esempio n. 5
0
        private static void Update <T>(string connectionString, T entity, Dictionary <string, object> fieldsWithValues) where T : new()
        {
            var(condition, wheres) = KeyAttribute.GetKeysQueryWhere(entity);

            var updateBuilder = new UpdateQueryBuilder()
                                .WithFields(fieldsWithValues)
                                .WithWhere(condition, wheres.ToArray());

            var query = updateBuilder.Build <T>();

            DataBaseDataReader.ExecuteNonQuery(connectionString, query);
        }
Esempio n. 6
0
 public ulong GetLastInsertId()
 {
     return(DataBaseDataReader.GetLastInsertId(connectionString));
 }
Esempio n. 7
0
 public Result <T> GetSelectValue <T>(string query, List <MySqlParameter> parameters = null)
 {
     return(DataBaseDataReader.GetSelectValue <T>(connectionString, query, parameters));
 }
Esempio n. 8
0
 public void ExecuteNonQuery(string query, List <MySqlParameter> parameters)
 {
     DataBaseDataReader.ExecuteNonQuery(connectionString, query, parameters);
 }
Esempio n. 9
0
 public void ExecuteNonQuery(string query)
 {
     DataBaseDataReader.ExecuteNonQuery(connectionString, query);
 }