generating SQL - problem

Michael Linnemann m.linnemann at addcom.de
Thu Aug 9 10:13:05 EDT 2001


Am Wed, 08 Aug 2001 22:07:57 +0100 Lee wrote:

>I wonder if someone could offer me a little advice. I have a large
>(155KB) text file holding MP3 data in the format:

>Filename with path   ; Title    ; Artistd
>d:\\SRS\\Breed.mp3      ; Breed         ; Snake River Conspiracy

>I want to parse this file and create a single SQL insert statement, but
>I am having a few problems. I have the following script, which works
>fine (may not be pretty, but it works ;-)

A very short (and fast) solution looks like:

"copy tablename from /path/to/your/file using delimiters ';'";

That ist postgresql-syntax, but other databases offer similar commands
("load data infile...", "copy from stdin...").

> [...]

># |     FullSQL = FullSQL + SQL + ";"

The ";" ends the SQL command; so why not send it to the database, check
for errors, and then try the next? It would be far easier to collect the
rejected lines this way. In _my_ files at least, there are always bad
lines.

Regards
Michael



More information about the Python-list mailing list