November 17, 2024

Marijuana Web

Mari Juana Web, the Best You Can Get!

Create conditions with (WHERE x =? OR y =? LIMIT 1). I can select, but I cannot use the results

Selecting the name of a company in the financial market from the combobox, I search in the database which is the last record that contains the company in company1 or company2 (WHERE company1 =? OR company2 =? LIMIT 1). Last_company searches if the last company (selected via combobox) is present in company1 or company2

if combo_company:

    combo_company = select_company.split(',')[0]                    

    cursor.execute("SELECT company1, company2, positive, negative FROM Table1 WHERE company1 =? OR company2=? LIMIT 1", [combo_company, combo_company])
    Last_company_value = cursor.fetchall()[0]

Based on whether the company is the last record in company1 or company2, I would like to have a condition (with if). The problem is that I can search if the company is the last record in company1 or company2, but I don’t know how to use company1 and company 2 separately (WHERE azienda1 =? OR azienda2 =? LIMIT 1) to create the condition. The condition is to automatically search if the result of Last_company_value is found in company1 or company2

#Last company in company1
cursor.execute("SELECT positive, negative FROM Table1 WHERE company1 =? LIMIT 1", [combo_company])
Last_Company_in_Company1 = cursor.fetchall()[0]

#Last company in company2
cursor.execute("SELECT positive, negative FROM Table1 WHERE company2 =? LIMIT 1", [combo_company])
Last_Company_in_Company2 = cursor.fetchall()[0]

Here is the one where I fail, that is to create the conditions with company1 and company2 (WHERE company1 =? OR company2 =? LIMIT 1). I’m not even sure if using [x] is the right way. I am getting the index out of range error

#result of Last_company_value is in company1
if (Last_company_value) and (Last_company_value[4]):
    print(Last_Company_in_Company1)

#result of Last_company_value is in company2
if (Last_company_value) and (Last_company_value[3]):
   print(Last_Company_in_Company2)