-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c1e7f8e
commit f5c461b
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import turbodbc | ||
from time import perf_counter | ||
|
||
|
||
def turbodbc_read_sql( | ||
query: str, turbodbc_connection: turbodbc.connection.Connection | ||
): | ||
with turbodbc_connection.cursor() as cursor: | ||
cursor.execute(query) | ||
return cursor.fetchallarrow().to_pandas() | ||
|
||
|
||
def mssql_connect_turbodbc() -> turbodbc.connection.Connection: | ||
odbc_string = "Driver={libtdsodbc.so};Server=localhost,1433;Database=turbodbc;Encrypt=yes;TrustServerCertificate=no;UID=sa;PWD=QuantCo123" | ||
conn_string_components = { | ||
x.split("=")[0].lower(): x.split("=")[1] for x in odbc_string.split(";") | ||
} | ||
return turbodbc.connect( | ||
**conn_string_components, | ||
turbodbc_options=turbodbc.make_options( | ||
prefer_unicode=True, large_decimals_as_64_bit_types=True | ||
), | ||
) | ||
|
||
|
||
connection = mssql_connect_turbodbc() | ||
start = perf_counter() | ||
turbodbc_read_sql("SELECT * FROM turbodbc.dbo.single_big", connection) | ||
print("Elapsed seconds:", perf_counter() - start) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import sqlalchemy as sa | ||
|
||
print("Hey") | ||
|
||
ROWS = 1_000_000 | ||
AT_ONCE = 1 | ||
|
||
eng = sa.create_engine("mssql+pyodbc://sa:QuantCo123@localhost:1433/turbodbc?driver=libtdsodbc.so") | ||
|
||
with eng.begin() as transaction: | ||
transaction.execute(sa.text("DELETE FROM single_big")) | ||
last = None | ||
for idx in range(0, ROWS, AT_ONCE): | ||
percentage = int(idx/ROWS * 100) | ||
if percentage % 10 == 0 and percentage != last: | ||
last = percentage | ||
print(percentage) | ||
|
||
value = "a" * 8_000 | ||
param = ", ".join([f"('{value}') "] * AT_ONCE) | ||
transaction.execute(sa.text(f"INSERT INTO single_big VALUES {param}")) |