I am executing below code using ctrlM job then I am experiencing
pyodbc.ProgrammingError: ('42000', "[42000] [FreeTDS][SQL Server]Incorrect syntax near ';'.
(102) (SQLExecDirectW)")
error whereas the same code when run in vscode is working fine.
logger = Logger.get_logger(processCode.LOG_PURGE_PROCESS.value, __name__)
d = "dateadd(mm, -1, getdate())"
params = UtilityLib.open_param_file(configFiles.PROJECT.value, logger)
path = params['LogFile']
open_connection_error_constant = 'Error occurred when opening connection to database : '
with open(path) as csv_file:
r = csv.DictReader(csv_file)
for row in r:
connection_params = row['database']
if connection_params is not None:
deletesql = "delete from " + str(row["tablename"]) + " where log_chg_dtm < = " + d + " ;"
print(deletesql)
cnxn = DBManagement.set_db_connection(connection_params, logger)
try:
result = PostgresqlQueryAssist.sql_delete(cnxn, deletesql, logger)
print('deleted records from table:', row["tablename"])
except pyodbc.Error as ex:
logger.exception(open_connection_error_constant + str(ex))
raise
finally:
cnxn.close()
My config file name is passed in csv file, after reading the file, connections are like :
"DBMSType": "SYBASE",
"serverName": "test",
"databaseName": "treat",
"port": "1000",
"userID": "user",
"password": "pswd"
After removing ; at the end of the query resolved the issue.