private static IPBlockBE PopulateIPBlock(IDataRecord dr) {
     IPBlockBE ipBlock = new IPBlockBE();
     ipBlock.Address = GetUTF8String(dr, "ipb_address");
     ipBlock.UserID = DbUtils.Convert.To<uint>(dr["ipb_user"]).Value;
     ipBlock.ByUserID = DbUtils.Convert.To<uint>(dr["ipb_by"]).Value;
     ipBlock.Reason = GetUTF8String(dr, "ipb_reason");
     ipBlock.Timestamp = GetUTF8String(dr, "ipb_timestamp");
     ipBlock.Auto = DbUtils.Convert.To<uint>(dr["ipb_auto"]).Value;
     ipBlock.AnonymousOnly = DbUtils.Convert.To<uint>(dr["ipb_anon_only"]).Value;
     ipBlock.CreateAccount = DbUtils.Convert.To<uint>(dr["ipb_create_account"]).Value;
     ipBlock.EnableAutoBlock = DbUtils.Convert.To<uint>(dr["ipb_enable_autoblock"]).Value;
     ipBlock.Expiry = GetUTF8String(dr, "ipb_expiry");
     return ipBlock;
 }
 public static void InsertDWIPBlock(IPBlockBE ipBlock) {
     uint banID = 0;
     MediaWikiConverterContext.Current.DWCatalog.NewQuery(String.Format("INSERT into bans (ban_by_user_id, ban_reason, ban_revokemask, ban_last_edit) VALUES ('{0}', '{1}', '{2}', '{3}');  SELECT LAST_INSERT_ID() as banid;",
        ipBlock.ByUserID, DataCommand.MakeSqlSafe(ipBlock.Reason), 9223372036854779902, ipBlock.Timestamp)).Execute(delegate(IDataReader dr) {
         while (dr.Read()) {
             banID = DbUtils.Convert.To<uint>(dr["banid"], 0);
         }
     });
     if (0 == ipBlock.UserID) {
         MediaWikiConverterContext.Current.DWCatalog.NewQuery(String.Format("INSERT into banips (banip_ipaddress, banip_ban_id) VALUES ('{0}', '{1}')",
            DataCommand.MakeSqlSafe(ipBlock.Address), banID)).Execute();
     } else {
         MediaWikiConverterContext.Current.DWCatalog.NewQuery(String.Format("INSERT into banusers (banuser_user_id, banuser_ban_id) VALUES ('{0}', '{1}')",
            ipBlock.UserID, banID)).Execute();
     }
 }