SQL How to write "If" conditions?

Atlas627

Deity
Joined
Aug 25, 2011
Messages
2,930
I want to edit some of the rows in the District table, but only if the Corporations mode is enabled. Is there a way to check that, say, Industry improvements have been added to the Improvement table, then edit the District table? I can only come up with ways to check the District table itself before editing it.
 
Try :
Code:
WHERE EXISTS(SELECT * FROM Improvements_MODE WHERE ImprovementType = 'IMPROVEMENT_INDUSTRY')
This should execute the Insert or whatever statement if there is an entry in the Improvements_MODE table where there is an industry Improvement, that is only there if the Mode is active.
 
I see, I assumed a WHERE clause was only checking in the actual table I am issuing a command to. Seems like WHERE is basically an if clause, and that SELECT allows me to check a different table for the if clause. Thanks!
 
Code:
UPDATE Buildings 
SET Strategy = 'TXT_KEY_BUILDING_LRS_SAILMAKER_STRATEGY_EE', Help = 'TXT_KEY_BUILDING_LRS_SAILMAKER_HELP_EE'
WHERE Type = 'BUILDING_LRS_SAILMAKER'
AND EXISTS (SELECT 1 FROM Eras WHERE Type = 'ERA_ENLIGHTENMENT');
It's Civ5 tables and columns but the SQL logic is the same.

You can also use AND NOT EXISTS

You also need to make sure your UpdateDatabase Action that contains this code has a relatively high LoadOrder value to ensure your Update statement does not execute before the stuff from the new mode is enacted.

You can also make your Action itself dependant on a criteria that the correct game mode is active. From the Tech Tree Shuffle mode modinfo
Code:
	<ActionCriteria>
		<Criteria id="TreeRandomizer_Mode">
			<RuleSetInUse>RULESET_STANDARD,RULESET_EXPANSION_1,RULESET_EXPANSION_2</RuleSetInUse>
			<ConfigurationValueMatches>
				<Group>Game</Group>
				<ConfigurationId>GAMEMODE_TREE_RANDOMIZER</ConfigurationId>
				<Value>1</Value>
			</ConfigurationValueMatches>
		</Criteria>
		<Criteria id="TreeRandomizer_Mode_Expansion2">
			<RuleSetInUse>RULESET_EXPANSION_2</RuleSetInUse>
			<ConfigurationValueMatches>
				<Group>Game</Group>
				<ConfigurationId>GAMEMODE_TREE_RANDOMIZER</ConfigurationId>
				<Value>1</Value>
			</ConfigurationValueMatches>
		</Criteria>
	</ActionCriteria>
      ......
	<InGameActions>
		<UpdateDatabase id="TreeRandomizerDB" criteria="TreeRandomizer_Mode">
			<File>Data/TreeRandomizer_Technologies_MODE.xml</File>
			<File>Data/TreeRandomizer_Civics_MODE.xml</File>
			<File>Data/TreeRandomizer_Civilopedia_MODE.xml</File>
			<File>Data/TreeRandomizer_GameCapabilities.xml</File>
		</UpdateDatabase>
		<UpdateDatabase id="TreeRandomizerDB_Expansion2" criteria="TreeRandomizer_Mode_Expansion2">
			<File>Data/TreeRandomizer_Expansion2_MODE.xml</File>
		</UpdateDatabase>
	</InGameActions>
I haven't gone online with Steam for a while so the new update stuff hasn't downloaded to my computer -- I don't have the designation for the corporations mode handy at the moment.
 
Top Bottom