in reply to Re^3: help figuring out what a section of script does
in thread help figuring out what a section of script does
I get an error on line 17 "no such table: image" so i looked at the DB, and there is a table name 'image'. It's structured thusly: CREATE TABLE image (a int, b int, c int, d int, tileset int, retrieved int, current bool, etag text, size int, data blob, UNIQUE(a, b, c, d) ON CONFLICT REPLACE); CREATE UNIQUE INDEX index_abcd on image (a, b, c, d); CREATE INDEX index_tileset on image (tileset); CREATE INDEX index_retrieved_tileset on image (retrieved, tileset);
So we open up the table image, and dump the field data, right?
#!perl use strict; use DBI; my $database = 'MapTiles.sqlitedb'; my $tablename = 'image'; # open db my $dbh = open_db($database); my $imgfolder = 'maptiles-output'; if (! -d $imgfolder){ mkdir($imgfolder, 0755) or die "$!"; } # select data my $sql = 'SELECT data from '.$tablename; my $sth = $dbh->prepare($sql); $sth->execute(); # recreate files while (my ($zoom, $x, $y, $flags, $length, $data) = $sth->fetchrow_arr +ay){ my $filename = "$imgfolder/$x,$y\@$zoom.png"; print "creating $filename\n"; open OUT,'>:raw',$filename or die "$filename : $!"; print OUT $data; close OUT; } # open db sub open_db { my $dbfile = shift; my $dbh = DBI->connect( "dbi:SQLite:dbname = $dbfile", "", "", { RaiseError => 1 } ) or die $DBI::errstr; return $dbh; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: help figuring out what a section of script does
by AnomalousMonk (Archbishop) on Mar 23, 2017 at 20:04 UTC | |
|
Re^5: help figuring out what a section of script does
by poj (Abbot) on Mar 23, 2017 at 19:35 UTC |