Skip to content

dbWriteTable() is renaming the 'end' column

1 message · Seth Falcon

#
Hello all,

I'm picking up this discussion from late September regarding the name 
mangling behavior of dbWriteTable as seen in RSQLite (and probably 
RMySQL too).

Here's a summary of the current situation:

The DBI package provides a make.db.names generic as well as a default 
function, make.db.names.default.  Both RSQLite and RMySQL define a 
method that simply calls this default function.  Both packages use the 
generic inside their dbWriteTable implementations.

The default function uses base::make.names and a translation of "." to 
"_" to make SQL identifiers.  Any strings that are quoted (either single 
or double) are left as-is.  I'm not sure the quote handling is correct. 
  Single quotes are used for string literals in SQL and are not valid 
identifiers, where as double quotes are used to create delimited 
identifiers.

When SQL keywords are encountered and the allow.keywords argument is 
FALSE, the result is the unfortunate name mangling.

Here are some possible changes:

1. Modify DBI::make.db.names.default such that if allow.keywords=FALSE 
any keywords encountered will be quoted using '"'.

2. Make a similar modification, but make it specific to the 
make.db.names method implemented by RSQLite.

3. Move away from name mangling entirely and rely more heavily on 
quoting.  To keep backwards compatibility, add a new argument, say 
'names.as.is' with default value FALSE.  When TRUE, data.frame column 
names will be quoted instead of mangled.  This could be done in addition 
to items 1 or 2.

4. Instead of a new argument to dbWriteTable, add an argument to 
SQLite() to make this configuration of the driver.

Comments?

Also, below, a note on Sean's suggestion for a quoting global option...
On 9/30/09 9:19 AM, Sean Davis wrote:
I don't think there is enough SQL generated by RSQLite to make this 
particularly useful.  dbWriteTable is the main SQL generating function I 
think.  I'd prefer to avoid global options whenever possible and allow 
control via function args.  But something along these lines could be useful.

For example, the driver constructor, e.g. SQLite(), could accept an 
argument that set the desired name behavior for dbWriteTable.

In any case, thanks for the feedback.

+ seth