Ejemplo n.º 1
0
 function executeListTablesQuery(&$sqlQuery)
 {
     $rs = new ResultSet();
     $rs->colNames = array("table");
     $rs->colAliases = array("");
     $rs->colTables = array("");
     $rs->colTableAliases = array("");
     $rs->colTypes = array(COL_TYPE_STRING);
     $rs->colDefaultValues = array("");
     $rs->colFuncs = array("");
     $rs->colFuncsExecuted = array(false);
     $handle = opendir($this->dbFolder);
     $rs->reset();
     while ($file = readdir($handle)) {
         if ($file != "." && $file != ".." && is_file($this->dbFolder . $file)) {
             $rs->appendRow(array(substr($file, 0, strlen($file) - strlen(TABLE_FILE_EXT))));
         }
     }
     // apply WHERE Statement
     if ($sqlQuery->where_expr) {
         $ep = new ExpressionParser();
         $rs = $ep->getFilteredResultSet($rs, $sqlQuery);
     }
     // Order ResultSet
     if (count($sqlQuery->orderColumns) > 0) {
         $rs->orderRows($sqlQuery->orderColumns, $sqlQuery->orderTypes);
     }
     // Group ResultSet (process GROUP BY)
     if (count($sqlQuery->groupColumns) > 0) {
         $rs = $rs->groupRows($sqlQuery->groupColumns, $sqlQuery->limit);
     }
     // Apply Limit
     $rs->reset();
     $rs = $rs->limitResultSet($sqlQuery->limit);
     closedir($handle);
     $rs->reset();
     return $rs;
 }
Ejemplo n.º 2
0
 function parseResultSetFromFileForAppend($fd)
 {
     $start = getmicrotime();
     $rs = new ResultSet();
     // COLUMN NAMES
     // read with a maximum of 1000 bytes, until there is a newline included (or eof)
     $buf = "";
     while (is_false(strstr($buf, "\n"))) {
         $buf .= fgets($fd, 1000);
         if (feof($fd)) {
             print_error_msg("Invalid Table File!<br>");
             return null;
         }
     }
     // remove newline
     remove_last_char($buf);
     $rec = $this->parseRowFromLine($buf);
     $rs->setColumnNames($rec);
     // COLUMN TYPES
     // read with a maximum of 1000 bytes, until there is a newline included (or eof)
     $buf = "";
     while (is_false(strstr($buf, "\n"))) {
         $buf .= fgets($fd, 1000);
         if (feof($fd)) {
             print_error_msg("Invalid Table File!<br>");
             return null;
         }
     }
     // remove newline
     remove_last_char($buf);
     $rec = $this->parseRowFromLine($buf);
     $rs->setColumnTypes($rec);
     // COLUMN DEFAULT VALUES
     // read with a maximum of 1000 bytes, until there is a newline included (or eof)
     $buf = "";
     while (is_false(strstr($buf, "\n"))) {
         $buf .= fgets($fd, 1000);
         if (feof($fd)) {
             break;
             // there's no newline after the colum types => empty table
         }
     }
     // remove newline
     if (last_char($buf) == "\n") {
         remove_last_char($buf);
     }
     $rec = $this->parseRowFromLine($buf);
     $rs->setColumnDefaultValues($rec);
     // get file size
     fseek($fd, 0, SEEK_END);
     $size = ftell($fd);
     $lastRecSize = min($size, ASSUMED_RECORD_SIZE);
     $lastRecPos = false;
     while (is_false($lastRecPos)) {
         fseek($fd, -$lastRecSize, SEEK_END);
         $buf = fread($fd, $lastRecSize);
         $lastRecSize = $lastRecSize * 2;
         $lastRecSize = min($size, $lastRecSize);
         if ($lastRecSize < 1) {
             print_error_message("lastRecSize should not be 0! Contact developer please!");
         }
         $lastRecPos = $this->getLastRecordPosInString($buf);
         if (TXTDBAPI_VERBOSE_DEBUG) {
             echo "<hr>pass! <br>";
             echo "lastRecPos: " . $lastRecPos . "<br>";
             echo "buf: " . $buf . "<br>";
         }
     }
     $buf = trim(substr($buf, $lastRecPos));
     verbose_debug_print("buf after substr() and trim(): " . $buf . "<br>");
     $rs->reset();
     $row = $this->parseRowFromLine($buf);
     if (TXTDBAPI_VERBOSE_DEBUG) {
         echo "parseResultSetFromFileForAppend(): last Row:<br>";
         print_r($row);
         echo "<br>";
     }
     $rs->appendRow($row);
     $rs->setColumnAliases(create_array_fill(count($rs->colNames), ""));
     $rs->setColumnTables(create_array_fill(count($rs->colNames), ""));
     $rs->setColumnTableAliases(create_array_fill(count($rs->colNames), ""));
     $rs->setColumnFunctions(create_array_fill(count($rs->colNames), ""));
     $rs->colFuncsExecuted = create_array_fill(count($rs->colNames), false);
     debug_print("<i>III: parseResultSetFromFileForAppend: " . (getmicrotime() - $start) . " seconds elapsed</i><br>");
     return $rs;
 }