Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- create_str = "CREATE PROC sp_General_GetAllData (@table_name AS NVARCHAR(MAX),
- @year AS INT, @month AS INT, @pd AS INT)
- AS
- BEGIN
- SET NOCOUNT ON;
- DECLARE @sql NVARCHAR(MAX) # for later uses
- IF @table_name LIKE '%[^a-zA-Z0-9_]%'
- BEGIN
- # the 'log' table allows NULLs and the fields are used in other cases
- INSERT INTO [myDB].[mySchema].[log]
- VALUES (SUSER_SNAME(), NULL, NULL, NULL, NULL, NULL,
- 'INVALID TABLE NAME: ' + @table_name, GETDATE())
- RAISERROR ('Bad table name! Contact your friendly DBA for details', 0, 0)
- RETURN
- END
- # do some things if the @table_name is ok...
- END"
- cursor = sql_conn.execute(create_str)
- cursor.commit()
- # calling the SP from python - doesn't write to the log table which get stucked
- query = "{CALL sp_General_GetAllData (?, ?, ?, ?)}"
- data = pd.read_sql(query, sql_conn, params=['just*testing', 2019, 7, 2])
- # calling the SP from SSMS - works fine
- EXEC sp_General_GetAllData 'just*testing', 2019, 7, 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement