60 lines
1.6 KiB
Perl
60 lines
1.6 KiB
Perl
#! /usr/bin/perl
|
|
# $OpenBSD: rebuild_schema,v 1.3 2019/03/15 11:29:53 espie Exp $
|
|
#
|
|
# Copyright (c) 2018 Marc Espie <espie@openbsd.org>
|
|
#
|
|
# Permission to use, copy, modify, and distribute this software for any
|
|
# purpose with or without fee is hereby granted, provided that the above
|
|
# copyright notice and this permission notice appear in all copies.
|
|
#
|
|
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
# example script that shows how to store all variable values into a
|
|
# database, using SQLite for that purpose.
|
|
#
|
|
# usage: cd /usr/ports && mksqlitedb
|
|
|
|
use strict;
|
|
use warnings;
|
|
use FindBin;
|
|
use lib $FindBin::Bin;
|
|
use Getopt::Std;
|
|
use Var;
|
|
use Inserter;
|
|
use DBI;
|
|
use PkgPath;
|
|
use Info;
|
|
use Trace;
|
|
|
|
|
|
package main;
|
|
|
|
our ($opt_v, $opt_q, $opt_p, $opt_V);
|
|
|
|
Trace->setup(\%SIG);
|
|
getopts('vq:p:V:');
|
|
my $dbname;
|
|
if (@ARGV == 1) {
|
|
$dbname = shift;
|
|
} elsif (@ARGV == 0) {
|
|
$dbname = 'sqlports';
|
|
} else {
|
|
exit 1;
|
|
}
|
|
|
|
my $db = DBI->connect("dbi:SQLite:dbname=$dbname", '', '', {AutoCommit => 0});
|
|
my $inserter = Inserter->new($db, 1000, $opt_v, 0);
|
|
|
|
|
|
$inserter->create_tables($Info::vars);
|
|
|
|
my $stmt = $db->prepare("UPDATE Meta set SchemaVersion=?");
|
|
$stmt->execute($opt_V);
|
|
|
|
$inserter->commit_to_db;
|