Beispiel #1
0
    def validate_and_route_query(self, txn, sql, query_id, sql_backend):

        m = re.search(r"^\s*select\s+", sql, flags=re.IGNORECASE)
        if m == None:

            # Process a non-select statement.

            return self.process_non_select(txn, sql, query_id, sql_backend)

        # Process a select statement.

        return sql_backend.do_select(txn, sql)
Beispiel #2
0
    def validate_and_route_query(self, txn, sql, query_id, sql_backend):

        m = re.search(r"^\s*select\s+", sql, flags=re.IGNORECASE)
        if m == None:

            # Process a non-select statement.

            return self.process_non_select(txn, sql, query_id, sql_backend)

        # Process a select statement.

        return sql_backend.do_select(txn, sql)
Beispiel #3
0
    def validate_and_route_query(self, txn, sql, query_id, sql_backend):

        # So when dbs rotate we'll force a shutdown of the backend
        # after a certain amount of time to avoid hung or long running
        # things in this code path from holding dbs open.  This
        # may/will invalidate references we might have in here so wrap
        # it all in a try catch...
        try:
            m = re.search(r"^\s*select\s+", sql, flags=re.IGNORECASE)
            if m == None:

                # Process a non-select statement.

                return self.process_non_select(txn, sql, query_id, sql_backend)

            # Process a select statement.

            return sql_backend.do_select(txn, sql)

        except Exception as e:

            msg = "Exception in validate_and_route_query: {}".format(str(e))
            logging.info(msg)
            return {"retval": 0, "error_message": msg}
Beispiel #4
0
    def validate_and_route_query(self, txn, sql, query_id, sql_backend):

        # So when dbs rotate we'll force a shutdown of the backend
        # after a certain amount of time to avoid hung or long running
        # things in this code path from holding dbs open.  This
        # may/will invalidate references we might have in here so wrap
        # it all in a try catch...
        try:
            m = re.search(r"^\s*select\s+", sql, flags=re.IGNORECASE)
            if m == None:

                # Process a non-select statement.

                return self.process_non_select(txn, sql, query_id, sql_backend)

            # Process a select statement.

            return sql_backend.do_select(txn, sql)

        except Exception as e:
            
            msg = "Exception in validate_and_route_query: {}".format(str(e))
            logging.info(msg)
            return { "retval" : 0, "error_message" : msg }
Beispiel #5
0
    def process_non_select(self, txn, sql, query_id, sql_backend):
        """
        Called for non-select statements like show tables and desc.
        """

        # DESC?

        m = re.search(r"^\s*desc\s+(\S+)\s*;$", sql, flags=re.IGNORECASE)

        if m != None:
            (retval, error_message,
             table) = sql_backend.do_desc(txn, m.group(1))

            result = {"retval": retval}
            if error_message:
                result["error_message"] = error_message
            if table:
                result["data"] = table

            return result

        # DESC VIEW?

        m = re.search(r"^\s*desc\s+view\s+(\S+)\s*;$",
                      sql,
                      flags=re.IGNORECASE)
        if m != None:
            return sql_backend.do_select(
                txn,
                "SELECT view FROM qasino_server_views WHERE viewname = '%s';" %
                m.group(1))

        # SHOW tables?

        m = re.search(r"^\s*show\s+tables\s*;$", sql, flags=re.IGNORECASE)
        if m != None:
            return sql_backend.do_select(
                txn,
                "SELECT *, strftime('%Y-%m-%d %H:%M:%f UTC', last_update_epoch, 'unixepoch') last_update_datetime FROM qasino_server_tables ORDER BY tablename;"
            )

        # SHOW tables with LIKE?

        m = re.search(r"^\s*show\s+tables\s+like\s+('\S+')\s*;$",
                      sql,
                      flags=re.IGNORECASE)
        if m != None:
            return sql_backend.do_select(
                txn,
                "SELECT *, strftime('%Y-%m-%d %H:%M:%f UTC', last_update_epoch, 'unixepoch') last_update_datetime FROM qasino_server_tables WHERE tablename LIKE {} ORDER BY tablename;"
                .format(m.group(1)))

        # SHOW connections?

        m = re.search(r"^\s*show\s+connections\s*;$", sql, flags=re.IGNORECASE)
        if m != None:
            return sql_backend.do_select(
                txn,
                "SELECT *, strftime('%Y-%m-%d %H:%M:%f UTC', last_update_epoch, 'unixepoch') last_update_datetime FROM qasino_server_connections ORDER BY identity;"
            )

        # SHOW info?

        m = re.search(r"^\s*show\s+info\s*;$", sql, flags=re.IGNORECASE)
        if m != None:
            return sql_backend.do_select(
                txn,
                "SELECT *, strftime('%Y-%m-%d %H:%M:%f UTC', generation_start_epoch, 'unixepoch') generation_start_datetime FROM qasino_server_info;"
            )

        # SHOW views?

        m = re.search(r"^\s*show\s+views\s*;$", sql, flags=re.IGNORECASE)
        if m != None:
            return sql_backend.do_select(
                txn,
                "SELECT viewname, loaded, errormsg FROM qasino_server_views ORDER BY viewname;"
            )

        # Exit?

        m = re.search(r"^\s*(quit|logout|exit)\s*;$", sql, flags=re.IGNORECASE)
        if m != None:
            return {"retval": 0, "error_message": "Bye!"}

        return {
            "retval": 1,
            "error_message": "ERROR: Unrecognized statement: %s" % sql
        }
