diff options
| author | Georgios Andreadis <G.Andreadis@student.tudelft.nl> | 2017-08-10 09:40:26 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-08-10 09:40:26 +0300 |
| commit | bc70e6ae115beb469541c12014ffdecc01a1e50c (patch) | |
| tree | 935c2ef5b1621b0e13ec76f2ca02f6912940d690 /opendc/models/model.py | |
| parent | 5d42f30ed30aa5b6970304569c6bd01c16078759 (diff) | |
| parent | 54617bf3268c27d63a40844216760a49f28d39e0 (diff) | |
Merge pull request #9 from atlarge-research/mariadb
Migration to MariaDB
Diffstat (limited to 'opendc/models/model.py')
| -rw-r--r-- | opendc/models/model.py | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/opendc/models/model.py b/opendc/models/model.py index e8a14e76..2507a287 100644 --- a/opendc/models/model.py +++ b/opendc/models/model.py @@ -109,20 +109,20 @@ class Model(object): def _generate_insert_placeholders_string(cls): """Generate a SQLite insertion placeholders string for this Model.""" - return ', '.join(['?'] * len(cls.COLUMNS)) + return ', '.join(['%s'] * len(cls.COLUMNS)) @classmethod def _generate_primary_key_string(cls): """Generate the SQLite primary key string for this Model.""" - return ' AND '.join(['{} = ?'.format(x) for x in cls.COLUMNS_PRIMARY_KEY]) + return ' AND '.join(['{} = %s'.format(x) for x in cls.COLUMNS_PRIMARY_KEY]) @classmethod def _generate_update_columns_string(cls): """Generate a SQLite updatable columns string for this Model.""" return ', '.join( - ['{} = ?'.format(x) for x in cls.COLUMNS if not x in cls.COLUMNS_PRIMARY_KEY] + ['{} = %s'.format(x) for x in cls.COLUMNS if not x in cls.COLUMNS_PRIMARY_KEY] ) # SQL TUPLE GENERATION METHODS @@ -207,7 +207,7 @@ class Model(object): """Return all instances of the Model in the database where column_name = value.""" if column_name is not None and value is not None: - statement = 'SELECT * FROM {} WHERE {} = ?'.format(cls.TABLE_NAME, column_name) + statement = 'SELECT * FROM {} WHERE {} = %s'.format(cls.TABLE_NAME, column_name) database_models = database.fetchall(statement, (value,)) else: @@ -264,7 +264,7 @@ class Model(object): else: query = query.format( self.TABLE_NAME, - '{} = ?'.format(column) + '{} = %s'.format(column) ) values = (getattr(self, column),) @@ -292,6 +292,7 @@ class Model(object): try: last_row_id = database.execute(statement, values) except Exception as e: + print e raise exceptions.ForeignKeyError(e.message) if 'id' in self.COLUMNS_PRIMARY_KEY: |
