Beispiel #1
0
 def load_schema(self, cur):
     self.check_tablename()
     q = "select 1 from information_schema.tables where table_name = %s"
     cur.execute(q, (self.table_name,))
     if not cur.fetchone():
         self.create_table(cur)
     q = "select column_name, column_default, character_maximum_length from INFORMATION_SCHEMA.COLUMNS where table_name=%s"
     cur.execute(q, (self.table_name,))
     cols = cur.fetchall()
     schema = {}
     for name, column_default, max_len in cols:
         schema[name] = odict(name=name, max_len=max_len)
         if name == 'id' and column_default == "nextval('%s_id_seq'::regclass)" % self.table_name:
             self.auto_id = True
     self.schema = schema
Beispiel #2
0
 def fetch_one_by(self, *args, **kw):
     try:
         super(UIPref, self).fetch_one_by(*args, **kw)
     except IndexError, err:
         return odict(self.defaults)