Пример #1
0
 def display(self, data, currentDB):
     dim = self.screen.getmaxyx()
     self.screen.clear()
     self.screen.keypad(1)
     k = 0
     selector = 0
     while selector != ord('\n'):
         j = 0
         i = 0
         for i in range(len(data[1])):
             if i + j + len(data[1][i][0]) // dim[1] + 1 > dim[0]:
                 i = i - 1
                 break
             if k == i:
                 self.screen.addstr(i + j, 0, data[1][i][0],
                                    curses.A_STANDOUT)
             else:
                 self.screen.addstr(i + j, 0, data[1][i][0], curses.A_DIM)
             if dim[1] < len(data[1][i][0]):
                 j += len(data[1][i][0]) // dim[1]
         if not data[1]:
             error.throw(self.screen, "No queries available.")
             self.screen.clear()
             return
         self.screen.refresh()
         selector = self.screen.getch()
         self.screen.clear()
         if selector == curses.KEY_UP:
             if k > 0:
                 k = k - 1
         if selector == curses.KEY_DOWN:
             if k < i:
                 k = k + 1
     queryDB.run(self, data[1][k][0], currentDB)
Пример #2
0
 def display(self, data, currentDB):
     dim = self.screen.getmaxyx()
     self.screen.clear()
     self.screen.keypad(1)
     k = 0
     selector = 0
     while selector != ord('\n'):
         j = 0
         i = 0
         for i in range(len(data[1])):
             if i + j + len(data[1][i][0])//dim[1] + 1 > dim[0]:
                 i = i - 1
                 break
             if k == i:
                 self.screen.addstr(i + j, 0, data[1][i][0], curses.A_STANDOUT)
             else:
                 self.screen.addstr(i + j, 0, data[1][i][0], curses.A_DIM)
             if dim[1] < len(data[1][i][0]):
                 j += len(data[1][i][0])//dim[1]
         if not data[1]:
             error.throw(self.screen, "No queries available.")
             self.screen.clear()
             return
         self.screen.refresh()
         selector = self.screen.getch()
         self.screen.clear()
         if selector == curses.KEY_UP:
             if k > 0:
                 k = k - 1
         if selector == curses.KEY_DOWN:
             if k < i:
                 k = k + 1
     queryDB.run(self, data[1][k][0], currentDB)
Пример #3
0
 def run(self, string, currentDB):
     result = query.query(string, currentDB, self.screen)
     if result == -1:
         error.throw(self.screen, "The query did not succeed.")
         self.screen.clear()
     elif result == 0:
         error.throw(self.screen, "The query was succesful.")
         self.screen.clear()
         q = "INSERT INTO queries_history (query) VALUES (%s)"
         query.query(q, 'queries', None, None, string)
     else:
         self.screen.clear()
         tableDisplay.navigate(result, 0, 0, self.screen)
         self.screen.clear()
         q = "INSERT INTO queries_history (query) VALUES (%s)"
         query.query(q, 'queries', None, None, string)
Пример #4
0
 def run(self, string, currentDB):
     result = query.query(string, currentDB, self.screen)
     if result == -1:
         error.throw(self.screen, "The query did not succeed.")
         self.screen.clear()
     elif result == 0:
         error.throw(self.screen, "The query was succesful.")
         self.screen.clear()
         q = "INSERT INTO queries_history (query) VALUES (%s)"
         query.query(q, 'queries', None, None, string)
     else:
         self.screen.clear()
         tableDisplay.navigate(result, 0, 0, self.screen)
         self.screen.clear()
         q = "INSERT INTO queries_history (query) VALUES (%s)"
         query.query(q, 'queries', None, None, string)
Пример #5
0
 def list_sql_files(self, dbname):
     top = os.getcwd()
     dir = os.listdir(top)
     parsed_file = []
     count = 0
     for f in dir:
         if fnmatch.fnmatch(f, '*.sql'):
             myOpt = {'dbname':dbname,'file':str(f)}
             lst = (str(f), self.import_sql, myOpt)
             parsed_file.append(tuple(lst))
             count = 1
     if count == 1:
         headeropts = {'db':dbname, 'title':"Select file to import", 'user':self.username}
         sqlfiles = Menu(parsed_file, self.screen, headeropts)
         sqlfiles.display()
     else:
         error.throw(self.screen, "No .sql files")
