Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

cursor.execute(query, params) error while trying to set table name  #94

Copy link
Copy link
@cdonate

Description

@cdonate
Issue body actions

I'm trying to dynamically set the table name on my queries. To avoid SQL Injection I'm using the option curso.execute(query, params).

When I try to set the table name I get the error:

[PARSE_SYNTAX_ERROR] Syntax error at or near ''my_table_name''(line 1, pos 14)

== SQL ==
SELECT * FROM 'my_table_name'
--------------^^^

To reproduce:

with sql.connect(server_hostname=self.hostname, http_path=self.path, access_token=self.token) as connection:
    with connection.cursor() as cursor:
         cursor.execute("SELECT * FROM %(table_name)s", {"table_name": "my_table_name"})
         result = cursor.fetchall()

         for row in result:
             print(row)

It seems the table name can't have quotes. Only way I can do this is with:

cursor.execute("SELECT * FROM {}".format("my_table_name"))

Or other unsafe string substitution.

Am I doing something wrong?

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.