Database.exe Errors

Database.exe - Downgrading 4.6.1.20 and above results in an error within the Translines Table.

Overview

Problem / Symptoms:

Change made in 4.6.1.20 to the way seat numbers are stored. We are now storing a bit field instead of just a straight seat number. This was done to add support for shared items that was removed a few versions back to fix an issue with Seat # 0 and YourOrder. The bit field will be used later to allow us to share items to specific seats.

Diagnosis:

What this means is that if you need to downgrade anyone that uses seat numbers from 4.6.1.20 to any earlier version, it will fail on the TransLines table

Solution / resolution:

The following SQL Script should be run only ONCE prior to downgrading the Database to an earlier version of Bepoz 

If (Select Max(SeatNum) from Translines) > 32767

BEGIN

    Print 'Downgrading Seat Numbers'

    update TransLines

    set SeatNum = 0

    where SeatNum = 9223372036854775807

    Update TransLines

    SET SeatNum = 0

    where SeatNum <> 0

    and LOG(SeatNum,2) <> ROUND(LOG(SeatNum,2),0,0)

    update TransLines

    set SeatNum = LOG(SeatNum,2) + 1

    where SeatNum <> 9223372036854775807

    and SeatNum <> 0

    and LOG(SeatNum,2) = ROUND(LOG(SeatNum,2),0,0)

END