Beispiel #6
0
    def process_non_select(self, txn, sql, query_id, sql_backend):
        """
        Called for non-select statements like show tables and desc.
        """

        # DESC?

        m = re.search(r"^\s*desc\s+(\S+)\s*;$", sql, flags=re.IGNORECASE)

        if m != None:
            (retval, error_message, table) = sql_backend.do_desc(txn, m.group(1))

            result = { "retval" : retval }
            if error_message:
                result["error_message"] = error_message
            if table:
                result["data"] = table

            return result

        # DESC VIEW?

        m = re.search(r"^\s*desc\s+view\s+(\S+)\s*;$", sql, flags=re.IGNORECASE)
        if m != None:
            return sql_backend.do_select(txn, "SELECT view FROM qasino_server_views WHERE viewname = '%s';" % m.group(1))
            
        # SHOW tables?

        m = re.search(r"^\s*show\s+tables\s*;$", sql, flags=re.IGNORECASE)
        if m != None:
            return sql_backend.do_select(txn, "SELECT *, strftime('%Y-%m-%d %H:%M:%f UTC', last_update_epoch, 'unixepoch') last_update_datetime FROM qasino_server_tables ORDER BY tablename;")

        # SHOW tables with LIKE?

        m = re.search(r"^\s*show\s+tables\s+like\s+('\S+')\s*;$", sql, flags=re.IGNORECASE)
        if m != None:
            return sql_backend.do_select(txn, "SELECT *, strftime('%Y-%m-%d %H:%M:%f UTC', last_update_epoch, 'unixepoch') last_update_datetime FROM qasino_server_tables WHERE tablename LIKE {} ORDER BY tablename;".format(m.group(1)) )

        # SHOW connections?

        m = re.search(r"^\s*show\s+connections\s*;$", sql, flags=re.IGNORECASE)
        if m != None:
            return sql_backend.do_select(txn, "SELECT *, strftime('%Y-%m-%d %H:%M:%f UTC', last_update_epoch, 'unixepoch') last_update_datetime FROM qasino_server_connections ORDER BY identity;")

        # SHOW info?

        m = re.search(r"^\s*show\s+info\s*;$", sql, flags=re.IGNORECASE)
        if m != None:
            return sql_backend.do_select(txn, "SELECT *, strftime('%Y-%m-%d %H:%M:%f UTC', generation_start_epoch, 'unixepoch') generation_start_datetime FROM qasino_server_info;")

        # SHOW views?

        m = re.search(r"^\s*show\s+views\s*;$", sql, flags=re.IGNORECASE)
        if m != None:
            return sql_backend.do_select(txn, "SELECT viewname, loaded, errormsg FROM qasino_server_views ORDER BY viewname;")

        # Exit?

        m = re.search(r"^\s*(quit|logout|exit)\s*;$", sql, flags=re.IGNORECASE)
        if m != None:
            return { "retval" : 0, "error_message" : "Bye!" }


        return { "retval" : 1, "error_message" : "ERROR: Unrecognized statement: %s" % sql }