SQL - Help

bane_

Howardianism High-Priest
Joined
Nov 27, 2013
Messages
1,559
Is it possible to do a 'flexible' update with SQL, only changing some value IF another value exists?

I want to create new entries in the table Buildings as <TibetMountain> and <TibetMountainNearby> with 'false' as the default, and want to update each building that has 'Mountain' to be turned 'false' and get 'true' on <TibetMountain>; then a similar process to <TibetMountainNearby> and 'NearbyMountainRequired'.

The reason I want to do this instead of manually changing the three BNW buildings with those requirements is because I want my mod to be modular, so any new building/wonder with a Mountain or NearbyMountainRequired will be updated when my mod loads.
 
Code:
-- No such thing as false or true in SQL, use 0 and 1 instead
ALTER TABLE Buildings ADD TibetMountain INTEGER DEFAULT 0;
UPDATE Buildings SET Mountain=0, TibetMountain=1 WHERE Mountain=1;

Will then work for all mods loaded before your's. If you need it to work regardless of load order, you'll also need to add a trigger.
 
As you've used SQL to alter the table, the game core doesn't work its magic to treat the columns as Booleans, so you'll need to use if (GameInfo.Buildings[iBuilding].TibetMountain == 1) then and not if (GameInfo.Buildings[iBuilding].TibetMountain) then
 
Top Bottom