Ejemplo n.º 1
0
    def get_one(self, where=None, vars=None, what='*', limit=None, order=None, group=None, offset=None):
	self._reconnection()
	if (isinstance(where, dict)):
	    where = sqlwhere(where)
	query = self.db.select(self._table_name, where=where, vars=vars, what=what, limit=1, order=order, group=group, offset=0);
	if query and len(query) > 0 :
	    return query.list().pop()
	else:
	    return None
Ejemplo n.º 2
0
 def count(self, where=None):
     if (isinstance(where, dict)):
         where = sqlwhere(where)
     if not where:
         where = None
 	query = self.get_one(where, what="COUNT(*) AS NUM");
 	if query:
 	    return query["NUM"];
 	else:
 	    return 0;
Ejemplo n.º 3
0
    def select(self, where=None, vars = None, what='*', limit = None, order = None, group = None, offset=None):
	self._reconnection()
	'''
	Selects `what` from `tables` with clauses `where`, `order`,
	`group`, `limit`, and `offset`. Uses vars to interpolate.
	Otherwise, each clause can be a SQLQuery.
	>>> db.select('foo', _test=True)
	<sql: 'SELECT * FROM foo'>
	>>> db.select(['foo', 'bar'], where="foo.bar_id = bar.id", limit=5, _test=True)
	<sql: 'SELECT * FROM foo, bar WHERE foo.bar_id = bar.id LIMIT 5'>
	'''
	if (isinstance(where, dict)):
	    where = sqlwhere(where)

	if not where:
	    where = None
	return self.db.select(self._table_name, where=where, vars=vars, what=what, limit=limit, order=order, group=group, offset=offset, _test=False)