2017-03-06 34 views
0

我在Ubuntu中使用Web2py和sqlite Db。 Iweb2py,用户输入帖子的项目到一个SQLite数据库,如“你好世界”如下: 在控制器默认的项目过帐到ThisDb如下:如何解决Sqlite数据库索引错误

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() 

另一个代码选秀权还是应该阅读项目从ThisDb,在这种情况下的 'Hello World',如下所示:

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() 

表 '输入',其中的Hello World”应该读我的数据库配置是这样的:

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

此代码先前工作良好,而Windows7和10编码,但我有这个问题离子Ubuntu 16.04。并且我不断收到此错误:

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

回答

0

row[0]是第一列中的值。
row[1]是第二列中的值。

显然,您以前的数据库有多个列。