Created
May 19, 2019 02:24
-
-
Save nathairtras/ffdc94f085d1bd8df09386206889b0d0 to your computer and use it in GitHub Desktop.
Revisions
-
nathairtras created this gist
May 19, 2019 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ import os import pytds # Grabbing the user and password from environment variables # Load these however you would like server = os.environ["MSSQL_SERVER"] user = os.environ["MSSQL_USER"] password = os.environ["MSSQL_PASS"] # Fake some rows, these could be from CSV rows = [ ["abc"], ["def"], ["ghi"], ] # Make a connection with pytds.connect(server=server, user=user, password=password, autocommit=True) as cnx: # Create a cursor with cnx.cursor() as cur: # Create the TVP from the rows tvp = pytds.TableValuedParam(type_name='dbo.StringList', rows=rows) # Use the TVP in a query / exec cur.execute('SELECT * FROM %s', (tvp,)) # Prove we got rows back print(cur.fetchall())