Advertisement
SipriusPT

SQL python DB submittion

Dec 20th, 2019
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. # Open sql_destination_file in read mode
  2. sql_destination_file_1 = open(destination_path + destination_file, 'r', encoding = 'utf-16')
  3. # Read sql_destination_file readlines
  4. sql_destination_file_content_1 = sql_destination_file_1.readlines()
  5.  
  6. # TEMP
  7. sql_copy_file = open(destination_path + 'SQL_copy.sql', 'w+', encoding = 'utf-16')
  8.  
  9. # SQL Server connection
  10. SQLdbconnection = pyodbc.connect(r'DRIVER={ODBC Driver 17 for SQL Server};SERVER=' + gfe_primavera_db_host + ';DATABASE=zrma;UID=' + gfe_primavera_db_username + ';PWD=' + gfe_primavera_db_password, autocommit=True)
  11. # Create a cursor from the connection
  12. SQLdbcursor = SQLdbconnection.cursor()
  13. for lines in sql_destination_file_content_1:
  14.     # TEMP
  15.     sql_copy_file.write('%s' % lines)
  16.  
  17.     # Print line by line
  18.     #print ("%s" %lines)
  19.     # Insert SQL to cursor along with SQL file
  20.     SQLdbcursor.executemany(%lines)
  21.     # Fetch the first row only
  22.     #print(SQLdbcursor.fetchone())
  23. # Close cursor and connection
  24. SQLdbcursor.close()
  25. SQLdbconnection.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement