Insert new UnitDef into the database

From Battletech Modding Wiki
Jump to: navigation, search
-- SQL Lite doesn't support sql @variables, so we create this temp table to serve as a way to use variables.
CREATE TEMP TABLE IF NOT EXISTS Variables (Name TEXT PRIMARY KEY, Value TEXT);

-- I'm using Insert Or Replace because if there's a problem in the script you can 
-- just fix the variables' values and rerun it to insert the correct data without
-- having to track down what failed.

-- Here you need to replace the values with your new data. Any unique text will probably work.
--                                                        vvvvvvvvvvvvvvvvvv - Change this column
INSERT OR REPLACE INTO Variables VALUES ('NewTagSetGuid', 'UniqueIdGoesHere');
INSERT OR REPLACE INTO Variables VALUES ('UnitDefId',     'mechdef_Eck'); -- This value is case sensitive, make sure it matches in the manifest and on disk just to be sure.
INSERT OR REPLACE INTO Variables VALUES ('FriendlyName',  'Eck');

-- Create the new TagSet using the id stored in NewTagSetGuid.
INSERT OR REPLACE INTO TagSet  (TagSetId, TagSetTypeId) VALUES((SELECT Value FROM Variables where Name='NewTagSetGuid' ), 5);

-- Add these Tags to the new TagSet
INSERT OR REPLACE INTO TagSetTag (TagSetID, TagId) VALUES ((SELECT Value FROM Variables where Name='NewTagSetGuid' ), '66a63b7b-1244-405b-8c05-fb54582348f5');
INSERT OR REPLACE INTO TagSetTag (TagSetID, TagId) VALUES ((SELECT Value FROM Variables where Name='NewTagSetGuid' ), 'c6cc2cec-800f-46b7-9a65-a3447b0bf3e8');
INSERT OR REPLACE INTO TagSetTag (TagSetID, TagId) VALUES ((SELECT Value FROM Variables where Name='NewTagSetGuid' ), '2f42a194-bcde-4f4b-bc1d-43a05571652c');
INSERT OR REPLACE INTO TagSetTag (TagSetID, TagId) VALUES ((SELECT Value FROM Variables where Name='NewTagSetGuid' ), 'a6790fc4-7145-43cc-a880-0a278a0810e1');
--INSERT OR REPLACE INTO TagSetTag (TagSetID, TagId) VALUES ((SELECT Value FROM Variables where Name='NewTagSetGuid' ), '');

-- Insert the new UnitDef
INSERT OR REPLACE INTO UnitDef (UnitDefId, FriendlyName, IconId, UnitTypeId, Cost, TagSetId) VALUES ((SELECT Value FROM Variables where Name='UnitDefId'), (SELECT Value FROM Variables where Name='FriendlyName'), '', 1, 1000000, (SELECT Value FROM Variables where Name='NewTagSetGuid' ));

-- Look at the data after we're done inserting.
SELECT 
	ud.*,
	t.Name as Tag
	FROM UnitDef ud
	INNER JOIN TagSetTag tst ON 
		ud.TagSetId = tst.TagSetId
	INNER JOIN Tag t ON
		tst.TagId = t.TagId
	WHERE
		ud.UnitDefId = (SELECT Value FROM Variables where Name='UnitDefId');

		
DROP TABLE Variables;