-1

How can I get values in a particular row by using Rowid in sqlite3. In my have written the python code:

conn = sqlite3.connect('database.db')
c = conn.cursor()
c.execute("SELECT rowid, * FROM aqn_data WHERE rowid = 25")

This prints [] where I want to print the values from row 25.

2 Answers2

0

Your execute statement appears to be correct.

Assuming your table actually has a column named rowid and it's not the implicit column as defined in the SQLite documentation.

Check if your database actually has an entry for rowid = 25.

SELECT * FROM aqn_data ORDER BY rowid ASC;

This gives you all entries in that table. Generally ORDER BY should be optional in this case but I have no information on how your table schema is created so I mentioned it regardless.

If it actually has the data you want, then the following line is sufficient:

SELECT * FROM aqn_data WHERE rowid = 25;

It's also worth reformatting your Cursor.execute() statement into:

c.execute("SELECT rowid, * FROM aqn_data WHERE rowid = ?", (25))

It makes no difference in this specific case, but again it's good to drill this practice into your code to avoid SQL injection issues in code which actually relies on variable data. Do not ever use python string formatting for sqlite3 objects!

gny-001f2
  • 29
  • 5
0

you have to write more code to grab output

conn = sqlite3.connect('database.db')
c = conn.cursor()
c.execute("SELECT rowid, * FROM aqn_data WHERE rowid = 25")

Right code

cur = conn.cursor()
cur.execute("SELECT rowid, * FROM aqn_data WHERE rowid = 25")

rows = cur.fetchall()

for row in rows:
    print(row)
Jin Thakur
  • 2,711
  • 18
  • 15