SQL error

qqqbbb

Prince
Joined
Sep 25, 2010
Messages
530
This simple sql line
Code:
UPDATE Government_SlotCounts SET GovernmentSlotType = 'SLOT_WILDCARD';
gives error: "UNIQUE constraint failed". Anyone knows why?
 
Try this:

UPDATE Governments SET GovernmentSlotType = "SLOT_WILDCARD";

This will make every slot type a wildcard (which I think is your intent)
 
This simple sql line
Code:
UPDATE Government_SlotCounts SET GovernmentSlotType = 'SLOT_WILDCARD';
gives error: "UNIQUE constraint failed". Anyone knows why?

If you want to make every slot a WildCard try
Code:
DELETE FROM Government_SlotCounts;

INSERT INTO Government_SlotCounts (GovernmentType, GovernmentSlotType, NumSlots) VALUES ('GOVERNMENT_CHIEFDOM', 'SLOT_WILDCARD', 2);
INSERT INTO Government_SlotCounts (GovernmentType, GovernmentSlotType, NumSlots) VALUES ('GOVERNMENT_AUTOCRACY', 'SLOT_WILDCARD', 4);
INSERT INTO Government_SlotCounts (GovernmentType, GovernmentSlotType, NumSlots) VALUES ('GOVERNMENT_OLIGARCHY', 'SLOT_WILDCARD', 4);
INSERT INTO Government_SlotCounts (GovernmentType, GovernmentSlotType, NumSlots) VALUES ('GOVERNMENT_CLASSICAL_REPUBLIC', 'SLOT_WILDCARD', 4);
INSERT INTO Government_SlotCounts (GovernmentType, GovernmentSlotType, NumSlots) VALUES ('GOVERNMENT_MONARCHY', 'SLOT_WILDCARD', 6);
INSERT INTO Government_SlotCounts (GovernmentType, GovernmentSlotType, NumSlots) VALUES ('GOVERNMENT_THEOCRACY', 'SLOT_WILDCARD', 6);
INSERT INTO Government_SlotCounts (GovernmentType, GovernmentSlotType, NumSlots) VALUES ('GOVERNMENT_MERCHANT_REPUBLIC', 'SLOT_WILDCARD', 6);
INSERT INTO Government_SlotCounts (GovernmentType, GovernmentSlotType, NumSlots) VALUES ('GOVERNMENT_FASCISM', 'SLOT_WILDCARD', 8);
INSERT INTO Government_SlotCounts (GovernmentType, GovernmentSlotType, NumSlots) VALUES ('GOVERNMENT_COMMUNISM', 'SLOT_WILDCARD', 8);
INSERT INTO Government_SlotCounts (GovernmentType, GovernmentSlotType, NumSlots) VALUES ('GOVERNMENT_DEMOCRACY', 'SLOT_WILDCARD', 8);

It's in the Governments.xml file which is what the UPDATE references

This is just wrong.
 
"UNIQUE constraint failed" is because the combination of the first 2 columns is the primary key, and therefore there can't be 2 identical rows over the combination of GovernmentType and GovernmentSlotType. You could do something like alberts2 and just rebuild the database from scratch, or if you want to make it flexible to changes Firaxis might make as they rebalance the game going forward, not to mention maintaining compatibility with changes other mods a user might also be using (though for that you'll want a trigger as well, since you won't know in what order you're going to be loaded), you'd use something like this:

Code:
REPLACE INTO Government_SlotCounts (GovernmentType, GovernmentSlotType, NumSlots)
    SELECT a.GovernmentType, 'SLOT_WILDCARD', a.NumSlots + b.NumSlots
    FROM Government_SlotCounts AS a, Government_SlotCounts AS b
    WHERE a.GovernmentType = b.GovernmentType
    AND a.GovernmentSlotType = 'SLOT_DIPLOMATIC'
    AND b.GovernmentSlotType = 'SLOT_WILDCARD';
DELETE FROM Government_SlotCounts
    WHERE GovernmentSlotType = 'SLOT_DIPLOMATIC';
 
There is no GovernmentSlotType column in Governments table.
@qqqbbb is absolutely correct in this. The definition of table <Governments> is as follows:
Code:
CREATE TABLE "Governments" (
  "GovernmentType" TEXT NOT NULL,
  "Name" TEXT NOT NULL,
  "PrereqCivic" TEXT,
  "InherentBonusDesc" TEXT NOT NULL,
  "AccumulatedBonusShortDesc" TEXT NOT NULL,
  "AccumulatedBonusDesc" TEXT NOT NULL,
  "OtherGovernmentIntolerance" INTEGER NOT NULL DEFAULT 0,
  "InfluencePointsPerTurn" INTEGER NOT NULL,
  "InfluencePointsThreshold" INTEGER NOT NULL,
  "InfluenceTokensPerThreshold" INTEGER NOT NULL,
  "BonusType" TEXT NOT NULL,
  PRIMARY KEY(GovernmentType),
  FOREIGN KEY (PrereqCivic) REFERENCES Civics(CivicType) ON DELETE SET DEFAULT ON UPDATE SET DEFAULT,
  FOREIGN KEY (BonusType) REFERENCES GovernmentBonusNames(GovernmentBonusType) ON DELETE SET DEFAULT ON UPDATE SET DEFAULT,
  FOREIGN KEY (GovernmentType) REFERENCES Types(Type) ON DELETE CASCADE ON UPDATE CASCADE);
Column named "GovernmentSlotType" is nowhere therein, so any attempt to state it as part of table <Governments> is going to result in fatal errors to the code.

See folder C:\Program Files (x86)\Steam\SteamApps\common\Sid Meier's Civilization VI\Base\Assets\Gameplay\Data\Schema for the definitions of all gametables that are adjusted or added to by files within the
Code:
<Components>
     <UpdateDatabase id="xxxxxxxxxxxxxx">
          <Items>
               <File>Filename.xml</File>
               <File>Filename.sql</File>
          </Items>
     </UpdateDatabase>
</Components>
portion of the modinfo file.

See folder C:\Program Files (x86)\Steam\SteamApps\common\Sid Meier's Civilization VI\Base\Assets\Configuration\Data\Schema for the definitions of all gametables that are adjusted by files within the
Code:
<Settings>
     <Custom id="SETTINGS">
          <Items>
                <File>Config.xml</File>
                 <File>Config.sql</File>
         </Items>
      </Custom>
</Settings>
portion of the modinfo file.
 
Back
Top Bottom