Coder77
Coder77

Reputation: 2333

SQLite3 in python - can't output

I'm having an issue with SQL in python, I am simply creating a table and I want to print it out. I'm confused D: I am using python 3.x

import sqlite3 


print ("-" * 80)
print ("-                        Welcome to my Address Book                     -")
print ("-" * 80)


new_db = sqlite3.connect('C:\\Python33\\test.db')
c = new_db.cursor()


c.execute('''CREATE TABLE Students
(student_id text,
student_firstname text,
student_surname text,
student_DOB date,
Form text)
''')

c.execute('''INSERT INTO Students
          VALUES ('001', 'John','Doe', '12/03/1992', '7S')''')
new_db.commit()
new_db.close()



input("Enter to close")

Upvotes: 0

Views: 116

Answers (1)

Aleksandar
Aleksandar

Reputation: 3661

firstname = "John"
surname   = "Foo"
c.execute("SELECT * FROM Students WHERE student_firstname LIKE ? OR student_surname LIKE ? ", [firstname, surname])
 while True:
    row = c.fetchone()
    if row == None:
        break# stops while loop if there is no more lines in table
    for column in row: #otherwise print line from table
            print col, " "

output should be:

001 John Doe 12/03/1992 7S

and any other row from table that contain first name John OR surname Foo

Upvotes: 1

Related Questions