| 8 | |
| 9 | |
| 10 | class TestLoadLocal(base.PyMySQLTestCase): |
| 11 | def test_no_file(self): |
| 12 | """Test load local infile when the file does not exist""" |
| 13 | conn = self.connect() |
| 14 | c = conn.cursor() |
| 15 | c.execute("CREATE TABLE test_load_local (a INTEGER, b INTEGER)") |
| 16 | try: |
| 17 | self.assertRaises( |
| 18 | OperationalError, |
| 19 | c.execute, |
| 20 | ( |
| 21 | "LOAD DATA LOCAL INFILE 'no_data.txt' INTO TABLE " |
| 22 | "test_load_local fields terminated by ','" |
| 23 | ), |
| 24 | ) |
| 25 | finally: |
| 26 | c.execute("DROP TABLE test_load_local") |
| 27 | c.close() |
| 28 | |
| 29 | def test_load_file(self): |
| 30 | """Test load local infile with a valid file""" |
| 31 | conn = self.connect() |
| 32 | c = conn.cursor() |
| 33 | c.execute("CREATE TABLE test_load_local (a INTEGER, b INTEGER)") |
| 34 | filename = os.path.join( |
| 35 | os.path.dirname(os.path.realpath(__file__)), "data", "load_local_data.txt" |
| 36 | ) |
| 37 | try: |
| 38 | c.execute( |
| 39 | f"LOAD DATA LOCAL INFILE '{filename}' INTO TABLE test_load_local" |
| 40 | + " FIELDS TERMINATED BY ','" |
| 41 | ) |
| 42 | c.execute("SELECT COUNT(*) FROM test_load_local") |
| 43 | self.assertEqual(22749, c.fetchone()[0]) |
| 44 | finally: |
| 45 | c.execute("DROP TABLE test_load_local") |
| 46 | |
| 47 | def test_unbuffered_load_file(self): |
| 48 | """Test unbuffered load local infile with a valid file""" |
| 49 | conn = self.connect() |
| 50 | c = conn.cursor(cursors.SSCursor) |
| 51 | c.execute("CREATE TABLE test_load_local (a INTEGER, b INTEGER)") |
| 52 | filename = os.path.join( |
| 53 | os.path.dirname(os.path.realpath(__file__)), "data", "load_local_data.txt" |
| 54 | ) |
| 55 | try: |
| 56 | c.execute( |
| 57 | f"LOAD DATA LOCAL INFILE '{filename}' INTO TABLE test_load_local" |
| 58 | + " FIELDS TERMINATED BY ','" |
| 59 | ) |
| 60 | c.execute("SELECT COUNT(*) FROM test_load_local") |
| 61 | self.assertEqual(22749, c.fetchone()[0]) |
| 62 | finally: |
| 63 | c.close() |
| 64 | conn.close() |
| 65 | conn.connect() |
| 66 | c = conn.cursor() |
| 67 | c.execute("DROP TABLE test_load_local") |
nothing calls this directly
no outgoing calls
no test coverage detected