Example #1
0
 function executeCreateTableQuery(&$sqlQuery)
 {
     clearstatcache();
     $filename = $this->dbFolder . $sqlQuery->tables[0] . TABLE_FILE_EXT;
     // checks
     if (!$sqlQuery->tables[0]) {
         print_error_msg("Invalid Table " . $sqlQuery->tables[0]);
         return false;
     }
     if (file_exists($filename)) {
         print_error_msg("Table " . $sqlQuery->tables[0] . " allready exists");
         return false;
     }
     if (count($sqlQuery->colNames) != count($sqlQuery->colTypes)) {
         print_error_msg("There's not a type defined for each column");
         return false;
     }
     for ($i = 0; $i < count($sqlQuery->colTypes); ++$i) {
         $tmp = $sqlQuery->colTypes[$i] = strtolower($sqlQuery->colTypes[$i]);
         if (!($tmp == COL_TYPE_INT || $tmp == COL_TYPE_STRING || $tmp == COL_TYPE_INC)) {
             print_error_msg("Column Type " . $tmp . " not supported");
             return false;
         }
     }
     // write file
     $fp = fopen($filename, "w" . TABLE_FILE_OPEN_MODE);
     $rsParser = new ResultSetParser();
     fwrite($fp, $rsParser->parseLineFromRow($sqlQuery->colNames));
     fwrite($fp, "\n");
     fwrite($fp, $rsParser->parseLineFromRow($sqlQuery->colTypes));
     fwrite($fp, "\n");
     fwrite($fp, $rsParser->parseLineFromRow($sqlQuery->fieldValues));
     fclose($fp);
     chmod($filename, 0777);
     return true;
 }
Example #2
0
     }
     echo "colCount: {$colCount}<br>";
     for ($i = 0; $i < $colCount; ++$i) {
         if (isset($_POST['dupCol' . $i])) {
             $rs->duplicateColumn($i);
             echo "Column {$i} duplicated!<br>";
         }
     }
     for ($i = 0; $i < $colCount; ++$i) {
         if (isset($_POST['delCol' . $i])) {
             $rs->removeColumn($i);
             echo "Column {$i} deleted!<br>";
         }
     }
     $fd = fopen($table_file, "wb");
     $rp = new ResultSetParser();
     $rp->parseResultSetIntoFile($fd, $rs);
     fclose($fd);
     if (isset($_POST['close_table'])) {
         echo "<br>";
         echo "Table saved and closed, klick <a href='" . $_SERVER['PHP_SELF'] . "'> here </a> to continue";
         $_SESSION['mode'] = 'choose_table';
         unset($_SESSION['table_file']);
         echo "<meta http-equiv='refresh' content='1;URL=" . $_SERVER['PHP_SELF'] . "'>";
     } else {
         $_SESSION['mode'] = 'edit_table';
         echo "<br>";
         echo "Table saved, klick <a href='" . $_SERVER['PHP_SELF'] . "'> here </a> to continue";
         echo "<meta http-equiv='refresh' content='1;URL=" . $_SERVER['PHP_SELF'] . "'>";
     }
 }