DatabaseError:在SQL上执行失败

时间:2019-09-25 12:13:53

标签: sql database python-2.7

代码将创建一个UI,并基于UI的输入进行一些计算并返回一些行。但是它返回了我:

DatabaseError:在sql'SELECT * FROM dbo.vw_DealPipelineHistorical WHERE InvestmentProgram ='CI-Principal Credit Investments'AND AND AND CashOutflowOrInflow ='Cash Inflow'AND FundingCurrency ='CAD'AND DealStatus ='Funded'中,执行失败'42000',u“ [42000] [Microsoft] [ODBC SQL Server驱动程序] [SQL Server]关键字'AND'附近的语法不正确。(156)(SQLExecDirectW)”) 127.0.0.1--[24 / Sep / 2019 17:31:27]“ POST / _dash-update-component HTTP / 1.1” 500-

   def update_check(n_button, prog, progc, amnt, amntc, date, datec, inout, inoutc, curr, currc, given):

        if given is None:
            return "Please enter an initial probability.", "", ""
        else:
            filteroptions = (progc, amntc, datec, inoutc, currc)
            filterstr =" WHERE ProbabilityofClosing = {}".format(given)
            filterfundstr = ""
            first = True
            firstfund = True
            outputlst = []
            nofilter = "Filtering by: "
            for option in filteroptions:
                #skip iteration if not checked

                if not option or option is None:
                    outputlst.append(None)
                    continue
                outputlst.append(option)
                #add WHERE or AND
                if not firstfund:
                    filterstr += " AND "
                    filterfundstr += " AND "
                else:
                    filterstr += " AND "
                    filterfundstr += " WHERE "


                #add filters

                if option[0] == 'prog':
                    if prog is None:
                        return "ERROR: Please select an Investment Program or adjust your filter criteria", "",""
                        continue
                    nofilter += "Investment Program, "
                    filterstr += "InvestmentProgram = '{}'".format(prog)
                    filterfundstr += "InvestmentProgram = '{}'".format(prog) 
                    first = False
                    firstfund = False

                elif option[0] == 'amnt':
                    if amnt is None:
                        return "ERROR: Please enter a Funding Amount or adjust your filter criteria", "", ""
                        continue
                    filterstr += "MostLikelyAmount = "
                    filterstr += str(amnt)
                    first = False
                    nofilter += "Amount, "

                elif option[0] == 'date':
                    filterstr += "MostLikelyFundingDate = '{}'".format(date)
                    first = False
                    nofilter += "Date, "

                elif option[0] == 'curr':
                    if not curr:
                        return "ERROR: Please select a Currency or adjust your filter criteria", "", ""
                        continue
                    if len(curr)>1:
                        filterstr += "("                                
                        filterfundstr += "("
                        firstcurr = True
                        for chosen in curr:                
                            if firstcurr:
                                firstcurr = False
                            else:
                                filterstr += " OR "
                                filterfundstr += " OR "
                            filterstr += "FundingCurrency = '{}'".format(chosen)
                            filterfundstr += "FundingCurrency = '{}'".format(chosen)                
                        filterstr += ")"
                        filterfundstr += ")"
                    else:
                        filterstr += "FundingCurrency = '{}'".format(curr[0])
                        filterfundstr += "FundingCurrency = '{}'".format(curr[0])
                    first = False
                    firstfund = False
                    nofilter += "Currency, "

                elif option[0] == 'inout':
                    if inout is None:
                        return "ERROR: Please select a Flow Direction or adjust your filter criteria", "", ""
                        continue
                    filterstr += "CashOutflowOrInflow = '"
                    filterstr += inout + "'"
                    filterfundstr += "CashOutflowOrInflow = '{}'".format(inout)
                    first = False
                    firstfund = False
                    nofilter += "Flow Direction, "


        if first:
            nofilter = "No filters Selected."
        else:
            nofilter = nofilter[:-2]
        #create query
        filteredSQLPotential = "SELECT * FROM dbo.vw_DealPipelineHistorical " +filterstr
        filteredSQLFunded = "SELECT * FROM dbo.vw_DealPipelineHistorical " +filterfundstr

        completed, total = dataImport(filteredSQLPotential, filteredSQLFunded, first)

        if total == 0:
            return "No deals matched your search.", "Please update your search criteria and try again.", ""

        confidence = "This update was calculated based on {} historical deals".format(total)
        prob = get_updated_prob(given, completed, total)
        return nofilter, prob*100, confidence

我也想问选项是什么意思?和选项[0]?在这种情况下代表什么?谢谢!

0 个答案:

没有答案