sql_delete

Commands ››
Parent Previous Next

The sql_delete command is used to generate SQL DELETE statements from CSV data. The CSV fields are used to specify the WHERE clause of the DELETE statement.

See also: sql_insert, sql_update

Flag

Req'd?

Description

-t table

Yes

Specifies the name of the SQL table to use in the UPDATE statement.

-w fields

Yes

Specifies the fields that will be used to generate the WHERE clause of the UPDATE statement. The list is comma-separated, with each pair being colon-separated. For example:

-f 1:name,2:rank,5:serialno

-s separator

No

Specifies the separator that will be appended to the end of each statement. By default this is a new line followed by a semicolon. If your database requires COMMITs after each insert, you could use something like this:

-s '\n;\nCOMMIT\n\;\n'

-nq fields

No

Turns off SQL quoting. See the sql_insert command for full description.

-qn

No

Specifies that the special value NULL should be quoted. By default CSVfix does not quote the NULL string (in whatever case).



The following example generates DELETE statements from the names.csv file. The SQL table is the same as that used in the example for sql_update:

csvfix sql_delete -t mailing -w 1:fname,2:sname data/names.csv

which produces:

DELETE FROM mailing WHERE fname = 'Charles' AND sname = 'Dickens'
;
DELETE FROM mailing WHERE fname = 'Jane' AND sname = 'Austen'
;
DELETE FROM mailing WHERE fname = 'Herman' AND sname = 'Melville'
;
DELETE FROM mailing WHERE fname = 'Flann' AND sname = 'O''Brien'
;
DELETE FROM mailing WHERE fname = 'George' AND sname = 'Elliot'
;
DELETE FROM mailing WHERE fname = 'Virginia' AND sname = 'Woolf'
;
DELETE FROM mailing WHERE fname = 'Oscar' AND sname = 'Wilde'
;

Created with the Personal Edition of HelpNDoc: Easily create iPhone documentation