-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqlscr.py
More file actions
117 lines (81 loc) · 1.9 KB
/
Copy pathsqlscr.py
File metadata and controls
117 lines (81 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# # Step 1 : import module
# import pymysql as p
# # #cx_Oracle
# #
# # # Step 2 : connect to database
# santhoshdb = p.connect(host = 'localhost', user = 'root', password = 'root', db = 'santhosh')
# print("connected successfully")
#
#
# #
# # # Step3 : create cursor
# mycursor = santhoshdb.cursor()
#
#
# # # # # #### selelect query ....
# # # # Step 4 : Prepare the query
# q1 = [
# 'select * from login;',
# 'select count(*) from login;',
# 'select email,password from login where name = "sandy";',
# 'select * from login where name = "santhosh";'
# ]
#
# for query in q1:
#
# # Step 5 : execute the query
# mycursor.execute(query)
#
# # Step 6 : fetch all result
# res = mycursor.fetchall()
# print(res)
#
#
# # Step7 : close DB
# santhoshdb.close()
#### dml statements
#
# #step 1
import pymysql as p
# Step 2 : connect to database
db = p.connect(host = 'localhost', user = 'root', password = 'root', db = 'santhosh')
print("connected successfully")
# Step3 : create cursor
mycursor = db.cursor()
##### insert query
# Step 4 : insert the data
# q1 = [
# "INSERT INTO login (id, name, email, password) VALUES (11, 'Venkat','venkat@gmail.com','venkat@987');",
# "INSERT INTO login (id, name, email, password) VALUES (12, 'gokul','gokul@gmail.com','gukul@880');",
# ]
q1 = [
"""
CREATE TABLE Ashwini (
PersonID int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
);
""",
"""
CREATE TABLE Ameen (
PersonID int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
);
"""
]
# Step 5 : execute the query
for x in q1:
try:
mycursor.execute(x)
except Exception as err:
print("error msg was = ", err)
# Step 6 : commit
db.commit()
# Step 7 : Close DB
db.close()
print("successfully inserted ")