def get_data(self, sort_column=None, sort_descending=False): """Gets a cursor of the data associated with this group""" sort_string = get_sort_string(sort_column, sort_descending) sql = "SELECT * FROM %s %s" % (self.view_name, sort_string) cursor = connection.cursor() cursor.execute(sql) return cursor
def _get_cursor(self, column_filters=[], sort_column="id", sort_descending=True): """Gets a cursor associated with a query against this table. See get_rows for documentation of the parameters.""" # Note that the data view is dependent on id being first if not self.parent: sql = ( " SELECT su.id as submission_id, su.submit_time, s.* FROM %s s " % self.table_name + " JOIN xformmanager_metadata m ON m.raw_data=s.id " + " JOIN receiver_attachment a ON m.attachment_id=a.id " + " JOIN receiver_submission su ON a.submission_id=su.id " + " WHERE m.formdefmodel_id=%s " % self.form.pk ) else: sql = "SELECT * from %s" % self.table_name # add filtering if column_filters: for filter in column_filters: if len(filter) != 3: raise TypeError( "_get_cursor expects column_filters of length 3 " + "e.g.['pk','=','3'] (only %s given)" % len(filter) ) if isinstance(filter[2], basestring): # strings need to be quoted if filter[0] == "submit_time": to_append = " AND su.%s %s '%s' " % tuple(filter) else: to_append = " AND s.%s %s '%s' " % tuple(filter) else: # force non-strings to strings filter[2] = unicode(filter[2]) to_append = " AND s.%s %s %s " % tuple(filter) sql = sql + to_append sql = sql + get_sort_string(sort_column, sort_descending) cursor = connection.cursor() cursor.execute(sql) return cursor