1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
#!/usr/bin/perl -w
#
# sqlitecheck.pl
# Outputs SQL commands for checking an sqlite database will adhere to
# length limits on strings when imported into a database that actually
# cares about lengths.
#
# Takes the schema for the new database as its argument, outputs commands
# for use with the old database.
#
# Copyright (C) 2006 Lee Hardy <lee -at- leeh.co.uk>
# Copyright (C) 2006 ircd-ratbox development team
#
# $Id$
use strict;
unless($ARGV[0])
{
print "Usage: ./sqlitecheck.pl <schema>\n";
exit;
}
unless(open(INPUT, "<$ARGV[0]"))
{
print "Unable to open $ARGV[0]\n";
exit;
}
my $table = "";
while(<INPUT>)
{
chomp;
if($_ =~ /^CREATE TABLE (.*) \(/)
{
$table = $1;
next;
}
elsif($_ =~ /\s*(.*) VARCHAR\((\d+)\)/)
{
print "SELECT * FROM $table WHERE LENGTH($1) > $2;\n";
}
}
|