Exemple #1
0
 def query_all(self,
               limit=None,
               order_by=None,
               include_extras=False,
               _log=False,
               **kwargs):
     #TODO: Does kwargs.keys() and kwargs.values() return items in the same order?
     where_clause = limit_clause = order_clause = ''
     values = []
     if kwargs is not None and len(kwargs.keys()) > 0:
         where_parts = []
         for key, value in kwargs.items():
             where_part, use_value = self.get_where_part(key, value)
             where_parts.append(where_part)
             if use_value:
                 values.append(value)
         where_clause = ' where ' + ' and '.join(where_parts)
     if limit is not None:
         limit_clause = ' limit {0} '.format(limit)
     if order_by is not None:
         order_clause = ' order by {0} '.format(
             order_by
         ) if not order_by.strip().startswith('order') else order_by
     query = 'select * from `{0}` {1} {2} {3} '.format(
         self._table_name, where_clause, order_clause, limit_clause)
     if _log:
         print query
         pprint(kwargs)
     rows = birdsql._get_db().fetch_all(query, tuple(values))
     if _log:
         print 'Total rows returned:', len(rows)
     return self._create_objects(rows, include_extras)
Exemple #2
0
 def _create_objects(self, rows, include_extras=False):
     if rows is None or len(rows) == 0:
         return None
     else:
         return [
             birdsql._get_db().get_generic(self.__class__(), row,
                                           include_extras) for row in rows
         ]
Exemple #3
0
 def query_all(self, limit=None, order_by=None, include_extras=False, _log=False, **kwargs):
     #TODO: Does kwargs.keys() and kwargs.values() return items in the same order?
     where_clause = limit_clause = order_clause = ''
     values = []
     if kwargs is not None and len(kwargs.keys()) > 0:
         where_parts = []
         for key, value in kwargs.items():
             where_part, use_value = self.get_where_part(key, value)
             where_parts.append(where_part)
             if use_value:
                 values.append(value)
         where_clause = ' where ' + ' and '.join(where_parts)
     if limit is not None:
         limit_clause = ' limit {0} '.format(limit)
     if order_by is not None:
         order_clause = ' order by {0} '.format(order_by) if not order_by.strip().startswith('order') else order_by
     query = 'select * from `{0}` {1} {2} {3} '.format(self._table_name, where_clause, order_clause, limit_clause)
     if _log:
         print query
         pprint(kwargs)
     rows = birdsql._get_db().fetch_all(query, tuple(values))
     if _log:
         print 'Total rows returned:', len(rows)
     return self._create_objects(rows, include_extras)
Exemple #4
0
 def update_full(self):
     return birdsql._get_db().update_generic_full(self)
Exemple #5
0
 def update(self, what_list=None):
     return birdsql._get_db().update_generic(self, what_list)
Exemple #6
0
 def insert(self, replace_into=False):
     """
     Insert this item into the database, optionally "REPLACE INTO"
     """
     return birdsql._get_db().insert_generic(self, replace_into=replace_into)
Exemple #7
0
 def insert_or_update(self):
     return birdsql._get_db().insert_or_update_generic(self)
Exemple #8
0
 def _create_objects(self, rows, include_extras=False):
     if rows is None or len(rows) == 0:
         return None
     else:
         return [ birdsql._get_db().get_generic(self.__class__(), row, include_extras) for row in rows ]
Exemple #9
0
 def _create_object(self, row, include_extras=False):
     return birdsql._get_db().get_generic(self, row, include_extras)
Exemple #10
0
 def raw_query_all(self, query, values, include_extras=False):
     rows = birdsql._get_db().fetch_all(query, values)
     return self._create_objects(rows, include_extras)
Exemple #11
0
 def raw_query_all(self, query, values, include_extras=False):
     rows = birdsql._get_db().fetch_all(query, values)
     return self._create_objects(rows, include_extras)
Exemple #12
0
 def delete(self):
     return birdsql._get_db().delete_generic(self)
Exemple #13
0
 def delete(self):
     return birdsql._get_db().delete_generic(self)
Exemple #14
0
 def update(self, what_list=None):
     return birdsql._get_db().update_generic(self, what_list)
Exemple #15
0
 def update_full(self):
     return birdsql._get_db().update_generic_full(self)
Exemple #16
0
 def insert_or_update(self):
     return birdsql._get_db().insert_or_update_generic(self)
Exemple #17
0
 def insert(self, replace_into=False):
     """
     Insert this item into the database, optionally "REPLACE INTO"
     """
     return birdsql._get_db().insert_generic(self,
                                             replace_into=replace_into)
Exemple #18
0
 def _create_object(self, row, include_extras=False):
     return birdsql._get_db().get_generic(self, row, include_extras)
Exemple #19
0
 def raw_query_one(self, query, values, include_extras=False):
     row = birdsql._get_db().fetch_one(query, values)
     return self._create_object(row, include_extras)
Exemple #20
0
 def raw_query_one(self, query, values, include_extras=False):
     row = birdsql._get_db().fetch_one(query, values)
     return self._create_object(row, include_extras)