Skip to content

Commit ffdd020

Browse files
committed
update
1 parent faa2de0 commit ffdd020

File tree

14 files changed

+117
-0
lines changed

14 files changed

+117
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CREATE TABLE "dept" (
2+
"deptno" INTEGER NOT NULL,
3+
"deptname" TEXT NOT NULL,
4+
PRIMARY KEY("deptno" AUTOINCREMENT)
5+
);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import sqlite3
2+
3+
conn = sqlite3.connect('employee.db')
4+
print "Opened database successfully";
5+
6+
conn.execute('CREATE TABLE students (name TEXT, addr TEXT, city TEXT, pin TEXT)')
7+
print "Table created successfully";
8+
conn.close()
Binary file not shown.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
INSERT INTO dept (deptname)
2+
VALUES ('Accounts');
3+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SELECT * FROM dept WHERE deptno >1 ;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
UPDATE dept set deptname = 'Sales & Marketing'
2+
WHERE deptno=1 ;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from flask import *
2+
import sqlite3
3+
4+
app = Flask(__name__)
5+
6+
@app.route("/")
7+
def index():
8+
return render_template("index.html");
9+
10+
@app.route("/add")
11+
def add():
12+
return render_template("add.html")
13+
14+
@app.route("/savedetails",methods = ["POST","GET"])
15+
def saveDetails():
16+
msg = "msg"
17+
if request.method == "POST":
18+
try:
19+
name = request.form["name"]
20+
email = request.form["email"]
21+
address = request.form["address"]
22+
with sqlite3.connect("employee.db") as con:
23+
cur = con.cursor()
24+
#qry = "INSERT into students (name, email, address) values (?,?,?)",(name,email,address)
25+
#msg = qry
26+
cur.execute("INSERT into students (name, email, address) values (?,?,?)",(name,email,address))
27+
28+
con.commit()
29+
msg = " Student successfully Added "
30+
except:
31+
con.rollback()
32+
msg = " can not add the student to the list"
33+
finally:
34+
return render_template("success.html",msg = msg)
35+
con.close()
36+
37+
@app.route("/view")
38+
def view():
39+
con = sqlite3.connect("employee.db")
40+
con.row_factory = sqlite3.Row
41+
cur = con.cursor()
42+
cur.execute("select * from students ")
43+
rows = cur.fetchall()
44+
return render_template("view.html",rows = rows)
45+
46+
if __name__ == "__main__":
47+
app.run()
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import sqlite3
2+
3+
conn = sqlite3.connect('employee.db')
4+
print "Opened database successfully";
5+
6+
conn.execute('CREATE TABLE students (name TEXT, addr TEXT, city TEXT, pin TEXT)')
7+
print "Table created successfully";
8+
conn.close()
Binary file not shown.

ClassExamples/PJ128_AIML6m_Jan21/flask/flaskSQLite_2/student.db

Whitespace-only changes.

0 commit comments

Comments
 (0)