<commit_before>#!/usr/bin/python

import urwid

"""
NOTES
-----
This module builds the widget to allow the user to enter in their own SQL query

This module will also run the sql query and show a success message if it works

"""

class QueryInfo:
  def __init__(self):
    self.query_text = ""
    self.error_msg = ""


def show_runsql(main_body, user_info):
  #used to easily insert a blank line widget
  blank = urwid.Divider()

  query_info = QueryInfo()

  #signal handler for the run button
  def run_btn_press(button):
    #ADD ERROR HANDLING!!!!!!!!!!!!!!!!!!!!!!!!!!
    #error handling to make sure the sql query works
    #if no error, then show success message and sql query
    #text_error.set_text(u"No error, query ran successfully!")
    text_error.set_attr_map({None:'topmenu'})
    text_error.original_widget.set_text(u" No error, query ran successfully!")
    size = (5,)
    text_error.render(size)
    

  #signal handler for text input, stores input information from user
  def edit_change_event(self, text):
    query_info.query_text = text

  #variables to hold text to show user for login view<commit_msg>adding functionality for running sql command<commit_after>#!/usr/bin/python

import urwid


"""
NOTES
-----
This module builds the widget to allow the user to enter in their own SQL query

This module will also run the sql query and show a success message if it works

"""


def show_runsql(main_body, user_info):
  #used to easily insert a blank line widget
  blank = urwid.Divider()

  query_text = ""

  #signal handler for text input, stores input information from user
  def edit_change_event(self, text):
    query_text = text


  #signal handler for the run button
  def run_btn_press(button):
    #ADD ERROR HANDLING!!!!!!!!!!!!!!!!!!!!!!!!!!
    #error handling to make sure the sql query works
    #if no error, then show success message and sql query

    #text_error.set_text(u"No error, query ran successfully!")
    #text_error.set_attr_map({None:'topmenu'})
    #text_error.original_widget.set_text(u" No error, query ran successfully!")
    #size = (5,)
    #text_error.render(size)
    user_info.db_conn.runquery()

    print "TeST"

    try:
      user_info.db_conn.execute(query_text)
      text_error.original_widget = urwid.AttrWrap( urwid.Text(u" No error, query ran successfully"), 'topmenu')
    except psycopg2.Error as e:
      query_error = u"There was an error"
      #query_error = e.pgerror
      text_error.original_widget = urwid.AttrWrap( urwid.Text(query_error), 'error')
      print e

 

  #variables to hold text to show user for login view
{'fraction_non_alphanumeric': 0.1032233307751343, 'fraction_numerical': 0.0011511895625479663, 'mean_word_length': 3.7572992700729926, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3243263', 'n_tokens_mistral': 812, 'n_tokens_neox': 782, 'n_words': 282}