lundi 28 décembre 2015

Python: How can I troubleshoot this Function?

I'm working on an application and currently focusing on the database area.

I have successfully setup functions that create databases and write to them, however right now I am trying to retrieve specific rows from the database however NO MATTER WHAT I TRY I always get a syntax error DESPITE my SQL query running successfully in in sqlite browser.

This is my trouble code:

def findapple():
    conn = sqlite3.connect('working.db')
    c = conn.cursor()
    for row in c.execute('SELECT * FROM "working" WHERE "symbol" = 'aapl';')
        print row

If I understand the code I've written, it should connect to "working.db" create a cursor for the database then for each row that match my query it should be printed to the console.

Can anyone please help shed some light on this?

Thank you!

Current Code Per comments below:

def findapple():
conn = sqlite3.connect('working.db')
c = conn.cursor()
for row in c.execute('SELECT * FROM working WHERE symbol = 'aapl'')
    print row

and the error output:

    Traceback (most recent call last):
  File "main.py", line 1, in <module>
    from stock import *
  File "/Users/ME/Documents/Code/Stocks/stock/database.py", line 61
    for row in c.execute('SELECT * FROM working WHERE symbol = 'aapl'')

Aucun commentaire:

Enregistrer un commentaire