Esempio n. 1
0
if con['state'] == 0: # If connection flag is set - good!
  print 'Connected!',
elif con['state'] == 1: # If connection flag is not set - fail!
  print 'Failed',

#if VERBOSE: # If set prints the failure message received in initial call to connect
  #print '[' + con['msg'] + ']'
print '\n'


print '\n--------------------------------------------'
print 'Get Tables from the Database'
print '--------------------------------------------'
print 'Attempt to query for table list...',
con = database_queries.dbTables(con) # Attempt to get tables in database

if con['msg'] == 'Tables retreived': # Check return msg for success
  print 'Passed!',
  
  if VERBOSE: # Print associated status message associated with call
    print '[' + con['msg'] + ']\n'

  for idx, table in enumerate(con['tables']): # Print out each table name line by line
    print 'Table ' + str(idx) + ': ' + table[0] + '\n'

else: # Call to retrieve table(s) must have failed. 
  print 'Failed',
  if VERBOSE:
    print '[' + con['msg'] + ']' # Print associated message related to call failure
Esempio n. 2
0
def printEditTableSubmenu(stdscr,con):
    stdscr.clear()
    stdscr.addstr(4, 2, "----------------------------------------------------------------------------")
    stdscr.addstr(6, 30, "-- EDIT TABLE --")
    stdscr.addstr(22, 45, "[B] Back")

    # Attempt to get tables in database so that they can be printed
    con = database_queries.dbTables(con) 

    # Detect if no tables exist
    if con['tbl_cnt'] == 0:
        stdscr.addstr(9, 6, "No tables in database")
        
        # Collect user's navigation selection
        user_input = stdscr.getch()

        # Navigate to submenu
        if user_input == ord('b') or user_input == ord('B'):
            printViewEditSubmenu(stdscr,con)

    # At least 1 table exists so print them
    else:
        y = 8
        x = 6 
        # Print out each table name line by line up to 6 per screen
        for idx, table in enumerate(con['tables']): 
            table_string = "[" + str(idx + 1) + "] " + table[0]
            stdscr.addstr(y, x, table_string)    
            y += 2

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

                # Navigate to submenu
                if user_input == ord('b') or user_input == ord('B'):
                    printViewEditSubmenu(stdscr,con)

                # Paginate
                elif user_input == ord('n') or user_input == ord('N'):
                    stdscr.clear()
                    stdscr.addstr(4, 2, "----------------------------------------------------------------------------")
                    stdscr.addstr(6, 30, "-- EDIT TABLE --")
                    stdscr.addstr(22, 45, "[B] Back")
                    y = 8
                    x = 6

                # Navigate to view table
                elif user_input >= ord('1') and user_input <= unichr(con['tbl_cnt']):
                    try:
                        printViewTableContentsSubmenu(stdscr, con, int(chr(user_input)) - 1)
                    except ValueError:
                        printViewTableSubmenu(stdscr, con)

                elif user_input == ord('\n'):
                    printViewTableSubmenu(stdscr, con)
                
        # Collect user's navigation selection
        user_input = stdscr.getch()
        

        # Navigate to submenu
        if user_input == ord('b') or user_input == ord('B'):
            printViewEditSubmenu(stdscr,con)

        # Navigate to view table
        elif user_input >= ord('1') and user_input <= unichr(con['tbl_cnt']):
            try:
                printViewTableContentsSubmenu(stdscr, con, int(chr(user_input)) - 1)
            except ValueError:
                printViewTableSubmenu(stdscr, con)

        elif user_input == ord('\n'):
            printViewTableSubmenu(stdscr, con)
Esempio n. 3
0
def printViewTableSubmenu(stdscr,con):
    stdscr.clear()
    stdscr.addstr(4, 2, "----------------------------------------------------------------------------")
    stdscr.addstr(6, 30, "-- VIEW TABLE --")
    stdscr.addstr(22, 45, "[B] Back")

    # Attempt to get tables in database so that they can be printed
    con = database_queries.dbTables(con) 

    # Detect if no tables exist
    if con['tbl_cnt'] == 0:
        stdscr.addstr(9, 6, "No tables in database")
        
        # Collect user's navigation selection
        user_input = stdscr.getch()
        
#---------------------------------------------------------------------
# TODO: NEED TO REFACTOR WITH HIGHLIGHT
#---------------------------------------------------------------------

        # Navigate to submenu
        if user_input == ord('b') or user_input == ord('B'):
            printViewEditSubmenu(stdscr,con)

        # TODO: need to refactor with hightlight selection
        curses.endwin() # can erase once highlight is implemented
        exit()

    # At least 1 table exists so print them
    else:
        y = 8
        x = 6 
        # Print out each table name line by line up to 6 per screen
        for idx, table in enumerate(con['tables']): 
            table_string = "[" + str(idx + 1) + "] " + table[0]
            stdscr.addstr(y, x, table_string)    
            y += 2

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

#---------------------------------------------------------------------
# TODO: NEED TO REFACTOR WITH HIGHLIGHT
#---------------------------------------------------------------------

                # Navigate to submenu
                if user_input == ord('b') or user_input == ord('B'):
                    printViewEditSubmenu(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 --")
                    stdscr.addstr(22, 45, "[B] Back")
                    y = 8
                    x = 6

                # Navigate to view table
                elif user_input >= ord('1') and user_input <= unichr(con['tbl_cnt']):
                    printViewTableContentsSubmenu(stdscr, con, int(chr(user_input)) - 1)

        # Collect user's navigation selection
        user_input = stdscr.getch()

#---------------------------------------------------------------------
# TODO: NEED TO REFACTOR WITH HIGHLIGHT
#---------------------------------------------------------------------

        # Navigate to submenu
        if user_input == ord('b') or user_input == ord('B'):
            printViewEditSubmenu(stdscr,con)

        # Navigate to view table
        elif user_input >= ord('1') and user_input <= unichr(con['tbl_cnt']):
            printViewTableContentsSubmenu(stdscr, con, int(chr(user_input)) - 1)