Skip to content

Commit ef537cb

Browse files
Hasith RathnayakeHasith Rathnayake
Hasith Rathnayake
authored and
Hasith Rathnayake
committed
Ex 1 final for week 2
1 parent 02d698f commit ef537cb

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

.DS_Store

8 KB
Binary file not shown.
8 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,32 @@
11
import sqlite3
2-
connection=sqlite3.connect('Ages')
2+
3+
connection=sqlite3.connect('Ages.sqlite')
4+
cur=connection.cursor()
5+
6+
#if the db exists then override
7+
#then create a table and 2 columns name and age
8+
cur.execute('DROP TABLE IF EXISTS Ages')
9+
cur.execute('CREATE TABLE Ages (name VARCHAR(128), age INTEGER)')
10+
11+
#Entering data
12+
data='''DELETE FROM Ages;INSERT INTO Ages (name, age) VALUES ('Naomie', 13);
13+
INSERT INTO Ages (name, age) VALUES ('Raonaid', 20);
14+
INSERT INTO Ages (name, age) VALUES ('Kellsey', 20);
15+
INSERT INTO Ages (name, age) VALUES ('Youer', 22);
16+
INSERT INTO Ages (name, age) VALUES ('Elody', 25);'''
17+
18+
sqlcmds=data.split(';')
19+
cleanSqlcmds=list()
20+
for item in sqlcmds[1:-1]:
21+
item=item.strip('\n')
22+
cur.execute(item)
23+
#commit to disk
24+
connection.commit()
25+
26+
#view db
27+
for row in cur.execute('SELECT name, age FROM Ages ORDER BY age'):
28+
print(str(row[0]), row[1])
29+
#for getting marks
30+
for row in cur.execute('SELECT hex(name||age) AS X FROM Ages ORDER BY X'):
31+
print(str(row[0]))
32+
break #print just one

0 commit comments

Comments
 (0)