|
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | 1 | import sqlite3 |
6 | 2 |
|
| 3 | + |
7 | 4 | def main(): |
8 | | - db=sqlite3.connect("information.db") |
9 | | - db.row_factory=sqlite3.Row |
| 5 | + # Connection to a database called information.db |
| 6 | + db = sqlite3.connect("information.db") |
| 7 | + # row_factory returns everything as a ditionary rather that a tuple. |
| 8 | + db.row_factory = sqlite3.Row |
| 9 | + # creates a table with 4 columns. |
| 10 | + # Name would be text and age would be int. |
10 | 11 | db.execute("create table if not exists Admin(Name text,age int)") |
11 | | - db.execute("insert into Admin (Name,age) values (? , ?)",("Hussein",26)) |
12 | | - db.execute("insert into Admin (Name,age) values (? , ?)",("Jena",1)) |
| 12 | + db.execute("insert into Admin (Name,age) values (? , ?)", ("Hussein", 26)) |
| 13 | + db.execute("insert into Admin (Name,age) values (? , ?)", ("Jena", 1)) |
13 | 14 | db.commit() |
14 | | - #db.execute("delete from Admin where name='Jena'") |
15 | | - #db.execute("Update Admin set age=2 where name='Jena'") |
16 | | - cusror=db.execute("select * from Admin") |
17 | | - for row in cusror: |
18 | | - print("Name:{}, Age:{}".format(row["Name"],row["age"])) |
| 15 | + # You could delete the entire row with Jena a the Name. |
| 16 | + # db.execute("delete from Admin where name='Jena'") |
19 | 17 |
|
| 18 | + # db.execute("Update Admin set age=2 where name='Jena'") |
20 | 19 |
|
| 20 | + # Selecting all from admin |
| 21 | + cusror = db.execute("select * from Admin") |
| 22 | + for row in cusror: |
| 23 | + print("Name:{}, Age:{}".format(row["Name"], row["age"])) |
21 | 24 |
|
22 | 25 |
|
23 | | -if __name__ == '__main__':main() |
| 26 | +if __name__ == "__main__": |
| 27 | + main() |
0 commit comments