[SOLVED] Need a quick error check

Mikecro

Chieftain
Joined
Aug 16, 2022
Messages
13
Hello, I have a problem with this code for a unique unit - database keeps saying syntax error near ''INSERT'' but i cannot find any problems. I would really appreciate if someone would tell me whats wrong. I am trying to add Huscarls from Vikings scenario in game.

Here's code:
SQL:
INSERT INTO Types (Type, Kind) VALUES ('UNIT_NORWEGIAN_HUSCARL', 'KIND_UNIT'),
INSERT INTO Types (Type, Kind) VALUES ('ABILITY_PLUS_10_DEFENDER', 'KIND_ABILITY');

INSERT INTO TypeTags (Type, Tag) VALUES ('UNIT_NORWEGIAN_HUSCARL', 'CLASS_MELEE'),
INSERT INTO TypeTags (Type, Tag) VALUES ('ABILITY_PLUS_10_DEFENDER', 'CLASS_NORWEGIAN_HUSCARL');

INSERT INTO UnitAiInfos (UnitType, AiType) VALUES ('UNIT_NORWEGIAN_HUSCARL', 'UNITAI_COMBAT'),
INSERT INTO UnitAiInfos (UnitType, AiType) VALUES ('UNIT_NORWEGIAN_HUSCARL', 'UNITAI_EXPLORE'),
INSERT INTO UnitAiInfos (UnitType, AiType) VALUES ('UNIT_NORWEGIAN_HUSCARL', 'UNITTYPE_MELEE'),
INSERT INTO UnitAiInfos (UnitType, AiType) VALUES ('UNIT_NORWEGIAN_HUSCARL', 'UNITTYPE_LAND_COMBAT');

INSERT INTO Units (UnitType, BaseMoves, Cost, AdvisorType, BaseSightRange, ZoneOfControl, Domain, FormationClass, Name, Description, PurchaseYield, PromotionClass, Maintenance, Combat, PrereqCivic, MandatoryObsoleteTech, TraitType) VALUES ('UNIT_NORWEGIAN_HUSCARL', '2', '120', 'ADVISOR_CONQUEST', '2', 1, 'DOMAIN_LAND', 'FORMATION_CLASS_LAND_COMBAT', 'LOC_UNIT_NORWEGIAN_HUSCARL_NAME', 'LOC_UNIT_NORWEGIAN_HUSCARL_DESCRIPTION', 'YIELD_GOLD', 'PROMOTION_CLASS_MELEE', '2', '40', 'CIVIC_FEUDALISM', 'TECH_REPLACEABLE_PARTS', 'TRAIT_CIVILIZATION_UNIT_NORWEGIAN_HUSCARL');

INSERT INTO UnitUpgrades (Unit, UpgradeUnit) VALUES ('UNIT_NORWEGIAN_HUSCARL', 'UNIT_MUSKETMAN');

INSERT INTO UnitAbilities (UnitAbilityType, Name, Description) VALUES ('ABILITY_PLUS_10_DEFENDER', 'LOC_ABILITY_PLUS_10_DEFENDER_NAME', 'LOC_ABILITY_PLUS_10_DEFENDER_DESCRIPTION');

INSERT INTO TypeTags (Type, Tag) VALUES ('ABILITY_PLUS_10_DEFENDER', 'CLASS_NORWEGIAN_HUSCARL');

INSERT INTO RequirementSets (RequirementSetId, RequirementSetType) VALUES ('PLAYER_IS_DEFENDER_REQUIREMENTS_SET', 'REQUIREMENTSET_TEST_ANY');

INSERT INTO RequirementSetRequirements (RequirementSetId, RequirementId) VALUES ('PLAYER_IS_DEFENDER_REQUIREMENTS_SET', 'PLAYER_IS_DEFENDER_REQUIREMENTS');

INSERT INTO Modifiers (ModifierId, ModifierType, SubjectRequirementSetId) VALUES ('PLUS_10_WHEN_DEFENDING_COMBAT_BONUS', 'MODIFIER_UNIT_ADJUST_COMBAT_STRENGTH', 'PLAYER_IS_DEFENDER_REQUIREMENTS_SET');

INSERT INTO UnitAbilityModifiers (UnitAbilityType, ModifierId) VALUES ('ABILITY_PLUS_10_DEFENDER', 'PLUS_10_WHEN_DEFENDING_COMBAT_BONUS');

INSERT INTO ModifierStrings (ModifierId, Context, Description) VALUES ('PLUS_10_WHEN_DEFENDING_COMBAT_BONUS', 'Preview', 'PLUS_10_WHEN_DEFENDING_COMBAT_BONUS_DESCRIPTION');

INSERT INTO ModifierArguments (ModifierId, Name, Value) VALUES ('PLUS_10_WHEN_DEFENDING_COMBAT_BONUS', 'Amount', '10');

Here's database's log:
Code:
[2813948.487] [Localization]: StartupErrorMessages.xml
[2813948.487] [Localization]: Input XML does not contain database entry tags. GameData, GameInfo or Database
[2813954.881] [Localization]: Validating Foreign Key Constraints...
[2813954.881] [Localization]: Passed Validation.
[2813954.903] [Configuration]: Validating Foreign Key Constraints...
[2813954.904] [Configuration]: Passed Validation.
[2813957.229] [FullTextSearch]: Initializing FullTextSearch
[2813958.180] [Gameplay]: Validating Foreign Key Constraints...
[2813958.198] [Gameplay]: Passed Validation.
[2813959.467] [Configuration]: Validating Foreign Key Constraints...
[2813959.468] [Configuration]: Passed Validation.
[2813961.703] [HallofFame]: Database found. Checking versions...
[2813961.717] [HallofFame]: Database is up-to-date!
[2813981.742] [FullTextSearch]: FTS - Creating Context
[2813998.893] [Configuration]: Validating Foreign Key Constraints...
[2813998.893] [Configuration]: Passed Validation.
[2814020.322] [Gameplay] ERROR: near "INSERT": syntax error
[2814050.263] [Configuration]: Validating Foreign Key Constraints...
[2814050.264] [Configuration]: Passed Validation.
[2814053.388] [FullTextSearch]: FTS - Creating Context
[2814068.188] [FullTextSearch]: FullTextSearch - Shutting down

