CRUD with Python ... IndexError: tuple index out of range -



CRUD with Python ... IndexError: tuple index out of range -

i have couple of selects , update using python. totally new @ language, , having bit of problem syntax when doing next (simple) queries:

select a.customer_name, a.customer_city, b.population contracts bring together cities b on a.customer_city = b.ident b.population <=500000 select a.ident, a.make, a.model, a.luxury, b.car_ident cars bring together contracts b on a.ident = b.car_ident luxury = 'y' update contracts set base_price=1000 contract_class >=10

i starting update...i figured shorter code.... when update statement, next error:

>'update {} set base_price = ? {}'.format(self._table), (row['base_price'], >row['where'])) >indexerror: tuple index out of range

here's have methods

def retrieve(self, key): cursor = self._db.execute('select {}'.format(self._table)) homecoming dict(cursor.fetchone()) def update(self, row): self._db.execute( 'update {} set base_price = ? {}'.format(self._table), (row['base_price'], row['where'])) self._db.commit() def disp_rows(self): cursor = self._db.execute('select ident, contract_class, base_price {} order base_price'.format(self._table)) row in cursor: print(' {}: {}: {}'.format(row['ident'], row['contract_class'], row['base_price'])) def __iter__(self): cursor = self._db.execute('select * {} order base_price'.format(self._table)) row in cursor: yield dict(row) def main(): db_cities = database(filename = 'insurance.sqlite', table = 'cities') db= database(filename = 'insurance.sqlite', table = 'contracts') db_cars = database(filename = 'insurance.sqlite', table = 'cars') print('retrieve rows') row in db: print(row) print('update rows') db.update({'where': 'contract_class' >= 10', 'base_price'= 1000}) row in db: print(row) print('retrieve rows after update') row in db: print(row) in advance help!

you misplaced bracket after self._table.

class="lang-py prettyprint-override">'update {table_name} set base_price = {base_price} {condition}'.format( table_name=self._table, base_price=row['base_price'], condition=row['where'] )

i did little code cleanup.

another question: why aren't using orm?

python crud

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -