Is it possible to create a trigger when another Mod is active in SQL?

Only if that mod adds a known and unique entry into the database. For example, you can test for the Xyz Era via the condition

Code:
... WHERE EXISTS (SELECT 1 FROM Eras WHERE Type='ERA_XYZ');

However, adding such a clause to the end of EVERY SQL statement to update every table for a building can get extremely irksome.

There are a couple of approaches to reduce the work

a) Add the building and all associated tables via SQL/XML assuming the mod is in use, then delete the building if the mod isn't in use and use the <DeleteMissingReferences> tag (the CivV equivalent of cascade delete) to clean up all the secondary tables

b) Put all the secondary table SQL into a trigger that fires on adding the main building entry, use the above to conditionally add the building (which will cause the trigger to fire), then delete the trigger.

c) Add the building et al as normal, then use Lua to stop it being built!

For both a) and b) make sure your mod References the other mod

HTH

W
 
I'm trying to update a specific building from a different mod when used with another, so using your trigger code.
Code:
UPDATE Language_EN_US 
SET Text = 'The Stone Temple grants +2 [ICON_PEACE] Faith and +2 [ICON_CULTURE] Culture. Requires a Shrine before the Stone Temple can be constructed.'
WHERE Tag = 'TXT_KEY_BUILDING_STEMPLES_STRATEGY' AND EXISTS (SELECT 1 FROM Buildings WHERE Type='BUILDING_STEMPLES');

UPDATE Buildings 
SET Cost = '150' 
WHERE Type = 'BUILDING_STEMPLES' AND EXISTS (SELECT 1 FROM Buildings WHERE Type='BUILDING_STEMPLES');

UPDATE Building_YieldChanges
SET Yield = '0'
WHERE BuildingType = 'BUILDING_STEMPLES' AND YieldType = 'YIELD_GOLD' AND EXISTS (SELECT 1 FROM Buildings WHERE Type='BUILDING_STEMPLES');

UPDATE Building_YieldChanges
SET Yield = '2'
WHERE BuildingType = 'BUILDING_STEMPLES' AND YieldType = 'YIELD_CULTURE' AND EXISTS (SELECT 1 FROM Buildings WHERE Type='BUILDING_STEMPLES');

INSERT INTO Building_ResourceYieldChanges (BuildingType, ResourceType, YieldType, Yield)
VALUES ('BUILDING_STEMPLES', 'RESOURCE_INCENSE', 'YIELD_CULTURE', '1')
WHERE EXISTS (SELECT 1 FROM Buildings WHERE Type='BUILDING_STEMPLES');

INSERT INTO Building_ResourceYieldChanges (BuildingType, ResourceType, YieldType, Yield)
VALUES ('BUILDING_STEMPLES', 'RESOURCE_INCENSE', 'YIELD_GOLD', '1')
WHERE EXISTS (SELECT 1 FROM Buildings WHERE Type='BUILDING_STEMPLES');

INSERT INTO Building_ResourceYieldChanges (BuildingType, ResourceType, YieldType, Yield)
VALUES ('BUILDING_STEMPLES', 'RESOURCE_WINE', 'YIELD_CULTURE', '1')
WHERE EXISTS (SELECT 1 FROM Buildings WHERE Type='BUILDING_STEMPLES');

INSERT INTO Building_ResourceYieldChanges (BuildingType, ResourceType, YieldType, Yield)
VALUES ('BUILDING_STEMPLES', 'RESOURCE_WINE', 'YIELD_GOLD', '1')
WHERE EXISTS (SELECT 1 FROM Buildings WHERE Type='BUILDING_STEMPLES');

INSERT INTO Building_ResourceYieldChanges (BuildingType, ResourceType, YieldType, Yield)
VALUES ('BUILDING_STEMPLES', 'RESOURCE_STONE', 'YIELD_CULTURE', '1')
WHERE EXISTS (SELECT 1 FROM Buildings WHERE Type='BUILDING_STEMPLES');

INSERT INTO Building_Flavors (BuildingType, FlavorType, Flavor)
VALUES ('BUILDING_STEMPLES', 'FLAVOR_CULTURE', '25')
WHERE EXISTS (SELECT 1 FROM Buildings WHERE Type='BUILDING_STEMPLES');

And it created these errors when loading the mod:
Code:
near "WHERE": syntax error
no such column: BuildingType
and when I started a new game, CTD:
Code:
no such column: Type
 
INSERT does not take a WHERE clause. So you'll have to recast them as INSERT ... (SELECT ... WHERE ...) style statements. Which is why I say such an approach is a real PITA.

Probably best to use the "add it all, and then delete it again if the other mod isn't in use" approach
 
Code:
no such column: BuildingType

In the datalog would say that a column of BuildingType is somewhere where it shouldn't exist. Is there anyway to extract more information since I can always repeat the CTD, but I do want to be time efficient.
 
Download SQLiteSpy, connect to the debug version of the database (in the cache sub-directory) and execute each SQL statement. Any errors will be reported.
 
Download SQLiteSpy, connect to the debug version of the database (in the cache sub-directory) and execute each SQL statement. Any errors will be reported.

Uhh, how would I execute each SQL statement? By right-clicking each table and making a select statement and running them?

Never mind, the no column buildingtype is a regular error. Something else is causing the CTD and isn't reporting it in any of the logs. Have to revert back to an older version. :(
 
Back
Top Bottom