Esempio n. 1
0
        public void Add(DBItem item)
        {
            if (!item.getAllProperties().Any())
            {
                Watchtower.OmniusWarning.Log($"Try to insert no values to table [{RealName}]", Watchtower.OmniusLogSource.Entitron, _db.Application);
                return;
            }

            _itemsToAdd.Add(item);
            _db.SaveTable(this);
        }
Esempio n. 2
0
        public override IDbCommand INSERT(DBConnection db, string tableName, DBItem item)
        {
            MySqlCommand command = new MySqlCommand();

            IEnumerable <string> columnNames = item.getColumnNames().Except(new string[] { PrimaryKey, FullPrimaryKey(tableName, false) });

            command.CommandText =
                $"INSERT INTO {ToRealTableName(db.Application, tableName)}({string.Join(",", columnNames.Select(c => AddQuote(c)))}) " +
                $"VALUES ({string.Join(",", columnNames.Select(c => $"@{command.AddParam(c, item[c])}"))});" +
                $"SELECT LAST_INSERT_ID() {PrimaryKey};";

            return(command);
        }
Esempio n. 3
0
        public DBTable Delete(DBItem item)
        {
            Manager <Condition> conditions = new Manager <Condition>(_db);

            conditions.i.tabloidName = Name;
            foreach (string columnName in item.getFullColumnNames())
            {
                conditions.Start();
                conditions.i.column = columnName;
                conditions.i.operation_params.Add(item[columnName]);
                conditions.Next();
            }

            _db.Commands.Enqueue(_db.CommandSet.DELETE(_db, Name, conditions));

            return(this);
        }
Esempio n. 4
0
        public int AddGetId(DBItem item)
        {
            if (!item.getAllProperties().Any())
            {
                Watchtower.OmniusWarning.Log($"Try to insert no values to table [{RealName}]", Watchtower.OmniusLogSource.Entitron, _db.Application);
                return(-1);
            }

            item.Tabloid = this;
            using (DBReader reader = _db.ExecuteCommand(_db.CommandSet.INSERT(_db, Name, item)))
            {
                reader.Read();
                int id = Convert.ToInt32(reader[DBCommandSet.PrimaryKey]);
                item[DBCommandSet.PrimaryKey] = id;
                return(id);
            }
        }
Esempio n. 5
0
        public ListJson <DBItem> Read(DBReader reader, Tabloid tabloid)
        {
            ListJson <DBItem> items = new ListJson <DBItem>();

            while (reader.Read())
            {
                DBItem newItem = new DBItem(this, tabloid);

                for (int i = 0; i < reader.FieldCount; i++)
                {
                    string columnName = reader.GetName(i);
                    newItem[columnName] = reader[columnName];
                }

                items.Add(newItem);
            }

            return(items);
        }
Esempio n. 6
0
        public override IDbCommand UPDATE(DBConnection db, string tableName, int rowId, DBItem item)
        {
            MySqlCommand command = new MySqlCommand();

            var columnTuples = ColumnsToTuple(db.Application, tableName, item.getFullColumnNames()).Where(ct => ct.Item2 != PrimaryKey);

            command.CommandText =
                $"UPDATE {ToRealTableName(db.Application, tableName)} SET {string.Join(", ", columnTuples.Select(pair => $"{ToRealTableName(db.Application, pair.Item1)}.{AddQuote(pair.Item2)}=@{command.AddParam(pair.Item2, item[$"{pair.Item1}.{pair.Item2}"])}"))} WHERE {ToRealTableName(db.Application, tableName)}.{AddQuote(PrimaryKey)}=@_{PrimaryKey}_;";

            command.Parameters.Add(new MySqlParameter($"_{PrimaryKey}_", rowId));

            return(command);
        }
Esempio n. 7
0
        public DBTable Update(DBItem item, int id)
        {
            _db.Commands.Enqueue(_db.CommandSet.UPDATE(_db, Name, id, item));

            return(this);
        }
Esempio n. 8
0
 public abstract IDbCommand UPDATE(DBConnection db, string tableName, int rowId, DBItem values);
Esempio n. 9
0
        public virtual IDbCommand INSERT_withoutId(DBConnection db, string tableName, DBItem item)
        {
            IDbCommand command = Command;

            IEnumerable <string> columnNames = item.getColumnNames().Except(new string[] { PrimaryKey, FullPrimaryKey(tableName, false) });

            command.CommandText =
                $"INSERT INTO {ToRealTableName(db.Application, tableName)}({string.Join(",", columnNames.Select(c => AddQuote(c)))}) " +
                $"VALUES ({string.Join(",", columnNames.Select(key => $"@{command.AddParam(key, item[key])}"))});";

            return(command);
        }
Esempio n. 10
0
 public abstract IDbCommand INSERT(DBConnection db, string tableName, DBItem item);