1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

IF statements and SQL mods

Discussion in 'Civ5 - Creation & Customization' started by es4, Oct 16, 2010.

  1. es4

    es4 Chieftain

    Joined:
    Aug 11, 2009
    Messages:
    73
    So I'm trying to add some tech-based bonuses to some improvements using SQL (which is much better than XML):

    That's working fine. However, if a different mod is already adding something like this, I wouldn't want my mod to do it as well. So, what I want to surround this statement with is something like:

    IF (DB.Query(SELECT COUNT(*) FROM Improvements_TechYieldChanges) < 2) THEN
    ...
    ENDIF


    However, I can't get that (or anything else I've tried) working. There's no real standard I can find for SQL IF statements, and none of the combinations I am trying work.

    Does anyone know how this works?
     
  2. Grumalg

    Grumalg Chieftain

    Joined:
    Sep 17, 2010
    Messages:
    17
    Location:
    OR, USA
    The base core of ANSI SQL does not include any 'Procedural' extensions. Many database engines do support such things, but SQLite doesn't. Nor does it support all of the basic ANSI SQL structure.

    It supports executing a sequence of semicolon seperated SQL statements, but not any conditional execution of some of them.

    You can find the full documentation here:
    http://www.sqlite.org/docs.html

    But the below parts will probably be the most useful to you...
    http://www.sqlite.org/lang.html
    http://www.sqlite.org/lang_corefunc.html
    http://www.sqlite.org/lang_aggfunc.html

    SQLite is a fairly strange beast. It supports declaring a field as a specific datatype such as integer, but it will cheerfully accept and write a string in an integer field and return the string back. They call this a 'Feature'... The docs say:

    That can cause unpleasant issues if you read an 'integer' field into a integer variable and someone stuck a string there...
     
  3. es4

    es4 Chieftain

    Joined:
    Aug 11, 2009
    Messages:
    73
    So this is pure SQLite? I know that Kael's modding doc says to use the SQLite extension to read the DB files, but the FOR statement used there doesn't seem to be in SQLite, so I was hoping it was a variant with some conditional logic.
     
  4. Gedrin

    Gedrin Chieftain

    Joined:
    Mar 27, 2008
    Messages:
    52
    Google insert where not exists. Never used it myself and no time to try it. Heading out... But that may help you.
     

Share This Page