From: Enrico Tassi Date: Tue, 21 Mar 2006 13:39:27 +0000 (+0000) Subject: added raw query form X-Git-Tag: 0.4.95@7852~1585 X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=commitdiff_plain;h=0d4d4734071fc6acb6c211d5465816abdb392c71;p=helm.git added raw query form --- diff --git a/matita/scripts/public_html/bench.php b/matita/scripts/public_html/bench.php index f11994ec1..4d45173ba 100644 --- a/matita/scripts/public_html/bench.php +++ b/matita/scripts/public_html/bench.php @@ -91,7 +91,7 @@ function links_of($name,$q,$limits){

-

Custom Query

+

Custom Query - Simple Interface

@@ -163,5 +163,20 @@ function links_of($name,$q,$limits){
+

Custom Query - raw SQL

+
+ + + + + + + + +
+
+
+
+ diff --git a/matita/scripts/public_html/common.php b/matita/scripts/public_html/common.php index 6668b6d68..48121b549 100644 --- a/matita/scripts/public_html/common.php +++ b/matita/scripts/public_html/common.php @@ -8,9 +8,52 @@ function array_to_combo($a) { } } +function prettify($s,$name) { + if (preg_match("/^[0-9]{12}$/",$s)) { + $year = substr($s,0,4); + $month = substr($s,4,2); + $day = substr($s,6,2); + $hour = substr($s,8,2); + $minute = substr($s,10,2); + return $day . "/" . $month . "/" . $year . " " . $hour . ":" . $minute; + } else if (preg_match("/time/",$name)){ + $min = floor($s / 6000); + $sec = floor(($s - $min * 6000) / 100); + $cents = $s % 100; + return $min . "m" . $sec . "." . $cents . "s"; + } else + return rtrim($s); +} + + +function printer($q){ + global $i; + echo ""; + if ( $i == 0) { + foreach( $q as $name => $txt) { + echo "$name"; + } + } + echo "\n"; + if ( $i%2 == 0) + echo ""; + else + echo ""; + foreach( $q as $name => $txt) { + echo "" . prettify($txt,$name) . ""; + } + echo "\n"; + $i++; +} + + function query($q,$f) { $db = mysql_pconnect("localhost","helm"); mysql_select_db("matita"); + if (!preg_match("/^(select|describe)[^\n;]*;?$/i",$q)) { + echo "Query not allowed!"; + return; + } $rc = mysql_query($q,$db); if(!$rc) { die("Query failed: " . mysql_error()); diff --git a/matita/scripts/public_html/showquery.php b/matita/scripts/public_html/showquery.php index 1d19033ed..cff5c032e 100644 --- a/matita/scripts/public_html/showquery.php +++ b/matita/scripts/public_html/showquery.php @@ -7,46 +7,13 @@ $qs = array(); foreach($nqs as $v){ $x = explode("@@@",$v); - $qs[$x[0]] = $x[1]; + if ($x[1] == NULL) { + $qs["Unnamed"] = $x[0]; + } else { + $qs[$x[0]] = mysql_escape_string($x[1]); + } } -function prettify($s,$name) { - if (preg_match("/^[0-9]{12}$/",$s)) { - $year = substr($s,0,4); - $month = substr($s,4,2); - $day = substr($s,6,2); - $hour = substr($s,8,2); - $minute = substr($s,10,2); - return $day . "/" . $month . "/" . $year . " " . $hour . ":" . $minute; - } else if ($name == "sum_time" || $name == "sum_timeuser" || $name == "time" || $name == "time_user" || $name == "timeuser"){ - $min = floor($s / 6000); - $sec = floor(($s - $min * 6000) / 100); - $cents = $s % 100; - return $min . "m" . $sec . "." . $cents . "s"; - } else - return $s; -} - -function printer($q){ - global $i; - echo ""; - if ( $i == 0) { - foreach( $q as $name => $txt) { - echo "$name"; - } - } - echo "\n"; - if ( $i%2 == 0) - echo ""; - else - echo ""; - foreach( $q as $name => $txt) { - echo "" . prettify($txt,$name) . ""; - } - echo "\n"; - $i++; -} - ?> @@ -57,7 +24,7 @@ function printer($q){ $q) { $i=0;?>

- +