Use LOAD DATA LOCAL INFILE on python with dynamic tables
<p>I am trying to use a query directly on python to update my database, but I need to do a lot of time in different table:</p>

<pre><code>def load_data(self, path, table):
    print table
    print path
    cursor = self.mariadb_connection.cursor()
    cursor.execute(" LOAD DATA LOCAL INFILE %s INTO TABLE %s"
                   " FIELDS TERMINATED BY ','"
                   " ENCLOSED BY '"'"
                   " LINES TERMINATED BY '\n'"
                   " ignore 1 lines ",
                   (path, table))
</code></pre>

<p>The function do not recognize the third line and when I put like a comment the query do not understand the table. Have another way to do this query?</p>

<p>Below follow the solution that I found:</p>

<pre><code>cursor = self.mariadb_connection.cursor()
cursor.execute("LOAD DATA LOCAL INFILE % s"
                "INTO TABLE " + str(table) + " "
                "FIELDS TERMINATED BY ',' "
                "ENCLOSED BY '\"' "
                "LINES TERMINATED BY '\n' "
                "ignore 1 lines ",
                   path)
self.mariadb_connection.commit()
</code></pre>

<p>The three quotes could be a very good solution for a standard database, but I do  not know why the query on mariadb is not allowed when we use a dynamic table (using %s to call a table). </p>

<p>Another thing the program accept the changes only after the commit.</p>

<p>The only solutions that fits for me was this one. Thank you for your support.</p>

python mysql