0

I'm trying to insert N"Pepito Malasanya O'Dhogerty" on Python 3 but cannot escape the single quote, the error on PYODBC is:

"Incorrect syntaxis".

I know that I have to add another one (O''Dhogerty) but I did my best trying everything I saw and didn't fix it.

That's what I did so far:

string = string.replace("'", "\\'\\'")

UPDATED:

It didn't work because I was using 'N' front of the string (because I have characters like "ª")

Now I have:

row[0] = row[0].replace("'","\'\'")

pyodbc.ProgrammingError: ('42S22', "[42S22] [Microsoft][ODBC SQL Server Driver][SQL Server]El nombre de columna 'Pepito Malasanya O''Dhogerty' no es válido. (207) (SQ LExecDirectW)")

What am I doing wrong? I'm going to check parameterized query as you said.

Dale K
  • 25,246
  • 15
  • 42
  • 71
M. Mariscal
  • 1,226
  • 3
  • 17
  • 46

1 Answers1

0

SOLUTION:

I was doing the execute method with '{}'.format... but it doesnt work with inserts with such special characters, i changed to cursor.execute("INSERT INTO table VALUES (?,?,?,?,?,?,?,?,?,?)",value1, value2....) and ANY PROBLEM

Thanks anyway for the help

M. Mariscal
  • 1,226
  • 3
  • 17
  • 46