public static int DBLookupID(OdbcConnection connection, String name, int version, Stage stage)
        {
            string lookupIDString = String.Format("SELECT id FROM Map WHERE name='{0}' AND version={1}", name, version);

            int id = -1;

            try
            {
                id = (int)DBExecuteScalar <long>(new OdbcCommand(lookupIDString, connection));
            }
            catch (KeyNotFoundException ex)
            {
                int mapStages = -1;
                if (stage != null)
                {
                    mapStages = stage.MapStages;
                }

                DBMap map = new DBMap(new Map {
                    Name = name, Version = version, Stages = mapStages
                });
                map.DBInsert(connection);
                id = map.Object.ID;
            }
            return(id);
        }
        public override void DBInsert(OdbcConnection connection)
        {
            new DBProfile(Object.Profile).DBInsert(connection, true);

            OdbcCommand cmd = new OdbcCommand(
                @"INSERT INTO GameInstance (id, profile, map, senderIP, startTime, endTime, dateReceived, timePlayed, nFrames, 
                    reason, endPosX, endPosY, endPosZ, hp, rage, ammunition, meleeWeapon, rangedWeapon, difficulty, gameVersion, 
                    stageNumber, stageHP, stageMaxHP, stageRage, stageTime, stageAmmo,
                    hitsTaken, damageDealt, damageTaken, timesNetted, nSlams, gbShots, totalShots, killedUnits) 
                  Values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);",
                connection);

            cmd.Parameters.Add("id", OdbcType.Binary, 16).Value         = Object.ID.ToByteArray();
            cmd.Parameters.Add("profile", OdbcType.Binary, 16).Value    = Object.Profile.ID.ToByteArray();
            cmd.Parameters.Add("map", OdbcType.Int).Value               = DBMap.DBLookupID(connection, Object.MapName, Object.MapVersion, Object.HighestStage);
            cmd.Parameters.Add("senderIP", OdbcType.VarChar, 20).Value  = Object.SenderIP ?? "";
            cmd.Parameters.Add("startTime", OdbcType.DateTime).Value    = Object.StartTime;
            cmd.Parameters.Add("endTime", OdbcType.DateTime).Value      = Object.EndTime;
            cmd.Parameters.Add("dateReceived", OdbcType.DateTime).Value = DateTime.Now;
            cmd.Parameters.Add("timePlayed", OdbcType.Decimal).Value    = Object.TimePlayed;
            cmd.Parameters.Add("nFrames", OdbcType.Int).Value           = Object.Frames;
            cmd.Parameters.Add("reason", OdbcType.VarChar, 100).Value   = Object.Reason ?? "";
            cmd.Parameters.Add("endPosX", OdbcType.Decimal).Value       = Object.EndPosX;
            cmd.Parameters.Add("endPosY", OdbcType.Decimal).Value       = Object.EndPosY;
            cmd.Parameters.Add("endPosZ", OdbcType.Decimal).Value       = Object.EndPosZ;
            cmd.Parameters.Add("hp", OdbcType.Int).Value                  = Object.Hitpoints;
            cmd.Parameters.Add("rage", OdbcType.Int).Value                = Object.Rage;
            cmd.Parameters.Add("ammunition", OdbcType.Int).Value          = Object.Ammunition;
            cmd.Parameters.Add("meleeWeapon", OdbcType.Int).Value         = Object.MeleeWeapon;
            cmd.Parameters.Add("rangedWeapon", OdbcType.Int).Value        = Object.RangedWeapon;
            cmd.Parameters.Add("difficulty", OdbcType.VarChar, 15).Value  = Object.Difficulty ?? "";
            cmd.Parameters.Add("gameVersion", OdbcType.VarChar, 30).Value = Object.GameVersion ?? "";

            var stage = Object.HighestStage;

            cmd.Parameters.Add("stageNumber", OdbcType.Int).Value   = stage != null ? stage.StageNumber : -1;
            cmd.Parameters.Add("stageHP", OdbcType.Int).Value       = stage != null ? stage.HitPoints : -1;
            cmd.Parameters.Add("stageMaxHP", OdbcType.Int).Value    = stage != null ? stage.MaxHitPoints : -1;
            cmd.Parameters.Add("stageRage", OdbcType.Int).Value     = stage != null ? stage.Rage : -1;
            cmd.Parameters.Add("stageTime", OdbcType.Decimal).Value = stage != null ? stage.Time : -1;
            cmd.Parameters.Add("stageAmmo", OdbcType.Int).Value     = stage != null ? stage.Ammo : -1;

            cmd.Parameters.Add("hitsTaken", OdbcType.Int).Value   = Object.HitsTaken;
            cmd.Parameters.Add("damageDealt", OdbcType.Int).Value = Object.DamageDealt;
            cmd.Parameters.Add("damageTaken", OdbcType.Int).Value = Object.DamageTaken;
            cmd.Parameters.Add("timesNetted", OdbcType.Int).Value = Object.TimesNetted;
            cmd.Parameters.Add("nSlams", OdbcType.Int).Value      = Object.NSlams;
            cmd.Parameters.Add("gbShots", OdbcType.Int).Value     = Object.GBShots;
            cmd.Parameters.Add("totalShots", OdbcType.Int).Value  = Object.TotalShots;
            cmd.Parameters.Add("killedUnits", OdbcType.Int).Value = Object.KilledUnits;

            PrintCommandString(cmd, 300);
            DBExecute(cmd);
        }