• We are currently performing site maintenance, parts of civfanatics are currently offline, but will come back online in the coming days. For more updates please see here.

Inserting multiple rows in SQL (happy update!)

Pazyryk

Deity
Joined
Jun 13, 2008
Messages
3,584
The latest patch updated to the newest SQLite version. This bit me in the behind on another issue, but here's some good news:
Spoiler :
insert-stmt.gif

What this means is that you can now do this:
Code:
INSERT INTO Unit_Flavors (UnitType, FlavorType, Flavor) VALUES
('UNIT_BIREMES',	'FLAVOR_NAVAL',		8	),
('UNIT_BIREMES',	'FLAVOR_NAVAL_RECON',	12	),
('UNIT_TRIREMES',	'FLAVOR_NAVAL',		24	),
('UNIT_TRIREMES',	'FLAVOR_NAVAL_RECON',	8	),
('UNIT_QUINQUEREMES',	'FLAVOR_NAVAL',		30	),
('UNIT_QUINQUEREMES',	'FLAVOR_NAVAL_RECON',	8	),
('UNIT_DROMONS',	'FLAVOR_NAVAL',		24	),
('UNIT_DROMONS',	'FLAVOR_NAVAL_RECON',	12	),
('UNIT_CARRACKS',	'FLAVOR_NAVAL',		30	),
('UNIT_CARRACKS',	'FLAVOR_NAVAL_RECON',	8	),
('UNIT_CARAVELS',	'FLAVOR_NAVAL',		4	),
('UNIT_CARAVELS',	'FLAVOR_NAVAL_RECON',	20	),
('UNIT_GALLEONS',	'FLAVOR_NAVAL',		36	),
('UNIT_GALLEONS',	'FLAVOR_NAVAL_RECON',	12	),
('UNIT_IRONCLADS',	'FLAVOR_NAVAL',		36	);
...which is a lot prettier than the SELECT UNION ALL construction.


There might be other nice improvements to find. It's the newest SQLite version now (SQLite Release 3.7.17 On 2013-05-20) if anyone wants to look. Not sure what previous version Civ5 was using but probably from 2010.
 
Yep, looks better, thanks for reporting that :)
 
Will this also work for altering a table with multiple columns?
 
Will this also work for altering a table with multiple columns?
Are you asking about an UPDATE? One UPDATE can affect many items depending on what you put in the WHERE clause. (IIRC there is a way to apply multiple criteria in one UPDATE with "CASE", but I don't know how.)
 
Are you asking about an UPDATE? One UPDATE can affect many items depending on what you put in the WHERE clause. (IIRC there is a way to apply multiple criteria in one UPDATE with "CASE", but I don't know how.)

No, I'm asking about inserting multiple columns into an existing table.

Right now I do that like:

Code:
ALTER TABLE Units ADD x integer DEFAULT 0;
ALTER TABLE Units ADD y boolean DEFAULT 0;
ALTER TABLE Units ADD z integer DEFAULT 0;

I'm wondering if there's a faster way to do that like:

Code:
ALTER TABLE Units ADD
(x integer DEFAULT 0),
(y boolean DEFAULT 0),
(z integer DEFAULT 0);
 
Thats good....but the only problem is that it is hard to distinguish a stray comma from semi-colon as opposed to a UNION ALL and a semi-colon. :crazyeye:

This happens a lot to me when I cut/paste and remove entries and forget to change the last line from a UNION ALL to a semi-colon!
 
Back
Top Bottom