Пример #6
0
 def list_sql_files(self, dbname):
     top = os.getcwd()
     dir = os.listdir(top)
     parsed_file = []
     count = 0
     for f in dir:
         if fnmatch.fnmatch(f, '*.sql'):
             myOpt = {'dbname': dbname, 'file': str(f)}
             lst = (str(f), self.import_sql, myOpt)
             parsed_file.append(tuple(lst))
             count = 1
     if count == 1:
         headeropts = {
             'db': dbname,
             'title': "Select file to import",
             'user': self.username
         }
         sqlfiles = Menu(parsed_file, self.screen, headeropts)
         sqlfiles.display()
     else:
         error.throw(self.screen, "No .sql files")
Пример #7
0
    def fetch(query, db, screen = None, ISO_level = None, multi_part = None, username = None, password = None):
        if username is None:
            try:
                string = "dbname=\'" + db + "\' user='******' password='******'"
                conn = psycopg2.connect(string)
            except:
                if screen is not None:
                    error.throw(screen, "Error to connecting to \'" + db + "\' database.")
                    return -1
                else:
                    return -1
        else:
            try:
                string = "dbname=\'" + db + "\' user=\'" + username + "\' password=\'" + password + "\'"
                conn = psycopg2.connect(string)
            except:
                if screen is not None:
                    error.throw(screen, "Error to connecting to \'" + db + "\' database.")
                    return -2
                else:
                    return -2

        if ISO_level is not None:
            try:
                conn.set_isolation_level(ISO_level)
            except:
                if screen is not None:
                    error.throw(screen, "Error setting Isolation Level.")
                    return -1
                else:
                    return -1

        try:
            cur = conn.cursor()
        except:
            if screen is not None:
                error.throw(screen, "Error creating cursor.")
                return -1
            else:
                return -1
        
        if ISO_level is not 0 or None:
            try:
                if multi_part is None:
                    cur.execute(query)
                else:
                    cur.execute(query, (multi_part,))
            except:
                if screen is not None:
                    error.throw(screen, "Error executing query.")
                    return -1
                else:
                    return -1

        try:
            cols = [desc[0] for desc in cur.description]
            rows = cur.fetchall()
        except:
            if screen is not None:
                error.throw(screen, "Error executing fetch.")
                return -1
            else:
                return -1

        try:
            cur.close()
        except:
            if screen is not None:
                error.throw(screen, "Error closing cursor.")
                return -1
            else:
                return -1

        try:
            conn.close()
        except:
            if screen is not None:
                error.throw(screen, "Error closing connection.")
                return -1
            else:
                return -1
        
        return (cols, rows)
Пример #8
0
    def execute(query, db, screen = None, ISO_level = None, multi_part = None, username = None, password = None):
    	#exceptions for debugging purposes
        if username is None:
            try:
                string = "dbname=\'" + db + "\' user='******' password='******'"
                conn = psycopg2.connect(string)
            except:
                if screen is not None:
                    error.throw(screen, "Error to connecting to \'" + db + "\' database.")
                    return -1
                else:
                    return -1
        else:
            try:
                string = "dbname=\'" + db + "\' user=\'" + username + "\' password=\'" + password + "\'"
                conn = psycopg2.connect(string)
            except:
                if screen is not None:
                    error.throw(screen, "Error to connecting to \'" + db + "\' database.")
                    return -2
                else:
                    return -2

        if ISO_level is not None:
            try:
                conn.set_isolation_level(ISO_level)
            except:
                if screen is not None:
                    error.throw(screen, "Error setting Isolation Level.")
                    return -1
                else:
                    return -1

        try:
            cur = conn.cursor()
        except:
            if screen is not None:
                print error.throw(screen, "Error creating cursor.")
                return -1
            else:
                return -1

        try:
            if multi_part is None:
                cur.execute(query)
            else:
                cur.execute(query, (multi_part,))
        except:
            if screen is not None:
                error.throw(screen, "Error executing query.")
                
                return -1
            else:
                return -1

        if ISO_level is not 0 or None:
            try:
                conn.commit()
            except:
                if screen is not None:
                    error.throw(screen, "Error commiting query.")
                    return -1
                else:
                    return -1

        try:
            cur.close()
        except:
            if screen is not None:
                error.throw(screen, "Error closing cursor.")
                return -1
            else:
                return -1

        try:
            conn.close()
        except:
            if screen is not None:
                error.throw(screen, "Error closing connection.")
                return -1
            else:
                return -1

        return 0
