Search code examples
sqliteweb2pyubuntu-16.04

How do I solve Sqlite DB Index Error


Am working with Web2py and sqlite Db in Ubuntu. Iweb2py, a user input posts an item into an sqlite DB such as 'Hello World' as follows: In the controller default the item is posted into ThisDb as follows:

consult = db.consult(id) or redirect(URL('index'))
form1 = [consult.body]
form5 = form1#.split()
name3 = ' '.join(form5)
conn = sqlite3.connect("ThisDb.db")
c = conn.cursor()
conn.execute("INSERT INTO INPUT (NAME) VALUES (?);", (name3,))
conn.commit()

Another code picks or should read the item from ThisDb, in this case 'Hello World' as follows:

location = ""
conn = sqlite3.connect("ThisDb.db")
c = conn.cursor()
c.execute('select * from input')
c.execute("select MAX(rowid) from [input];")
for rowid in c:break
for elem in rowid:
    m = elem
    c.execute("SELECT * FROM input WHERE rowid = ?", (m,))
    for row in c:break
    location = row[1]
    name = location.lower().split()

my DB configuration for the table 'input' where Hello World' should be read from is this:

CREATE TABLE `INPUT` (
    `NAME`  TEXT
);

This code previously workd well while coding with windows7 and 10 but am having this problem ion Ubuntu 16.04. And I keep getting this error:

File "applications/britamintell/modules/xxxxxx/define/yyyy0.py", line 20, in xxxdefinition
    location = row[1]
IndexError: tuple index out of range

Solution

  • row[0] is the value in the first column.
    row[1] is the value in the second column.

    Apparently, your previous database had more than one column.