| Message: 90451 |
 |
BY: Mike Pomraning (pilcrow) DATE: 2009-09-22 03:03 SUBJECT: RE: Running an external .sql file > Is there a way to execute an external .sql
> file? I tried using something like
> dbh.execute("start some_file.sql") but
> that didn't seem to work.
No, not unless your driver supports a driver-specific extension like
dbh.func(:run_batch_file, sql_fn)
> If this should be a bug or feature request
> let me know and I'll submit it properly.
I don't think such a feature, handy as it is, is within the DBI's purview.
AFAIK, native db interfaces (libpq-fe.h, sqlite3.h) and driver abstractions (perl-DBI, JDBC) don't offer such functionality, but leave it to separate utilities (unixODBC's isql, hsql's SqlTool, MySQL's mysql).
So, absent driver support for parsing commands out of files, the DBI would need to grok encoding, quoting and line-termination conventions
for this and that db, just to pull out queries. That's easy 90% of the time, but hard with weird quoting or, say, DELIMITERs for stored procedure definitions.
The end-user, however, usually knows his or her .sql files quite well, and can pull out queries one-at-a-time in a fashion that's good enough for those .sql files.
(The next problem is users. :) They invariably want to substitute variables in the SQL, and then it evolves into something like perl's Data::Phrasebook::SQL or CAM::SQLManager's XML format. Those aren't bad things, but they aren't the DBI -- they sit atop it.)
-Mike | |