Advertisement
Guest User

Untitled

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