Python Forum
Python Variables and Sqlite3 Database
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Variables and Sqlite3 Database
#1
Is there any way to pull each column entry and make each db entry it's own variable? I know how to pull a single entry at a time using something like

for rows in cursor.execute("SELECT commands FROM CR WHERE ID = [1]):
variable=rows
print(variable)
else:
variable = 0

But I need a way to make variable1 = (column entry 1), Variable2 = (column entry 2), so on and so forth. I'm assuming I would have to use arrays but can't find any guidance online. Any help would be greatly appreciated. Thanks.
Reply
#2
I figured it out. If anyone else needs to do this... Here is the correct code...

for i in range(1,3):
print(i)
cur.execute("SELECT commands FROM CR WHERE ID=?", (i,))
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Create SQLite3 database with peewee Jim53_1980 2 601 Dec-20-2023, 02:38 PM
Last Post: buran
  Regex replace in SQLite3 database WJSwan 1 749 Dec-04-2023, 05:55 PM
Last Post: Larz60+
  Rows not adding to sqlite3 database using SQLAlchemy Calab 11 1,597 Jun-02-2023, 05:53 PM
Last Post: bowlofred
  Basic SQL query using Py: Inserting or querying sqlite3 database not returning data marlonbown 3 1,306 Nov-08-2022, 07:16 PM
Last Post: marlonbown
  how to use variables when open a sqlite database? 53535 1 1,176 Apr-07-2022, 08:33 AM
Last Post: ndc85430
  doubt about python tkinter and sqlite3 LONDER 2 2,119 Aug-14-2021, 08:48 AM
Last Post: ibreeden
  Python, PySimpleGUI and SQLite3 jamesaarr 0 1,943 Jul-29-2021, 01:22 PM
Last Post: jamesaarr
  sqlite3 database problem Maryan 2 2,427 Oct-05-2020, 05:21 AM
Last Post: buran
  sqlite3 database does not save data across restarting the program SheeppOSU 1 3,405 Jul-24-2020, 05:53 AM
Last Post: SheeppOSU
  ZIP file in Sqlite3 database chesschaser 4 3,426 Jul-23-2020, 09:53 PM
Last Post: chesschaser

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020