pymssql

How to execute an .sql file in pymssql

微笑、不失礼 提交于 2021-02-08 13:12:13
问题 I'm trying to execute an sql file in python using pymssql, this file contains a BEGIN TRANSACTION, a COMMIT TRANSACTION and an END, and some safety nets before and after. I'm trying to open the file in memory and execute the content: file = open(options.sqlFile, 'r') sqlFileContents = file.read() file.close() cursor.execute(sqlFileContents) conn.commit() But it's returning me errors: pymssql.ProgrammingError: (102, "Incorrect syntax near 'GO'.DB-Lib error message 102, severity 15:\nGeneral

How to execute an .sql file in pymssql

淺唱寂寞╮ 提交于 2021-02-08 13:05:15
问题 I'm trying to execute an sql file in python using pymssql, this file contains a BEGIN TRANSACTION, a COMMIT TRANSACTION and an END, and some safety nets before and after. I'm trying to open the file in memory and execute the content: file = open(options.sqlFile, 'r') sqlFileContents = file.read() file.close() cursor.execute(sqlFileContents) conn.commit() But it's returning me errors: pymssql.ProgrammingError: (102, "Incorrect syntax near 'GO'.DB-Lib error message 102, severity 15:\nGeneral

How to execute an .sql file in pymssql

删除回忆录丶 提交于 2021-02-08 13:03:55
问题 I'm trying to execute an sql file in python using pymssql, this file contains a BEGIN TRANSACTION, a COMMIT TRANSACTION and an END, and some safety nets before and after. I'm trying to open the file in memory and execute the content: file = open(options.sqlFile, 'r') sqlFileContents = file.read() file.close() cursor.execute(sqlFileContents) conn.commit() But it's returning me errors: pymssql.ProgrammingError: (102, "Incorrect syntax near 'GO'.DB-Lib error message 102, severity 15:\nGeneral

pymssql package does not work with lambda in aws

混江龙づ霸主 提交于 2021-02-08 08:29:41
问题 How do we create a pymssql package for lambda. I tried creating it using pip install pymssql -t . When I run my lambda function it complaints saying that Unable to import module 'lambda_function': No module named lambda_function I follow the steps on this link http://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html I have a windows machine 回答1: Glad that it worked for you, could you please share the working process for your, me too tried different trial

How to get the sql print message using pymssql

拟墨画扇 提交于 2021-02-08 05:02:24
问题 I'm running some queries, that print runtime stats from their execution. It's done through print('message') used within the sql script. I would want to see these messages while calling the procedures/scripts through pymssql. conn = pymssql.connect(server, user, password, "tempdb") cursor = conn.cursor() cursor.execute("print('message')") conn.commit() Above script doesn't return anything, and I can't find any tips on how to get that print to show up in the console output. 回答1: Found a

Passing parameters not being recognized and throws SQL error when executing raw query (on SQL-Server database and Pymssql) with SqlAlchemy

泪湿孤枕 提交于 2021-02-05 11:22:09
问题 I'm trying to execute simple raw SQL query, on SQL-Server db with SqlAlchemy (and Pymssql as provider). Here is my first try (using execute method of connection and passing parameters in **kwargs way): provider = DataProvider().engine q = "select url from Crawler.CrawlSource where source=@source" query = text(q) result = provider.connect().execute(query, source ='mysource') I passed the parameters in any way shown in tutorials (passing as kwargs and passing as dict) but neither of them worked

Apache Airflow - Connection issue to MS SQL Server using pymssql + SQLAlchemy

百般思念 提交于 2021-02-05 05:57:20
问题 I am facing a problem to connect to an Azure MS SQL Server 2014 database in Apache Airflow 1.10.1 using pymssql . I want to use the MsSqlHook class provided by Airflow, for the convenience to create my connection in the Airflow UI, and then create a context manager for my connection using SqlAlchemy : @contextmanager def mssql_session(dt_conn_id): sqla_engine = MsSqlHook(mssql_conn_id=dt_conn_id).get_sqlalchemy_engine() session = sessionmaker(bind=sqla_engine)() try: yield session except:

Apache Airflow - Connection issue to MS SQL Server using pymssql + SQLAlchemy

。_饼干妹妹 提交于 2021-02-05 05:56:05
问题 I am facing a problem to connect to an Azure MS SQL Server 2014 database in Apache Airflow 1.10.1 using pymssql . I want to use the MsSqlHook class provided by Airflow, for the convenience to create my connection in the Airflow UI, and then create a context manager for my connection using SqlAlchemy : @contextmanager def mssql_session(dt_conn_id): sqla_engine = MsSqlHook(mssql_conn_id=dt_conn_id).get_sqlalchemy_engine() session = sessionmaker(bind=sqla_engine)() try: yield session except:

pymssql executemany insert value very slow

我怕爱的太早我们不能终老 提交于 2021-01-28 18:16:14
问题 python-2.7.15, pymssql-2.1.4, SQL_Server-2018, Windows 10 Pro, MS-Office-2016 import time import csv import pymssql db_settings = { "host" : "127.0.0.1", "port" : "1433", "user" : "sa", "password" : "********", "database" : "testdb", "charset" : "utf8" } conn = pymssql.connect(**db_settings) cursor = conn.cursor() ff = csv.reader(open('base.csv', 'r')) sql = """ BEGIN INSERT INTO Base([name], [year], [update], [status], [timeline], [language], [pic]) VALUES (%s, %s, %s, %s, %s, %s, %s) END ""

Strings used in query always sent with NVARCHAR syntax, even if the underlying column is not unicode

谁说胖子不能爱 提交于 2021-01-27 22:19:03
问题 I'm noticing some odd behavior in the SQL generated for queries against string fields in MS SQL. Server version: SQL Server 2014 12.0.5000.0 Collation: SQL_Latin1_General_CP1_CI_AS Python version: 3.7 Our database has a mix of NVARCHAR (mostly newer) and VARCHAR (mostly older) fields. We are using SQLAlchemy to connect our Python application to the database, and even though we specify that a column is of type String (as opposed to Unicode ), the executed SQL always comes out in NVARCHAR