Thanks to anyone who helps.
Note: i dont know whats causing localization error but all xml files have GameData and GameInfo set properly, otherwise i wouldnt be able to build a mod. Using ModBuddy.
 

maconnolly

Warlord
Joined
Jun 3, 2019
Messages
190
Your issue is that you are repeating certain parts of code where you do not need to; or, alternatively, you are not 'closing' the statements with semi-colons in all cases. I'll just the very first code section to illustrate what I mean - the same principle applies to all of the code you shared.

Code:
INSERT INTO Types (Type, Kind) VALUES ('UNIT_NORWEGIAN_HUSCARL', 'KIND_UNIT'),
INSERT INTO Types (Type, Kind) VALUES ('ABILITY_PLUS_10_DEFENDER', 'KIND_ABILITY');

Above, you are inserting two sets of values into the 'Types' table. To do this, you only need the 'INSERT INTO Types' part once. The second set of values can just appear beneath the first set of values - with each set of values separated by commas.

Alternatively, you can repeat the 'INSERT INTO Types' part - however, at the end of each line, you need to use a semi-colon. The semi-colon is a delimiter that says "this is the end of this command - I will start a new command straight afterwards".

Valid alternatives are:

Code:
INSERT INTO Types (Type, Kind) VALUES ('UNIT_NORWEGIAN_HUSCARL', 'KIND_UNIT'), ('ABILITY_PLUS_10_DEFENDER', 'KIND_ABILITY');

The above would be my recommended approach - it is the most efficient. I would also recommend spacing it out a little differently - so each new set of values is on a new line. Something like this:
Code:
INSERT INTO Types (Type, Kind)
VALUES
('UNIT_NORWEGIAN_HUSCARL', 'KIND_UNIT'),
('ABILITY_PLUS_10_DEFENDER', 'KIND_ABILITY');

Note that we only put a semi-colon after our last values. We separate sets of values with commas. This is how we create a 'list' of values.

The following would also be valid code, but I am sure you can see why it is less efficient:

Code:
INSERT INTO Types (Type, Kind) VALUES ('UNIT_NORWEGIAN_HUSCARL', 'KIND_UNIT');
INSERT INTO Types (Type, Kind) VALUES ('ABILITY_PLUS_10_DEFENDER', 'KIND_ABILITY');

Here, we are writing two separate INSERT commands, one for each set of values we are adding to the Types table. The key point is that we delimit each code-line with a semi-colon to form valid syntax.

Hope this helps.
 

Mikecro

Chieftain
Joined
Aug 16, 2022
Messages
13
Your issue is that you are repeating certain parts of code where you do not need to; or, alternatively, you are not 'closing' the statements with semi-colons in all cases. I'll just the very first code section to illustrate what I mean - the same principle applies to all of the code you shared.

Code:
INSERT INTO Types (Type, Kind) VALUES ('UNIT_NORWEGIAN_HUSCARL', 'KIND_UNIT'),
INSERT INTO Types (Type, Kind) VALUES ('ABILITY_PLUS_10_DEFENDER', 'KIND_ABILITY');

Above, you are inserting two sets of values into the 'Types' table. To do this, you only need the 'INSERT INTO Types' part once. The second set of values can just appear beneath the first set of values - with each set of values separated by commas.

Alternatively, you can repeat the 'INSERT INTO Types' part - however, at the end of each line, you need to use a semi-colon. The semi-colon is a delimiter that says "this is the end of this command - I will start a new command straight afterwards".

Valid alternatives are:

Code:
INSERT INTO Types (Type, Kind) VALUES ('UNIT_NORWEGIAN_HUSCARL', 'KIND_UNIT'), ('ABILITY_PLUS_10_DEFENDER', 'KIND_ABILITY');

The above would be my recommended approach - it is the most efficient. I would also recommend spacing it out a little differently - so each new set of values is on a new line. Something like this:
Code:
INSERT INTO Types (Type, Kind)
VALUES
('UNIT_NORWEGIAN_HUSCARL', 'KIND_UNIT'),
('ABILITY_PLUS_10_DEFENDER', 'KIND_ABILITY');

Note that we only put a semi-colon after our last values. We separate sets of values with commas. This is how we create a 'list' of values.

The following would also be valid code, but I am sure you can see why it is less efficient:

Code:
INSERT INTO Types (Type, Kind) VALUES ('UNIT_NORWEGIAN_HUSCARL', 'KIND_UNIT');
INSERT INTO Types (Type, Kind) VALUES ('ABILITY_PLUS_10_DEFENDER', 'KIND_ABILITY');

Here, we are writing two separate INSERT commands, one for each set of values we are adding to the Types table. The key point is that we delimit each code-line with a semi-colon to form valid syntax.

Hope this helps.
It helped immensely! Now gameplay is finally finished. Didnt know about those rules with commas and semicolons so thanks again.
 
Top Bottom