Example #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)
Example #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
         ]
Example #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)
Example #4
0
 def update_full(self):
     return birdsql._get_db().update_generic_full(self)
Example #5
0
 def update(self, what_list=None):
     return birdsql._get_db().update_generic(self, what_list)
Example #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)
Example #7
0
 def insert_or_update(self):
     return birdsql._get_db().insert_or_update_generic(self)
Example #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 ]
Example #9
0
 def _create_object(self, row, include_extras=False):
     return birdsql._get_db().get_generic(self, row, include_extras)
Example #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)
Example #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)
Example #12
0
 def delete(self):
     return birdsql._get_db().delete_generic(self)
Example #13
0
 def delete(self):
     return birdsql._get_db().delete_generic(self)
Example #14
0
 def update(self, what_list=None):
     return birdsql._get_db().update_generic(self, what_list)
Example #15
0
 def update_full(self):
     return birdsql._get_db().update_generic_full(self)
Example #16
0
 def insert_or_update(self):
     return birdsql._get_db().insert_or_update_generic(self)
Example #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)
Example #18
0
 def _create_object(self, row, include_extras=False):
     return birdsql._get_db().get_generic(self, row, include_extras)
Example #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)
Example #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)