Perl DBI without accessing the database

前端 未结 6 1936
悲哀的现实
悲哀的现实 2021-01-18 16:08

I\'m creating a set of SQL INSERT statements for a database that doesn\'t exist yet, and I\'m saving them to file.

How can I use Perl\'s powerful DBI m

6条回答
  •  一生所求
    2021-01-18 16:47

    Unfortunately, the actual quote() behaviour isn't always a portable characteristic, so each driver will do them differently. Unless you connect to a driver, you don't know which quoting format to use in practice. (There is one module that might do this without a connection, DBIx::Abstract, but it is not especially current.).

    The quote() method is actually implemented by the corresponding driver class, in the DBD::* namespace. You might attempt to load the driver you need and call the function directly (see http://search.cpan.org/~timb/DBI-1.616/lib/DBI/DBD.pm#Writing_DBD::Driver::db::quote) but this feels grubby.

    I'd still make a DBI connection, if only so that you get the right format of quoting. You don't need to actually send it any statements, but then you do know that the quoting format will be correct for the database you will use.

提交回复
热议问题