コード例 #1
0
ファイル: mainpanel.py プロジェクト: edv4rd0/pyreportcreator
 def run_query(self):
     """
     Get current doc and run the query.
     This asks the user for a filename.
     """
     try:
         query = self.documentsOpen[self.view.GetCurrentPage().documentID].document
     except AttributeError:
         return
     try:
         builtQuery = querybuilder.build_query(query)
     except querybuilder.ClauseException:
         dlg = wx.MessageDialog(parent = wx.GetApp().GetTopWindow(),\
                                message = "One or more of the query conditions are either empty or missing parameters, please check them and try again.",\
                                caption = "Query Building Error", style = wx.OK)
         dlg.ShowModal()
         dlg.Destroy()
         return
     except sqlalchemy.exc.OperationalError:
         dlg = wx.MessageDialog(parent = wx.GetApp().GetTopWindow(),\
                                message = "There was an error connecting to the database. Please make sure it's up and try again.", \
                                caption = "Database Connectivity Error", style = wx.OK)
         dlg.ShowModal()
         dlg.Destroy()
         return
     #now run the built query
     try:
         dlg = wx.FileDialog(wx.GetApp().GetTopWindow(), "Choose Output File", os.getcwd(), "", "*.csv", wx.SAVE)
         if dlg.ShowModal() == wx.ID_OK:
             path = dlg.GetPath()
             dlg.Destroy()
             if path[-4:] != ".csv":
                 path = path + ".csv"
             #write report to csv file
             headings = []
             for t in query.selectItems.keys():
                 for c in query.selectItems[t]:
                     headings.append(t + "." + c[0])
             querybuilder.run_report(builtQuery, query.engineID, path, headings)
             dlg = wx.MessageDialog(parent = wx.GetApp().GetTopWindow(),\
                                message = "Successfully created report. \nWritten to: " + path, \
                                caption = "Success!", style = wx.OK)
             dlg.ShowModal()
             dlg.Destroy()
     except querybuilder.ClauseException:
         dlg = wx.MessageDialog(parent = wx.GetApp().GetTopWindow(),\
                                message = "One or more of the query conditions are either empty or missing parameters, please check them and try again.",\
                                caption = "Query Building Error", style = wx.OK)
         dlg.ShowModal()
         dlg.Destroy()
     except sqlalchemy.exc.OperationalError:
         dlg = wx.MessageDialog(parent = wx.GetApp().GetTopWindow(),\
                                message = "There was an error connecting to the database. Please make sure it's up and try again.", \
                                caption = "Database Connectivity Error", style = wx.OK)
         dlg.ShowModal()
         dlg.Destroy()
コード例 #2
0
ファイル: mainpanel.py プロジェクト: edv4rd0/pyreportcreator
 def view_sql(self):
     """Get current doc and then generate sql"""
     try:
         query = self.documentsOpen[self.view.GetCurrentPage().documentID].document
     except AttributeError:
         return
     try:
         builtQuery = querybuilder.build_query(query)
         dlg = ViewSQLDialog(wx.GetApp().GetTopWindow(), builtQuery.__str__())
         dlg.ShowModal()
         dlg.Destroy()
     except querybuilder.ClauseException:
         dlg = wx.MessageDialog(parent = wx.GetApp().GetTopWindow(),\
                                message = "One or more of the query conditions are either empty or missing parameters, please check them and try again.",\
                                caption = "Query Building Error", style = wx.OK)
         dlg.ShowModal()
         dlg.Destroy()
     except sqlalchemy.exc.OperationalError:
         dlg = wx.MessageDialog(parent = wx.GetApp().GetTopWindow(),\
                                message = "There was an error connecting to the database. Please make sure it's up and try again.", \
                                caption = "Database Connectivity Error", style = wx.OK)
         dlg.ShowModal()
         dlg.Destroy()