-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
163 lines (119 loc) · 3.36 KB
/
Copy pathmain.py
File metadata and controls
163 lines (119 loc) · 3.36 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import pyodbc
import time
# Configs
driver = 'SQL Server'
server = 'localhost\SQLEXPRESS'
db = 'PythonMsSQL'
user = 'sa'
password = 'P@ssw0rd'
# Create Connector
conn = None
try:
conn = pyodbc.connect('driver={%s};server=%s;database=%s;uid=%s;pwd=%s' % ( driver, server, db, user, password ) )
except:
pass
try:
conn = pyodbc.connect('driver={%s};server=%s;database=%s;trusted_connection=yes' % ( driver, server, db ))
except:
pass
if conn == None:
print('Connection Error.')
exit()
__start_time = None
__stop_time = None
cursor = conn.cursor()
# CRUD Query
def SelectCustomer():
cursor.execute('SELECT * FROM customer')
for row in cursor:
print(row)
def InsertCustomer(fname, lname, age, gender):
sql = F"""INSERT INTO Customer (Fname, Lname, Age, Gender)
VALUES ('{fname}', '{lname}', '{age}', '{gender}');"""
cursor.execute(sql)
cursor.commit()
pass
def UpdateCustomer(id, fname, lname, age, gender):
sql = F"""UPDATE Customer
SET Fname = '{fname}', Lname = '{lname}', Age = '{age}', Gender = '{gender}'
WHERE Id = '{id}';"""
cursor.execute(sql)
cursor.commit()
pass
def DeleteCustomer(id):
sql = F"""DELETE Customer WHERE Id = '{id}';"""
cursor.execute(sql)
cursor.commit()
pass
__data = []
class customerClass:
fname : str
lname : str
age : str
gender : str
def InsertTemp(fname, lname, age, gender):
temp = customerClass()
temp.fname = fname
temp.lname = lname
temp.age = age,
temp.gender = gender
__data.append(temp)
# Can Insert At 1000 rows
def InsertManyCustomer():
if(len(__data) <= 0):
return
row = 0
limit = 100
values = ''
count_insert = 1
for item in __data:
row += 1
if row >= limit :
print('Insert--->', count_insert)
count_insert+=1
values = ''
row = 0
else:
values += F"( '{item.fname}','{item.lname}','{item.age[0]}','{item.gender}' ),"
# values = ''
# for item in __data:
# i += 1
# print(i)
# if i < 1000 :
# total_insert += i
# i = 0
# else :
# print('a')
# print(i)
# # values += F"( '{item.fname}','{item.lname}','{item.age[0]}','{item.gender}' ),"
# # values = values[0:len(values) -1]
# # sql = F""" INSERT INTO Customer (fname, lname, age, gender)
# # VALUES {values}"""
# # cursor.execute(sql)
# # cursor.commit()
# # i = 0
# # values = ''
# print('End')
# EXECUTE Stored return Reuslt
# EXECUTE Stored No Parameter
# EXECUTE SQL Stored + Parameter
# SelectCustomer()
# InsertCustomer('F-Name', 'L-Name', '26', 'M')
# UpdateCustomer(11, 'NewFname', 'NewLastName', '30', 'F')
# DeleteCustomer(12)
def time_convert(sec):
mins = sec // 60
sec = sec % 60
hours = mins // 60
mins = mins % 60
return ("Time Lapsed = {0}:{1}:{2}".format(int(hours),int(mins),sec))
for x in range(950):
InsertTemp(F'FName{x}', F'LName{x}', 22 ,F'M')
__start_time = time.time()
InsertManyCustomer()
__stop_time = time.time()
time_lapsed = time_convert((__stop_time - __start_time))
print('Start', __start_time )
print('Stop', __stop_time )
print('TimeEnd', time_lapsed)
# SelectCustomer()