XML-SQL Cheat Sheet (Civ5)

From Civilization Modding Wiki
Revision as of 20:02, 2 September 2012 by DonQuich (talk | contribs) (Created page with "== Inserting rows == === XML === <syntaxhighlight lang="xml"> <GameData> <Colors> <!-- Insert a new color --> <Row> <Type>COLOR_CUSTOM</T...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Inserting rows

XML

<GameData>
	<Colors>
            <!-- Insert a new color -->
            <Row>
                <Type>COLOR_CUSTOM</Type>
                <Red>0.1</Red>
                <Green>0.1</Green>
                <Blue>0.1</Blue>
                <Alpha>0.45</Alpha>
            </Row>	
	</Colors>
<GameData>

SQL

INSERT INTO Colors (Type, Red, Green, Blue, Alpha)
VALUES ('COLOR_CUSTOM', 0.1, 0.1, 0.1, 0.45);


Deleting rows

XML

<GameData>
	<Colors>
            <!-- Deletes all colors named COLOR_CUSTOM (there is only one actually) -->
            <Delete Type="COLOR_CUSTOM" />
            <!-- You can specify as many conditions as you want -->
            <Delete R="1" G="1"/>
	</Colors>
<GameData>

SQL

DELETE FROM Colors
WHERE Type = 'COLOR_CUSTOM' AND Red = 1;


Updating rows

XML

<GameData>
	<Colors>
            <!-- Changes the red channel for all colors named COLOR_CUSTOM (there is only one actually)
            <Update>
                <Where Type="COLOR_CUSTOM"/>
                <Set Red="1"/>
            </Update>
            <!-- You can specify as many conditions as you want and set as many properties as you want -->
            <Update>
                <Where Type="COLOR_CUSTOM" Red="0"/>
                <Set Red="1" Green="0"/>
            </Update>
            <!-- As always, formatting rules are relaxed, use what's the most convenient for you -->
            <Update>
                <Where>
                    <Type>COLOR_CUSTOM</Type>
                </Where>
                <Set>
                    <Red>1</Red>
                    <Green>1</Green>
                </Set>
            </Update>
        </Colors>
</GameData>


SQL

UPDATE Colors
SET Red = 1, Green = 0
WHERE Type = 'COLOR_CUSTOM' AND Red = 0;

New tables

XML

<GameData>
    <Table Name="MyColors">
	<Column name="ID" type="integer" primarykey="true" autoincrement="true"/>
	<Column name="Type" type="text" notnull="true" unique="true"/>
    </Table>
</GameData>

SQL

CREATE TABLE MyColors( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT UNIQUE );


New columns

SQL

ALTER TABLE Colors COLUMN 'Description' TEXT DEFAULT NULL;