-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlesson30.py
More file actions
31 lines (24 loc) · 840 Bytes
/
Copy pathlesson30.py
File metadata and controls
31 lines (24 loc) · 840 Bytes
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
import psycopg2
connection = psycopg2.connect(host='localhost', database='postgres', port=5432, user='postgres', password='postgres')
cursor = connection.cursor()
cursor.execute('SELECT * FROM person')
print(cursor.fetchone())
print(cursor.fetchone())
print(cursor.fetchall())
cursor.execute('SELECT * FROM person')
print(cursor.fetchone())
print(cursor.fetchone())
print(cursor.fetchall())
name = 'Zidan); Drop table players; --'
cursor.execute("INSERT INTO players(name) values(%s)", (name, ))
names = [('name1', ), ('name2', ), ('name3', )]
cursor.executemany(f"INSERT INTO players(name) values(%s)", names)
connection.commit()
try:
cursor.execute('CREATE TABLE players (id serial primary key, name varchar(100))')
cursor.close()
connection.commit()
except:
print('Ha')
connection.rollback()
connection.close()