예제 #1
0
    def sql_complete_callback_for_text(self, result, query_id, query_start, request):
        """
        Called when a sql statement completes.
        """

        retval        = result["retval"]
        data          = result["data"]          if "data"          in result else None
        error_message = result["error_message"] if "error_message" in result else ''
        max_widths    = result["max_widths"]    if "max_widths"    in result else None

        if retval == 0 and data != None:

            # I'm sure there is a better way but I'm just not thinking straight right now..
            class Outputter(object):
                @staticmethod
                def sendLine(text):
                    request.write(text + "\n")

            outputter = Outputter()

            util.pretty_print_table(outputter, data, max_widths=max_widths)

        if retval != 0:
            logging.info("HttpReceiver: (%d) SQL error: %s", query_id, error_message)
            request.write("SQL error: %s" % error_message)
        else:
            logging.info("HttpReceiver: (%d) SQL completed (%.02f seconds)", query_id, time.time() - query_start)

        request.finish()
예제 #2
0
    def sql_complete_callback(self, result, query_id, query_start):
        """
        Called when a sql statement completes.
        """

        retval = result["retval"]
        data = result["data"] if "data" in result else None
        error_message = result[
            "error_message"] if "error_message" in result else ''
        max_widths = result["max_widths"] if "max_widths" in result else None

        if retval == 0 and data != None:
            util.pretty_print_table(self, data, max_widths=max_widths)

        if retval != 0:
            logging.info("SqlReceiver: (%d:%d) SQL error: %s",
                         self.connection_id, query_id, error_message)
            self.sendLine("SQL error: %s" % error_message)
        else:
            logging.info("SqlReceiver: (%d:%d) SQL completed (%.02f seconds)",
                         self.connection_id, query_id,
                         time.time() - query_start)

        self.nr_queries += 1
        self.factory.nr_queries += 1
        self.sql_statement = ''
예제 #3
0
    def sql_complete_callback_for_text(self, result, query_id, query_start,
                                       request):
        """
        Called when a sql statement completes.
        """

        retval = result["retval"]
        data = result["data"] if "data" in result else None
        error_message = result[
            "error_message"] if "error_message" in result else ''
        max_widths = result["max_widths"] if "max_widths" in result else None

        if retval == 0 and data != None:

            # I'm sure there is a better way but I'm just not thinking straight right now..
            class Outputter(object):
                @staticmethod
                def sendLine(text):
                    request.write(text + "\n")

            outputter = Outputter()

            util.pretty_print_table(outputter, data, max_widths=max_widths)

        if retval != 0:
            logging.info("HttpReceiver: (%d) SQL error: %s", query_id,
                         error_message)
            request.write("SQL error: %s" % error_message)
        else:
            logging.info("HttpReceiver: (%d) SQL completed (%.02f seconds)",
                         query_id,
                         time.time() - query_start)

        request.finish()
예제 #4
0
    def sql_complete_callback(self, result, query_id, query_start):
        """
        Called when a sql statement completes.
        """

        retval = result["retval"]
        data          = result["data"]          if "data"          in result else None
        error_message = result["error_message"] if "error_message" in result else ''
        max_widths    = result["max_widths"]    if "max_widths"    in result else None

        if retval == 0 and data != None:
            util.pretty_print_table(self, data, max_widths=max_widths)

        if retval != 0:
            logging.info("SqlReceiver: (%d:%d) SQL error: %s", self.connection_id, query_id, error_message)
            self.sendLine("SQL error: %s" % error_message)
        else:
            logging.info("SqlReceiver: (%d:%d) SQL completed (%.02f seconds)", self.connection_id, query_id, time.time() - query_start)

        self.nr_queries += 1
        self.factory.nr_queries += 1
        self.sql_statement = ''
예제 #5
0
    def send_query(self, sql_statement, use_write_db=False):

        request_meta = {
            "op": "query",
            "sql": sql_statement,
            "use_write_db": use_write_db
        }

        response = self.conn.send_and_get_response(json.dumps(request_meta))
        if response == None:
            print "ERROR: error communicating with server"
            return

        try:
            obj = json.loads(response)
        except Exception as e:
            print "ERROR: unable to parse response from server: %s: %s" % (
                response, str(e))
            return

        if obj == None or "response_op" not in obj:
            print "ERROR: invalid response from server: ", obj

        elif obj["response_op"] == "error":
            if "error_message" in obj:
                print "ERROR: %s" % str(obj["error_message"])
            else:
                print "ERROR: Unknown error from server."

        elif obj["response_op"] == "result_table":

            max_widths = obj["max_widths"] if "max_widths" in obj else None

            util.pretty_print_table(self, obj["table"], max_widths=max_widths)
            #print "Got response: ", obj

        else:
            print "ERROR: Unknown op response from server."