def do_select(self, txn, sql):

        self.stats['sql_received'] = self.stats.get('sql_received', 0) + 1

        try: 
            retval = txn.execute(sql)

        except Exception as e:

            self.stats['sql_errors'] = self.stats.get('sql_errors', 0) + 1

            return { "retval": 1, "error_message" : str(e) }

        # Find the max column with for each column.

        max_widths = {}

        # Get the column names.

        column_names = []

        try:
            for column_index, column_name in enumerate(txn.getdescription()):

                if not max_widths.has_key(str(column_index)) or len(column_name[0]) < max_widths[str(column_index)]:
                    max_widths[str(column_index)] = len(column_name[0])
            
                column_names.append(column_name[0])

        except apsw.ExecutionCompleteError as e:
            # Ugh, getdescription fails if the query succeeds but returns no rows!  This is the message:
            #    "Can't get description for statements that have completed execution"

            # For now return a zero row empty table:

            data = { "column_names" : [ "query returned zero rows" ], "rows" : [ ] }

            return { "retval" : 0, "error_message" : '', "data" : data, "max_widths" : { "0" : 24 } }

        # Save the data here:

        saved_rows = []
        nr_rows = 0

        # For each row.

        # Under certain circustances (like 'select 1; abc') we'll get an exception in fetchall!
        try:
            for row in txn.fetchall():

                saved_row = []

                # For each column.

                for column_index, cell in enumerate(row):

                    # Convert all to strings and compute the length.

                    cell = unicode_safe_str(cell)

                    length = len(cell)

                    if not max_widths.has_key(str(column_index)) or max_widths[str(column_index)] < length:
                        max_widths[str(column_index)] = length

                    # Save the cell to the row for output later.

                    saved_row.append(cell)

                # Save the row to the rows for output later.

                saved_rows.append(saved_row)

        except ValueError as e:

            self.stats['sql_errors'] = self.stats.get('sql_errors', 0) + 1

            return { "retval": 1, "error_message" : str(e) }


        self.stats['sql_completed'] = self.stats.get('sql_completed', 0) + 1

        data = { "column_names" : column_names,
                 "rows" : saved_rows }

        return { "retval" : 0, "error_message" : '', "data" : data, "max_widths" : max_widths }
dataset/ETHPy150Open MediaMath/qasino/lib/sqlite_backend.py/SqlConnections.do_select/swapped operands of `<`