pygcam.mcs.Database

API

This module includes contributions by Sam Fendell and Ryan Jones.

pygcam.mcs.Database.beforeSavingRun(_mapper, _connection, run)

Before inserting/updating a Run instance, set numerical status and timestamps according to the status string.

pygcam.mcs.Database.canonicalizeRegion(name)

Return the canonical name for a region, normalizing the use of capitalization and underscores.

Parameters:name – a GCAM region name
Returns:region name in canonical format, i.e., lowercase with underscores changed to spaces. (The use of underscores is inconsistent and thus hard to remember, e.g., ‘South America_Northern’)
pygcam.mcs.Database.getDatabase(checkInit=True)

Return the instantiated CoreDatabase, or created one and return it. The optional dbClass argument is provided to facilitate subclassing.

pygcam.mcs.Database.parseSqlScript(filename=None, text=None)

Parse a SQL script into semi-colon-terminated statements.

Parameters:
  • filename – (str) the path of the file of SQL statements
  • text – (str) optionally pass the contents of the file rather than the filename
Returns:

(list of str) the individual statements

pygcam.mcs.Database.sqlite_FK_pragma(dbapi_connection, connection_record)

Turn on foreign key support in sqlite

pygcam.mcs.Database.usingPostgres()

Return True if the DbURL indicates that we’re using Postgres, else return False

pygcam.mcs.Database.usingSqlite()

Return True if the DbURL indicates that we’re using Sqlite, else return False