Пример #9
0
    def fetch(query,
              db,
              screen=None,
              ISO_level=None,
              multi_part=None,
              username=None,
              password=None):
        if username is None:
            try:
                string = "dbname=\'" + db + "\' user='******' password='******'"
                conn = psycopg2.connect(string)
            except:
                if screen is not None:
                    error.throw(
                        screen,
                        "Error to connecting to \'" + db + "\' database.")
                    return -1
                else:
                    return -1
        else:
            try:
                string = "dbname=\'" + db + "\' user=\'" + username + "\' password=\'" + password + "\'"
                conn = psycopg2.connect(string)
            except:
                if screen is not None:
                    error.throw(
                        screen,
                        "Error to connecting to \'" + db + "\' database.")
                    return -2
                else:
                    return -2

        if ISO_level is not None:
            try:
                conn.set_isolation_level(ISO_level)
            except:
                if screen is not None:
                    error.throw(screen, "Error setting Isolation Level.")
                    return -1
                else:
                    return -1

        try:
            cur = conn.cursor()
        except:
            if screen is not None:
                error.throw(screen, "Error creating cursor.")
                return -1
            else:
                return -1

        if ISO_level is not 0 or None:
            try:
                if multi_part is None:
                    cur.execute(query)
                else:
                    cur.execute(query, (multi_part, ))
            except:
                if screen is not None:
                    error.throw(screen, "Error executing query.")
                    return -1
                else:
                    return -1

        try:
            cols = [desc[0] for desc in cur.description]
            rows = cur.fetchall()
        except:
            if screen is not None:
                error.throw(screen, "Error executing fetch.")
                return -1
            else:
                return -1

        try:
            cur.close()
        except:
            if screen is not None:
                error.throw(screen, "Error closing cursor.")
                return -1
            else:
                return -1

        try:
            conn.close()
        except:
            if screen is not None:
                error.throw(screen, "Error closing connection.")
                return -1
            else:
                return -1

        return (cols, rows)
Пример #10
0
    def execute(query,
                db,
                screen=None,
                ISO_level=None,
                multi_part=None,
                username=None,
                password=None):
        #exceptions for debugging purposes
        if username is None:
            try:
                string = "dbname=\'" + db + "\' user='******' password='******'"
                conn = psycopg2.connect(string)
            except:
                if screen is not None:
                    error.throw(
                        screen,
                        "Error to connecting to \'" + db + "\' database.")
                    return -1
                else:
                    return -1
        else:
            try:
                string = "dbname=\'" + db + "\' user=\'" + username + "\' password=\'" + password + "\'"
                conn = psycopg2.connect(string)
            except:
                if screen is not None:
                    error.throw(
                        screen,
                        "Error to connecting to \'" + db + "\' database.")
                    return -2
                else:
                    return -2

        if ISO_level is not None:
            try:
                conn.set_isolation_level(ISO_level)
            except:
                if screen is not None:
                    error.throw(screen, "Error setting Isolation Level.")
                    return -1
                else:
                    return -1

        try:
            cur = conn.cursor()
        except:
            if screen is not None:
                print error.throw(screen, "Error creating cursor.")
                return -1
            else:
                return -1

        try:
            if multi_part is None:
                cur.execute(query)
            else:
                cur.execute(query, (multi_part, ))
        except:
            if screen is not None:
                error.throw(screen, "Error executing query.")

                return -1
            else:
                return -1

        if ISO_level is not 0 or None:
            try:
                conn.commit()
            except:
                if screen is not None:
                    error.throw(screen, "Error commiting query.")
                    return -1
                else:
                    return -1

        try:
            cur.close()
        except:
            if screen is not None:
                error.throw(screen, "Error closing cursor.")
                return -1
            else:
                return -1

        try:
            conn.close()
        except:
            if screen is not None:
                error.throw(screen, "Error closing connection.")
                return -1
            else:
                return -1

        return 0