コード例 #1
0
ファイル: curses_interface.py プロジェクト: BauerBr/CS419
def printEditTableContentsSubmenu(stdscr, con, idx):
    stdscr.clear()
    stdscr.refresh()
    stdscr.addstr(4, 2, "----------------------------------------------------------------------------")
    stdscr.addstr(6, 28, "-- EDIT TABLE --")

    # Draw input table
    stdscr.addstr(8, 6, "Enter a sql statement:")
    stdscr.addstr(10, 5, "+")
    stdscr.addstr(10, 6, "--------------------------------------------------------------------")
    stdscr.addstr(10, 74, "+")
    stdscr.addstr(11, 5, "|")
    stdscr.addstr(12, 5, "|")
    stdscr.addstr(13, 5, "|")
    stdscr.addstr(11, 74, "|")
    stdscr.addstr(12, 74, "|")
    stdscr.addstr(13, 74, "|")
    stdscr.addstr(14, 5, "+")
    stdscr.addstr(14, 6, "--------------------------------------------------------------------")
    stdscr.addstr(14, 74, "+")

    # Collect user input
    user_input = stdscr.getstr(12, 7, 66)
    
#---------------------------------------------------------------------
# TODO: NEED TO REFACTOR WITH HIGHLIGHT
#---------------------------------------------------------------------

    # Attempt to submit query
    con = database_queries.dbQuery(con, user_input)

    # Edit query success; return to main menu
    if queryCheck(con) == 1:
        stdscr.clear()
        stdscr.addstr(4, 2, "----------------------------------------------------------------------------")
        stdscr.addstr(6, 28, "-- EDIT TABLE --")
        stdscr.addstr(10, 5, "Query Success! Press Enter to Continue...")
        stdscr.getstr(1, 1, 0)
        printMainMenu(stdscr,con)

    # Edit query failure; return to main menu
    else:
        stdscr.clear()
        stdscr.addstr(4, 2, "----------------------------------------------------------------------------")
        stdscr.addstr(6, 28, "-- EDIT TABLE --")
        stdscr.addstr(10, 5, "Query Failure! Press Enter to Continue...")
        stdscr.getstr(1, 1, 0)
        printEditTableSubmenu(stdscr,con)
コード例 #2
0
ファイル: curses_interface.py プロジェクト: BauerBr/CS419
def printViewTableContentsSubmenu(stdscr, con, idx):
    stdscr.clear()
    stdscr.addstr(4, 2, "----------------------------------------------------------------------------")
    stdscr.addstr(6, 30, "-- VIEW TABLE --")  
    
    # Create the query string to retrieve the contents of the selected table
    table_string = "SELECT * FROM " + str(con['tables'][idx][0])

    # Conduct SELECT query; results in con['rows']
    con = database_queries.dbQuery(con, table_string)

    y = 12
    x = 14
    c = 10 # New Y Coordinate for columns
    s = 14 # New X Coordinate for columns

    totalRows = "Number of Rows: " + str(con['cnt'])
    stdscr.addstr(8, s, totalRows)

    # TODO: add borders
    # Printing Attribute names. https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlcursor-column-names.html
    for idx, col in enumerate(con['cols']):
        if idx != 11:
            #mid = int(math.ceil(s / 2))
            mid = int(math.ceil((s) - 3.5))
            stdscr.addstr(c, mid, "|")
        col_string = str(col)
        if len(col_string) >= 11:   # Trimming column name if it is too long.
            col_string = col_string[:10]
        stdscr.addstr(c, s, col_string)
        s += 15
    stdscr.addstr(y, 5, "--------------------------------------------------------------------------------------------------------------------------------------------------------")    
    y += 2

    # Print out each row line by line up to 6 per screen
    if con['cnt'] == 0:
        stdscr.addstr(y, 14, "No Rows in Table!")
        y += 2
        stdscr.addstr(y, 5, "--------------------------------------------------------------------------------------------------------------------------------------------------------")    

        # Collect user's navigation selection
        user_input = stdscr.getch()
        if user_input == ord('b') or user_input == ord('B'):
            printViewTableSubmenu(stdscr,con)

    else:
        mybool = False
        count = 0
        for idx, row in enumerate(con['rows']):

        #Detect the last row that can fit on a page (6th)
            if idx != 0 and idx % 11 == 0:
                mybool = True
                # Detect if there are add'l rows past multiple of 6th
                if (idx + 1) < con['row_cnt']:
                    y += 2
                    stdscr.addstr(y, 15, "[N] Next")
                    stdscr.addstr(y, 45, "[B] Back")  
                
                #Collect user's navigation selection
                user_input = stdscr.getch()

                # Navigate to submenu
                if user_input == ord('b') or user_input == ord('B'):
                    printViewTableSubmenu(stdscr,con)
                # Paginate
                elif user_input == ord('n') or user_input == ord('N'):
                    stdscr.clear()
                    stdscr.addstr(4, 2, "----------------------------------------------------------------------------")
                    stdscr.addstr(6, 30, "-- VIEW TABLE --")
                    y = 12
                    x = 14
            # Collect user's navigation selection
            #user_input = stdscr.getch()
            count += 1
            row_count = "[" + str(count) + "]  "
            x = 5
            stdscr.addstr(y, x, row_count)
            for ndx, col in enumerate(con['cols']): #Created new counter 'ndx' for traversing within the SQL row.

                row_string = str(row[col])
                #DO NOT TOUCH THIS LINE
                if len(row_string) >= 11:   # Trimming column name if it is too long.
                    row_string = row_string[:10]
                if ndx == 0:    # Do this for the first value.
                    x = 14 
                    mid = int(math.ceil((x) - 3.5))
                    stdscr.addstr(y, mid, "|")  
                    stdscr.addstr(y, x, row_string)
                else:
                    x += 15
                    mid = int(math.ceil((x) - 3.5))
                    stdscr.addstr(y, mid, "|")
                    stdscr.addstr(y, x, row_string)   
                #y += 2

            y += 2
            #stdscr.addstr(y, 45, "[B] Back")  

        # y += 2
        if mybool == False:
            stdscr.addstr(y, 45, "[B] Back")
            y += 2  
    
    stdscr.addstr(y, 5, "--------------------------------------------------------------------------------------")    
コード例 #3
0
ファイル: database_test.py プロジェクト: BauerBr/CS419
else: # Call to retrieve table(s) must have failed. 
  print 'Failed',
  if VERBOSE:
    print '[' + con['msg'] + ']' # Print associated message related to call failure


print '\n--------------------------------------------'
print 'Send Query (SELECT/DELETE/INSERT) to the Database'
print '--------------------------------------------'
user_query = raw_input('Enter a proper SQL query: ') # Intended to collect a mysql query from the user
print '\nYou entered: ' + user_query + '\n\n'

# attempt to get tables in database
print 'Attempting to send query to the database...',
con = database_queries.dbQuery(con, user_query) # Attempt to get tables in database

response = con['msg'].split() # Parse response message to determine if query worked or not
if response[0] == 'Successful':
  print 'Passed!',

  if VERBOSE:
    print '[' + con['msg'] + ']' # Print associated success message

  if response[1] == 'SELECT': # Print rows of a table if SELECT was chosen
    # print each row
    print '\nROWS IN SELECT:'
    for idx,row in enumerate(con['rows']):
      print 'row ' + str(idx) + ': ' + str(row)
    # print row count of table
    print 'Row Count: ' + str(con['row_cnt']) # Print the number of rows in the SELECT call