Exemple #1
0
 def rows(self):
   curz  = db.cursor()
   qry   = 'SELECT %s FROM %s' % (', '.join([x[0] for x in self.cols]), self.tablename)
   curz.execute(qry)
   rs  = curz.fetchall()
   curz.close()
   db.commit()
   return rs
 def create_in_db(self, repc):
   try:
     tbl, cols = stuff = self.creation_sql(repc)
     if self.created: return stuff
     curz  = db.cursor()
     curz.execute('SELECT TRUE FROM information_schema.tables WHERE table_name = %s', (tbl,))
     if not curz.fetchone():
       curz.execute('CREATE TABLE %s (indexcol SERIAL NOT NULL);' % (tbl,))
       curz.close()
       return self.create_in_db(repc)
     for col in cols:
       curz.execute('SELECT TRUE FROM information_schema.columns WHERE table_name = %s AND column_name = %s', (tbl, col[0]))
       if not curz.fetchone():
         curz.execute('ALTER TABLE %s ADD COLUMN %s %s;' % (tbl, col[0], col[1]))
     curz.close()
     db.commit()
     self.created  = True
     return stuff
   except Exception, e:
     raise Exception, ('Table creation: ' + str(e))