aboutsummaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2008-06-05 19:07:27 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2008-06-05 19:07:27 +0000
commit13366a3a41485cc4a8aadcd81eb99b674c0f2abf (patch)
tree587127c83bf7f01e5c281920e0b216eec48c8344 /contrib
parent18a9621da9bf0d4e71480a50d0534d5743bb1a4c (diff)
Merge the adaptive realtime branch, which will make adding new required fields
to realtime less painful in the future. git-svn-id: http://svn.digium.com/svn/asterisk/trunk@120789 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/scripts/dbsep.cgi38
1 files changed, 38 insertions, 0 deletions
diff --git a/contrib/scripts/dbsep.cgi b/contrib/scripts/dbsep.cgi
index c274f9340..dd060f769 100755
--- a/contrib/scripts/dbsep.cgi
+++ b/contrib/scripts/dbsep.cgi
@@ -28,6 +28,7 @@ my ($cgi, $dbh, %cfg, $table, $mode);
# dsn=<some valid dsn>
# dbuser=<user>
# dbpass=<passwd>
+# dbschema=<dbname>
# backslash_is_escape={yes|no}
#
open CFG, "</etc/asterisk/dbsep.conf";
@@ -120,6 +121,43 @@ if ($mode eq 'single') {
$affected = $dbh->do($sql);
$dbh->disconnect();
print "Content-type: text/html\n\n$affected\n";
+} elsif ($ENV{PATH_INFO} =~ m/require$/) {
+ my $result = 0;
+ my $dbh = DBI->connect($cfg{dsn}, $cfg{dbuser}, $cfg{dbpass});
+ my $sql = "SELECT data_type, character_maximum_length FROM information_schema.tables AS t " .
+ "JOIN information_schema.columns AS c " .
+ "ON t.table_catalog=c.table_catalog AND " .
+ "t.table_schema=c.table_schema AND " .
+ "t.table_name=c.table_name " .
+ "WHERE c.table_schema='$cfg{dbschema}' AND " .
+ "c.table_name=? AND c.column_name=?";
+ my $sth = $dbh->prepare($sql);
+ foreach my $param (cgi_to_where_clause($cgi, \%cfg)) {
+ my ($colname, $value) = split /=/, $param;
+ my ($type, $size) = split /:/, $value;
+ $sth->execute($table, $colname);
+ my ($dbtype, $dblen) = $sth->fetchrow_array();
+ $sth->finish();
+ if ($type eq 'char') {
+ if ($dbtype !~ m#char#i) {
+ print STDERR "REQUIRE: $table: Type of column $colname requires char($size), but column is of type $dbtype instead!\n";
+ $result = -1;
+ } elsif ($dblen < $size) {
+ print STDERR "REQUIRE: $table: Size of column $colname requires $size, but column is only $dblen long!\n";
+ $result = -1;
+ }
+ } elsif ($type eq 'integer') {
+ if ($dbtype =~ m#char#i and $dblen < $size) {
+ print STDERR "REQUIRE: $table: Size of column $colname requires $size, but column is only $dblen long!\n";
+ $result = -1;
+ } elsif ($dbtype !~ m#int|float|double|dec|num#i) {
+ print STDERR "REQUIRE: $table: Type of column $colname requires integer($size), but column is of type $dbtype instead!\n";
+ $result = -1;
+ }
+ } # TODO More type checks
+ }
+ $dbh->disconnect();
+ print "Content-type: text/html\n\n$result\n";
} elsif ($ENV{PATH_INFO} =~ m/static$/) {
# file parameter in GET, no POST
my (@get, $filename, $sql, $sth);