Last active
December 20, 2021 10:08
Check pyodbc + ignite odbc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pyodbc | |
with pyodbc.connect('DRIVER={Apache Ignite};SERVER=127.0.0.1;PORT=10800;SCHEMA=PUBLIC;') as conn: | |
conn.setencoding(encoding='utf-8') | |
cursor = conn.cursor() | |
try: | |
cursor.execute("CREATE TABLE IF NOT EXISTS PERSON(ID INT PRIMARY KEY, FIRSTNAME VARCHAR(100), LASTNAME VARCHAR(100), AGE INT)") | |
assert 'PERSON' in set(row[2] for row in cursor.tables().fetchall()) | |
cursor.execute("INSERT INTO PERSON (ID, FIRSTNAME, LASTNAME, AGE) VALUES (1, 'John', 'Doe', 18)") | |
cursor.execute("INSERT INTO PERSON (ID, FIRSTNAME, LASTNAME, AGE) VALUES (2, 'Jane', 'Doe', 25)") | |
cursor.execute("INSERT INTO PERSON (ID, FIRSTNAME, LASTNAME, AGE) VALUES (3, 'Baby', 'Doe', 2)") | |
print("Print all") | |
print("-" * 50) | |
cursor.execute("SELECT * FROM PERSON") | |
for row in cursor.fetchall(): | |
print(row) | |
print('\n') | |
print("All adults") | |
print("-" * 50) | |
cursor.execute("SELECT * FROM PERSON WHERE AGE >= ?", 18) | |
for row in cursor.fetchall(): | |
print(row) | |
finally: | |
cursor.execute("DROP TABLE IF EXISTS PERSON") | |
assert 'PERSON' not in set(row[2] for row in cursor.tables().fetchall()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment