Skip to main content

snippets_py

Integration

New integration from credential
mssql_connection = yepcode.integration.mssql('credential-slug')
New integration from plain authentication data
import pymssql

mssql_connection = pymssql.connect(server='localhost', user='sa', password='Pass@word', database='master')

SELECT Text Only

SELECT Text only
cursor = mssql_connection.cursor()
try:
cursor.execute('SELECT name, price FROM products')
row = cursor.fetchone()
while row:
print(str(row[0]) + " " + str(row[1]))
row = cursor.fetchone()
except (pymssql.Error as error):
print(error)

mssql_connection.close()

SELECT Parameterized

SELECT Parameterized
cursor = mssql_connection.cursor()
try:
cursor.execute('SELECT * FROM products WHERE name = %s', ('awesome-product-name'))
row = cursor.fetchone()
while row:
print('row = %r' % (row,))
row = cursor.fetchone()
except (pymssql.Error as error):
print(error)

mssql_connection.close()

INSERT Text Only

INSERT Text only
cursor = mssql_connection.cursor()
try:
cursor.execute('INSERT INTO products(name, price, stock, created_at) VALUES('awesome-product-name', 14, 99, CURRENT_TIMESTAMP)')
mssql_connection.commit()
except (pymssql.Error as error):
print(error)

mssql_connection.close()

INSERT Parameterized

INSERT Parameterized
cursor = mssql_connection.cursor()
query = 'INSERT INTO products(name, price, stock, created_at) VALUES(%s, %s, %s, CURRENT_TIMESTAMP)'
try:
cursor.execute(query, ('awesome-product-name', 14, 99))
mssql_connection.commit()
except (pymssql.Error as error):
print(error)

mssql_connection.close()