def selectone(cls, *k, **kw): for (key, value) in kw.items(): if isinstance(value, DBTable): kw[key] = value._handle (where_exp, where_params) = dbsql.where(*k, **kw) if where_exp: where_exp = 'WHERE ' + where_exp sql = 'SELECT HANDLE handle FROM %s %s' % (cls._table, where_exp) row = cls._cursor.execute(sql, where_params).fetchone() new = cls.__new__(cls) new.__init__(row.handle) return new
def _where(self, columns): if not self.isset(): raise KeyNotSet() literals = self.sql_literals() where = [] for column, literal in zip(columns, literals): where.append(column) where.append("=") where.append(literal) where.append("AND") del where[-1] # remove the straneous AND return sql.where(*where)
def select(cls, *k, **kw): for (key, value) in kw.items(): if isinstance(value, DBTable): kw[key] = value._handle if len(k) == 1 and isinstance(k[0], basestring): (where_exp, where_params) = k[0], tuple() else: (where_exp, where_params) = dbsql.where(*k, **kw) if where_exp: where_exp = 'WHERE ' + where_exp sql = 'SELECT HANDLE handle FROM %s %s' % (cls._table, where_exp) cursor = cls._cursor.execute(sql, where_params) # row = cursor.fetchone() for row in cursor.fetchall(): new = cls.__new__(cls) new.__init__(row.handle) yield new