3

I'm somewhat stuck here. I'm using Python 3.9.0 with PyMySQL (0.10.1) and trying to create a function that creates a table. Every time I run the following statement:

        table = 'test'

        cursor = db.cursor()

        statement = """CREATE TABLE IF NOT EXISTS `%s` (
          `id` int NOT NULL AUTO_INCREMENT,
          `client_id` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
          `client_secret` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
          `security_token` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
          PRIMARY KEY (`id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;"""

        cursor.execute(statement, (table))

The table is created each time, but it creates it inside single quotes like 'test'. I need it to be created without quotes of course.

Anyone have any insights into why this is happening? Any help is much appreciated.

Thank you, Marko

Marko Bajlovic
  • 323
  • 5
  • 12
  • 1
    I suspect that is because it sees that the argument to the prepared statement is a string and therefore all it is doing is outputting the string representation of its argument after doing any necessary escaping of single quote characters and doesn't really appreciate the context in which it is being used, i.e. not as a column value. – Booboo Jan 08 '21 at 19:21

0 Answers0