XML-SQL Cheat Sheet (Civ5): Difference between revisions

From Civilization Modding Wiki
Jump to navigationJump to search
(Created page with "== Inserting rows == === XML === <syntaxhighlight lang="xml"> <GameData> <Colors> <!-- Insert a new color --> <Row> <Type>COLOR_CUSTOM</T...")
 
mNo edit summary
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Inserting rows ==
''This page is a part of the [[Civ5 XML Reference]].''
 
= Things to remember =
* '''Booleans:''' SQLite does not have booleans, it uses integers. So do not use <code>true</code> or <code>false</code>, use <code>1</code> and <code>0</code>.
 
 
= Inserting rows =
=== XML ===
=== XML ===
<syntaxhighlight lang="xml">
<div class="civ5-example"><syntaxhighlight lang="xml" style="left:40px;">
<GameData>
<GameData>
<Colors>
<Colors>
             <!-- Insert a new color -->
             <!-- Inserts a new color -->
             <Row>
             <Row>
                 <Type>COLOR_CUSTOM</Type>
                 <Type>COLOR_CUSTOM</Type>
Line 14: Line 20:
</Colors>
</Colors>
<GameData>
<GameData>
</syntaxhighlight>
</syntaxhighlight></div>


=== SQL ===
=== SQL ===
<syntaxhighlight lang="sql">
<div class="civ5-example"><syntaxhighlight lang="sql">
/* Inserts a new color */
INSERT INTO Colors (Type, Red, Green, Blue, Alpha)
INSERT INTO Colors (Type, Red, Green, Blue, Alpha)
VALUES ('COLOR_CUSTOM', 0.1, 0.1, 0.1, 0.45);
VALUES ('COLOR_CUSTOM', 0.1, 0.1, 0.1, 0.45);
</syntaxhighlight>
</syntaxhighlight></div>




== Deleting rows ==
= Deleting rows =
{{Warning}} See [http://forums.civfanatics.com/showthread.php?t=463429 Deleting data and issues, and how to avoid them] if you plan to delete rows and are not aware of the troubles that may arise.
=== XML ===
=== XML ===
<syntaxhighlight lang="xml">
<div class="civ5-example"><syntaxhighlight lang="xml">
<GameData>
<GameData>
<Colors>
<Colors>
Line 34: Line 42:
</Colors>
</Colors>
<GameData>
<GameData>
</syntaxhighlight>
</syntaxhighlight></div>


=== SQL ===
=== SQL ===
<syntaxhighlight lang="sql">
<div class="civ5-example"><syntaxhighlight lang="sql">
/* Deletes all colors named TYPE_CUSTOM whose red channel is equal to 1 */
DELETE FROM Colors
DELETE FROM Colors
WHERE Type = 'COLOR_CUSTOM' AND Red = 1;
WHERE Type = 'COLOR_CUSTOM' AND Red = 1;
</syntaxhighlight>
</syntaxhighlight></div>




== Updating rows ==
= Updating rows =
=== XML ===
=== XML ===
<syntaxhighlight lang="xml">
<div class="civ5-example"><syntaxhighlight lang="xml">
<GameData>
<GameData>
<Colors>
<Colors>
Line 70: Line 79:
         </Colors>
         </Colors>
</GameData>
</GameData>
</syntaxhighlight>
</syntaxhighlight></div>
 


=== SQL ===
=== SQL ===
<syntaxhighlight lang="sql">
<div class="civ5-example"><syntaxhighlight lang="sql">
/* Update all colors whose names are COLOR_CUSTOM and red channel is 0 */
UPDATE Colors
UPDATE Colors
SET Red = 1, Green = 0
SET Red = 1, Green = 0
WHERE Type = 'COLOR_CUSTOM' AND Red = 0;
WHERE Type = 'COLOR_CUSTOM' AND Red = 0;
</syntaxhighlight>


== New tables ==
/* Makes everything brighter */
UPDATE Colors
SET Red = Red + 0.1, Green = Green + 0.1, Blue=Blue + 0.1;
</syntaxhighlight></div>
 
 
= New tables =
=== XML ===
=== XML ===
<syntaxhighlight lang="xml">
<div class="civ5-example"><syntaxhighlight lang="xml">
<GameData>
<GameData>
     <Table Name="MyColors">
     <Table Name="MyColors">
Line 89: Line 103:
     </Table>
     </Table>
</GameData>
</GameData>
</syntaxhighlight>
</syntaxhighlight></div>


=== SQL ===
=== SQL ===
<syntaxhighlight lang="sql">
<div class="civ5-example"><syntaxhighlight lang="sql">
/* Create one new table with two columns */
CREATE TABLE MyColors( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT UNIQUE );
CREATE TABLE MyColors( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT UNIQUE );
</syntaxhighlight>
</syntaxhighlight></div>




== New columns ==
= New columns =
=== SQL ===
=== SQL ===
<syntaxhighlight lang="sql">
<div class="civ5-example"><syntaxhighlight lang="sql">
/* Adds one Description column to Colors. */
ALTER TABLE Colors COLUMN 'Description' TEXT DEFAULT NULL;
ALTER TABLE Colors COLUMN 'Description' TEXT DEFAULT NULL;
</syntaxhighlight>
</syntaxhighlight></div>
 
 
[[Category:Civ5 XML Files]]
[[Category:Civ5 Tutorials]]

Latest revision as of 12:09, 25 September 2012

This page is a part of the Civ5 XML Reference.

Things to remember

  • Booleans: SQLite does not have booleans, it uses integers. So do not use true or false, use 1 and 0.


Inserting rows

XML

<GameData>
	<Colors>
            <!-- Inserts 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

/* Inserts a new color */
INSERT INTO Colors (Type, Red, Green, Blue, Alpha)
VALUES ('COLOR_CUSTOM', 0.1, 0.1, 0.1, 0.45);


Deleting rows

Radioactive.png See Deleting data and issues, and how to avoid them if you plan to delete rows and are not aware of the troubles that may arise.

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

/* Deletes all colors named TYPE_CUSTOM whose red channel is equal to 1 */
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 all colors whose names are COLOR_CUSTOM and red channel is 0 */
UPDATE Colors
SET Red = 1, Green = 0
WHERE Type = 'COLOR_CUSTOM' AND Red = 0;

/* Makes everything brighter */
UPDATE Colors
SET Red = Red + 0.1, Green = Green + 0.1, Blue=Blue + 0.1;


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 one new table with two columns */
CREATE TABLE MyColors( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT UNIQUE );


New columns

SQL

/* Adds one Description column to Colors. */
ALTER TABLE Colors COLUMN 'Description' TEXT DEFAULT NULL;