SQLite: How to detect values from DLC?

isau

Deity
Joined
Jan 15, 2007
Messages
3,071
Hey guys, I'm totally stuck on this. What I want to be able to do is mod leaders like Jadwiga and Montezuma without requiring players to have every single DLC installed. I know various tricks to affect all leaders, but when trying to address them specifically I run into the problem of not being able to tell if the primary keys these leaders require exist in the database. As soon as I try to mod one of them, if the player doesn't have the DLC installed, the game crashes.

I know that this code correctly returns a 1 if Jadwiga is present and 0 if she is not:

Code:
SELECT  EXISTS (
           SELECT 1
             FROM Leaders
            WHERE Leaders.LeaderType = 'LEADER_JADWIGA'
       )

I can also combine this with an outside SELECT statement to only return results if the leader exists:

Code:
SELECT * from leaders where EXISTS (
           SELECT 1
             FROM Leaders
            WHERE Leaders.LeaderType = 'LEADER_JADWIGA'
       )

The code above returns the entire list of Leaders if Jadwiga exists in the list.

However, this is invalid code:

Code:
INSERT INTO Modifiers
    (ModifierId, ModifierType, RunOnce, Permanent, OwnerRequirementSetId, SubjectRequirementSetId)
VALUES    ('QUO_POLAND_MODIFIER', 'MODIFIER_ALL_CITIES_TERRAIN_ADJACENCY', 0, 0, NULL, NULL) 
WHERE EXISTS (
           SELECT 1
             FROM Leaders
            WHERE Leaders.LeaderType = 'LEADER_JADWIGA'
       ) ;


The question now is how do I safely perform an INSERT into tables like LeaderTraits that use LeaderType as a primary key? Ideally, I would run the check, see if the leader exists, and only attempt to run the code if so. But I cannot figure out a clean way to make that happen.

I'm also aware of statements like INSERT OR IGNORE but have no experience with them. Is that what I should be using here instead of just INSERT? I'd really like to avoid having to make players download a separate mod to accommodate every possible DLC they might have.

Thanks for any help!
 
Update, I may have answered my own question, although this method feels like it may not be the best way to accomplish this. The code below seems to handle this situation:

Code:
INSERT INTO Modifiers
    (ModifierID,             ModifierType,                     RunOnce,     Permanent,     OwnerRequirementSetId,     SubjectRequirementSetId)
SELECT    'QUO_POLAND_MODIFIER',               'MODIFIER_PLAYER_CITIES_FEATURE_ADJACENCY',     0,         0,         NULL,            NULL    
FROM Leaders WHERE Leaders.LeaderType = 'LEADER_JADWIGA';

Basically, if Jadwiga doesn't exist in the Leaders table, the WHERE clause limits the number of returned rows to 0 and prevents the code from running. Not the cleanest thing ever, but I'll take it, unless someone knows a better way?
 
I'm pretty sure it has to be done the way you are doing it.

As I recall sqlite does not allow a INSERT INTO VALUES WHERE structure of the syntax, only a INSERT INTO SELECT FROM WHERE structure of the syntax.

In Civ5 we could also just insert the data and then later delete if something did not exist, like this sort of thing:
Code:
INSERT INTO Technologies
		(Type,				Cost,	Description,					Era,			GridX,	GridY,	PortraitIndex,	IconAtlas,	Disable,	Civilopedia,					Help,						Quote,						WorkerSpeedModifier) 
VALUES		('TECH_LRSDUMMY_ENLIGHTENMENT',  13500,	'TXT_KEY_TECH_RSDUMMY_ENLIGHTENMENT_TITLE',	'ERA_ENLIGHTENMENT',	9,	12,	31,		'TECH_ATLAS_1', 1,		'TXT_KEY_TECH_LRSDUMMY_ENLIGHTENMENT_DESC',	'TXT_KEY_TECH_LRSDUMMY_ENLIGHTENMENT_HELP',	'TXT_KEY_TECH_LRSDUMMY_ENLIGHTENMENT_QUOTE',	10);

DELETE FROM Technologies WHERE Type = 'TECH_LRSDUMMY_ENLIGHTENMENT' 
AND NOT EXISTS (SELECT 1 FROM Eras WHERE Type = 'ERA_ENLIGHTENMENT');
But Civ6 has that CASCADE ON INSERT and CASCADE ON DELETE stuff in the table-definitions and I'm not sure yet if that is really different than the auto-increment behavior of civ5 for primary columns.
 
Back
Top Bottom