forked from exasol/pyexasol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patha07_exceptions.py
94 lines (76 loc) · 2.09 KB
/
a07_exceptions.py
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
"""
Exceptions for basic queries
"""
import pyexasol
import _config as config
import pprint
printer = pprint.PrettyPrinter(indent=4, width=140)
# Bad dsn
try:
C = pyexasol.connect(dsn='123' + config.dsn, user=config.user, password=config.password, schema=config.schema)
except pyexasol.ExaConnectionError as e:
print(e)
# Bad user \ password
try:
C = pyexasol.connect(dsn=config.dsn, user=config.user, password='123' + config.password, schema=config.schema)
except pyexasol.ExaAuthError as e:
print(e)
C = pyexasol.connect(dsn=config.dsn, user=config.user, password=config.password, schema=config.schema,
fetch_size_bytes=1024 * 10)
# Invalid SQL
try:
stmt = C.execute("""
SELECT1 *
FROM users
ORDER BY user_id
LIMIT 5
""")
except pyexasol.ExaQueryError as e:
print(e)
# Valid SQL, but error during execution
try:
stmt = C.execute("""
SELECT *
FROM users
WHERE user_name = 10
ORDER BY user_id
LIMIT 5
""")
except pyexasol.ExaQueryError as e:
print(e)
# Attempt to read from closed cursor
stmt = C.execute("SELECT * FROM payments")
stmt.fetchone()
stmt.close()
try:
stmt.fetchall()
except pyexasol.ExaRequestError as e:
print(e)
# Attempt to fetch query without result set
stmt = C.execute("COMMIT")
try:
stmt.fetchone()
except pyexasol.ExaRuntimeError as e:
print(e)
# Attempt to run SELECT with duplicate column names
try:
stmt = C.execute("""
SELECT 1, 1, 2 AS user_id, 3 AS user_id
FROM dual
""")
except pyexasol.ExaRuntimeError as e:
print(e)
# Attempt to run query on closed connection
C.close()
try:
C.execute("SELECT 1")
except pyexasol.ExaRuntimeError as e:
print(e)
# Simulate websocket error during close
C1 = pyexasol.connect(dsn=config.dsn, user=config.user, password=config.password, schema=config.schema)
C2 = pyexasol.connect(dsn=config.dsn, user=config.user, password=config.password, schema=config.schema)
C2.execute(f'KILL SESSION {C1.session_id()}')
try:
C1.close()
except pyexasol.ExaError as e:
print(e)