0

I have the following data element

 "In less than two minutes you can provide feedback to help us build the best customer service in healthcare.",
  "Based on your chat, how easy is your health plan to do business with?", "☹️", "", "", " ", "", "The survey has expired. Thank you for your time."

It throws the error

Unclosed quotation mark after the character string ''.

In sql server I have the record set as nvarchar to handle emojis. Do I need to append N to it as well? Here is my code

    def __insert_records(self, rows, target_fields):
        try:      
            mssql_connection = BaseHook.get_connection(self.mssql_conn_id)

            connection = pyodbc.connect(DRIVER='FreeTDS',host=mssql_connection.host,DATABASE=mssql_connection.schema,user=mssql_connection.login,password=mssql_connection.password,port=mssql_connection.port,driver='/usr/lib64/etc')
            cursor = connection.cursor()

            for i, row in enumerate(rows, 1):
                record = []

                for cell in row:
                    record.append(self._serialize_cell(cell))

                record_dictionary = self.__get_record_dictionary(record, target_fields)

                cursor.execute(self.__generate_insert_sql_statement(record_dictionary))

                connection.commit()

            cursor.close()
            connection.close()
        except pyodbc.ProgrammingError as programmingError:
            sqlstate = programmingError.args[0]
            if sqlstate = '42000':
                print(programmingError.args[0])
cluis92
  • 664
  • 12
  • 35
  • You anyway got SQL injection issues. Convert to using parameters instead of generating the insert on the fly, and your problem will also go away – Charlieface Feb 04 '21 at 14:58
  • Does this answer your question? [incorrect syntax near '' unclosed quotation mark after the character string ')'](https://stackoverflow.com/questions/28084206/incorrect-syntax-near-unclosed-quotation-mark-after-the-character-string) – Charlieface Feb 04 '21 at 14:59
  • 1
    i don't write Python, but Google is your friend. See https://stackoverflow.com/questions/1633332/how-to-put-parameterized-sql-query-into-variable-and-then-execute-in-python for example – Charlieface Feb 04 '21 at 15:06
  • 1
    Python supports parameterized statements. –  Feb 04 '21 at 16:30

1 Answers1

1

https://github.com/FreeTDS/freetds/issues/317

There is an issue with the FreeTDS driver that I am using. Attempting to update the mssql driver.

cluis92
  • 664
  • 12
  • 35