0

I am trying to import an .sql file with sqlite3, but I have problems since it contains escape characters

INSERT INTO `<table>` (`ext_id`, `street`, `street_number`, `city`, `country`)
VALUES 
    ('', 'Vicolo dell\'Ortaglia', '45', 'Brescia', 'IT'),
    ('', 'Via San Zeno', '73', 'Pavia', 'IT'),
    ('V2Z67B', 'Via Valli di Carnia', '', 'Amaro', 'IT'),
    ('3D004G', 'Via Emilia Piacentina - CC \"Il Castello\"', '', 'Castel San Giovanni', 'IT');

Some 'ext_id' are blank, and the street names can contains both ' or " (single or double quotes).

conn = sqlite3.connect(path)
f = open(filename, 'r')
sql = f.read()
conn.execute(sql)

If I open this file with sqlite3 I obtain this error

near "Ortaglia": syntax error

How can I import this file without loose single and double quotes in street names?

Thanks in advance!

0 Answers0