def test_load_from_file(self): q1 = MySQLQuery.load("/path/to/file").into("abc") q2 = MySQLQuery.load("/path/to/file").into(self.table_abc) self.assertEqual( "LOAD DATA LOCAL INFILE '/path/to/file' INTO TABLE `abc` FIELDS TERMINATED BY ','", str(q1), ) self.assertEqual( "LOAD DATA LOCAL INFILE '/path/to/file' INTO TABLE `abc` FIELDS TERMINATED BY ','", str(q2), )
def import_csv(self, table, file_path, connection=None): """ Execute a query to import a file into a table using the provided connection. :param table: The name of a table to import data into. :param file_path: The path of the file to be imported. :param connection: (Optional) The connection to execute this query with. """ import_query = MySQLQuery.load(file_path).into(table) self.execute(str(import_query), connection=connection)