示例#1
0
 public function sanitize($fld, $value)
 {
     if (preg_match("#text\$#", $this->modelStructure[$fld]["type"]) || preg_match("#char\$#", $this->modelStructure[$fld]["type"]) || $this->modelStructure[$fld]["type"] == "enum" || $this->modelStructure[$fld]["type"] == "date" || $this->modelStructure[$fld]["type"] == "timestamp") {
         $value = "'" . Datasource::escape($value) . "'";
     } else {
         if ($this->modelStructure[$fld]["type"] == "tinyint") {
             if (!(intval($value) == 0 || intval($value) == 1)) {
                 SimpleMVCErrors::generalError("Given value ({$value}) is not a valid boolean value");
             }
         } else {
             // Assume to be numeric
             if (!is_numeric($value) && $value != 'NULL') {
                 SimpleMVCErrors::generalError("{$value} given as numeric database input (" . $this->modelSource . ".{$fld})");
             }
         }
     }
     return $value;
 }
示例#2
0
 private function cacheTable($tbName)
 {
     ob_start();
     echo "<?class ModelCache_" . $tbName . " extends ModelCache {\n";
     echo "public function ModelCache_{$tbName}() {\n";
     echo "\t\$this->modelSource = '{$tbName}';\n";
     $rs = Datasource::query("describe " . Datasource::escape($tbName));
     foreach ($rs as $row) {
         echo "\$this->modelStructure['" . $row["Field"] . "'] = array();\n";
         echo "\$this->modelStructure['" . $row["Field"] . "']['is_id'] = " . ($row["Key"] == 'PRI' ? "true" : "false") . ";\n";
         echo "\$this->modelStructure['" . $row["Field"] . "']['type'] = '" . $this->parseType($row["Type"]) . "';\n";
         echo "\$this->modelStructure['" . $row["Field"] . "']['null'] = " . ($row["Null"] == 'NO' ? "false" : "true") . ";\n";
         echo "\$this->modelStructure['" . $row["Field"] . "']['maxlength'] = " . $this->parseLength($row["Type"]) . ";\n";
         echo "\$this->modelStructure['" . $row["Field"] . "']['default'] = " . $this->getDefault($row) . ";\n";
     }
     echo "}\n";
     echo "\n}?>\n";
     $cacheContents = ob_get_contents();
     ob_end_clean();
     $cachePointer = fopen(WEBAPP_ROOT . "/tmp/modelcache/" . md5($tbName) . ".php", "w");
     fwrite($cachePointer, $cacheContents);
     flush($cachePointer);
     fclose($cachePointer);
 }