For regression testing i need to dump the entire contents of an SQLite database into a text file. But all references to that sort of act开发者_开发问答ivity only lead to guides using the sqlite executable. Is there a way in Perl to do this without the executable?
You can use the standard DBI methods for querying schema. DBD::SQLite manpage says:
See also to the DBI documentation for the details of other common methods.
table_info
$sth = $dbh->table_info(undef, $schema, $table, $type, \%attr);
Returns all tables and schemas (databases) as specified in "table_info" in DBI. The schema and table arguments will do a "LIKE" search. You can specify an ESCAPE character by including an ’Escape’ attribute in \%attr. The $type argument accepts a comma separated list of the following types
’TABLE’, ’VIEW’, ’LOCAL TEMPORARY’ and ’SYSTEM TABLE’ (by default all are returned). Note that a statement handle is returned, and not a direct
list of tables.
One option is to steal the .dump
implementation from the sqlite program's source code.
精彩评论