Skip to content

Switch to the official Python package to connect with the server #27

@KartikSoneji

Description

@KartikSoneji

def run_command(self, code, timeout=-1, async_=False):
# Writing the cell code within a file and then sourcing it in the client
# offers us a lot of advantages.
# We avoid Pexpect's limitation of PC_MAX_CANON (1024) chars per line
# and we also avoid more nasty issues like MariaDB client behaviour
# sending continuation prompt when "\n" is received.

The current implementation of using the mariadb client cli has some limitations.

def run_statement(self, code, timeout=-1):

The run_statement doesn't support parameter substitution, which can lead to unintentional SQL injections while adding more magics:

use_csv_update_table_cmd = f"""LOAD DATA LOCAL INFILE '{self.csv_file_path}'

f"select * from {self.table_name} limit 5;"

Security is not as much of an issue, but it can lead to issues with some commands, for example if the file is named ' a.csv.
Trying to escape these edge cases in Python will lead to an imperfect re-implementation of the escaping logic like the original connector.

Ideally, the run_statement method should accept a list of substitution parameters like the Python connector

cur.execute("INSERT INTO test.accounts(first_name, last_name, email, amount) VALUES (?, ?, ?, ?)",
      (first_name, last_name, email, amount))

self.prompt = re.compile(r"MariaDB \[.*\]>[ \t]")

Listening for the MariaDB [] prompt causes some queries to never finish or truncate the output.
The Python connector will be more reliable as it is both officially supported and throughly tested.

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions