Here is a start, save as sqlite.archive.pl and run md outdir && perl sqlite.archive.pl && ls outdir
#!/usr/bin/perl -- use strict; use warnings; use DBI; use FindBin; use autodie 1.999; chdir $FindBin::Bin; eval { # create/init test.sqlite #http://svn.ali.as/cpan/trunk/SQLite-Default/share/default.sql my $dbh = DBI->connect( 'dbi:SQLite:dbname=test.sqlite', undef, undef, { RaiseError => 1, PrintError => 1, } ); $dbh->do($_) for q~ create table foo ( id integer not null primary key, str varchar(255) null );~, q~ create table foobar ( id integer not null primary key, str varchar(255) null );~, q~insert into foo (id, str) values ( 1, 'value foo' );~, q~insert into foobar (id, str) values ( 1, 'value foobar' );~; }; #http://cpansearch.perl.org/src/ADAMK/SQLite-Archive-0.02/lib/SQLite/A +rchive.pm # ??? # SQLite::Archive->new(...)->create_dir('fromthisfile.sqlite','tothisd +ir'); create_dir( { csv_attr => ''}, 'test.sqlite', 'outdir' ); sub create_dir { use DBI; use DBD::SQLite; use Text::CSV_XS; # prereq for SQLite::Archive my ( $self, $file, $outdir ) = @_; my $dbh = DBI->connect("dbi:SQLite:dbname=$file"); my $tables = $dbh->selectall_arrayref( q~ SELECT name, sql FROM sqlite_master WHERE type='table' ORDER BY name; ~ ); use autodie; open OUT, '>', "$outdir/create.sql"; for my $ix ( 0 .. $#$tables ) { print OUT $tables->[$ix][1], ";\n"; } close OUT; for my $ix ( 0 .. $#$tables ) { my $table = $tables->[$ix][0]; open OUT, '>', "$outdir/$table.csv"; my $sth = $dbh->prepare( "select * from " . $dbh->quote($table +) ); if ( $sth->execute ) { my $csv = Text::CSV_XS->new( $self->{csv_attr} ); while ( my $ary_ref = $sth->fetchrow_arrayref ) { ## warn Dumper($ary_ref); $csv->print( \*OUT, $ary_ref ); } } close OUT; } ## use Data::Dumper; ## print Data::Dumper->new( [ $tables, $tables_sql ] )->Indent(1)-> +Dump; }

In reply to Re^2: making an SQLite::Archive? by Anonymous Monk
in thread making an SQLite::Archive? by azadian

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.