Mithaldu
Mithaldu

Reputation: 2410

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

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 activity only lead to guides using the sqlite executable. Is there a way in Perl to do this without the executable?

Upvotes: 0

Views: 572

Answers (2)

jira
jira

Reputation: 3944

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.

Upvotes: 2

Marcelo Cantos
Marcelo Cantos

Reputation: 185862

One option is to steal the .dump implementation from the sqlite program's source code.

Upvotes: 0

Related Questions