2

I have a problem with a Python 2.7 project.

I'm trying to set a variable to a value retrieved from an sqlite3 database, but I'm having trouble. Here is my code thus far, and the error I'm receiving. Yes, the connection opens just fine, and the table, columns, and indicated row are there as they should be.

import sqlite3 import Trailcrest

conn = sqlite3.connect('roster.paw')
c = conn.cursor()

def Lantern(AI):
    """Pulls all of the data for the selected user."""
    Trailcrest.FireAutoHelp = c.execute("""select fireautohelp 
                                             from roster 
                                            where index = ?;""", (AI,) ).fetchall()

The error is:

> Traceback (most recent call last):   
> File "<pyshell#4>", line 1, in <module> Lantern(1)
> File "C:\Users\user\MousePaw Games\Word4Word\PYM\Glyph.py", line 20, 
> in Lantern
>     Trailcrest.FireAutoHelp = c.execute("""select fireautohelp from roster where index = ?;""", (AI,)).fetchall()
> OperationalError: near "index": syntax error
1
  • 2
    index is an sql keyword, so I guess you can't use it as a column name. Commented Jul 6, 2011 at 0:16

1 Answer 1

6

As Thomas K mentions in a comment, index is a SQL keyword.
You can either rename that column, or enclose in backticks:

Trailcrest.FireAutoHelp = c.execute("""select fireautohelp 
                                         from roster 
                                        where `index` = ?;""", (AI,) ).fetchall()
Sign up to request clarification or add additional context in comments.

1 Comment

That was indeed the problem. Thank you!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.