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:
I can also combine this with an outside SELECT statement to only return results if the leader exists:
The code above returns the entire list of Leaders if Jadwiga exists in the list.
However, this is invalid code:
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!
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!