开发者

How do i dump the contents of an SQLite database without using the command line, but in Perl code?

开发者 https://www.devze.com 2023-01-27 05:43 出处:网络
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 execut

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消