Ejemplo n.º 1
0
        public SQLIngameItemID GenerateNewIngameItemEntry(SQLIngameItemInfo _ItemInfo)
        {
            var conn = OpenConnection();

            try
            {
                using (var cmd = new NpgsqlCommand("INSERT INTO ingameitemtable(id, itemid, enchantid, suffixid, uniqueid) VALUES (DEFAULT, :ItemID, :EnchantID, :SuffixID, :UniqueID) RETURNING id", conn))
                {
                    cmd.Parameters.Add(new NpgsqlParameter("ItemID", NpgsqlDbType.Integer)).Value    = _ItemInfo.ItemID;
                    cmd.Parameters.Add(new NpgsqlParameter("EnchantID", NpgsqlDbType.Integer)).Value = _ItemInfo.EnchantID;
                    cmd.Parameters.Add(new NpgsqlParameter("SuffixID", NpgsqlDbType.Integer)).Value  = _ItemInfo.SuffixID;
                    cmd.Parameters.Add(new NpgsqlParameter("UniqueID", NpgsqlDbType.Integer)).Value  = _ItemInfo.UniqueID;
                    using (var reader = cmd.ExecuteReader())
                    {
                        if (reader.Read() == true)
                        {
                            return(new SQLIngameItemID(reader.GetInt32(0)));
                        }
                    }
                }
            }
            finally
            {
                CloseConnection();
            }
            return(new SQLIngameItemID(0));
        }
Ejemplo n.º 2
0
        public bool GetIngameItems(IEnumerable <SQLIngameItemID> _IngameItems, out Dictionary <SQLIngameItemID, SQLIngameItemInfo> _ResultItems)
        {
            var distinctItems = _IngameItems.Distinct();

            int[] itemsArray   = new int[distinctItems.Count()];
            int   itemsCounter = 0;

            foreach (var item in distinctItems)
            {
                if (item.ID > 0)
                {
                    itemsArray[itemsCounter++] = item.ID;
                }
            }
            if (itemsCounter != itemsArray.Length)
            {
                int[] oldItemsArray = itemsArray;
                itemsArray = new int[itemsCounter];
                for (int i = 0; i < itemsCounter; ++i)
                {
                    itemsArray[i] = oldItemsArray[i];
                }
            }
            var conn = OpenConnection();

            try
            {
                const int ID_COLUMN        = 0;
                const int ITEMID_COLUMN    = 1;
                const int ENCHANTID_COLUMN = 2;
                const int SUFFIXID_COLUMN  = 3;
                const int UNIQUEID_COLUMN  = 4;
                using (var cmd = new NpgsqlCommand("SELECT id, itemid, enchantid, suffixid, uniqueid FROM IngameItemTable WHERE id = ANY(:IDs)", conn))
                {
                    {
                        var idArrayParam = new NpgsqlParameter("IDs", NpgsqlDbType.Array | NpgsqlDbType.Integer);
                        idArrayParam.Value = itemsArray;
                        cmd.Parameters.Add(idArrayParam);
                    }
                    using (var reader = cmd.ExecuteReader())
                    {
                        if (reader.HasRows == true)
                        {
                            _ResultItems = new Dictionary <SQLIngameItemID, SQLIngameItemInfo>();
                            while (reader.Read())
                            {
                                SQLIngameItemID   sqlID    = new SQLIngameItemID(reader.GetInt32(ID_COLUMN));
                                SQLIngameItemInfo itemInfo = new SQLIngameItemInfo();
                                itemInfo.ItemID    = reader.GetInt32(ITEMID_COLUMN);
                                itemInfo.EnchantID = reader.GetInt32(ENCHANTID_COLUMN);
                                itemInfo.SuffixID  = reader.GetInt32(SUFFIXID_COLUMN);
                                itemInfo.UniqueID  = reader.GetInt32(UNIQUEID_COLUMN);
                                _ResultItems.AddOrSet(sqlID, itemInfo);
                            }
                            return(true);
                        }
                    }
                }
            }
            finally
            {
                CloseConnection();
            }
            _ResultItems = null;
            return(false);
        }