public function importTableHeaderFromCSV($file)
 {
     $filename = $file . ".csv";
     if (!fileExists($filename) and $this->entityexist($file)) {
         echo "import can only in a new table";
         die;
     }
     $CSVHandler = new CSVHandler($filename);
     $CSVHandler->countColumns();
     $data = $CSVHandler->getHeaders();
     $HelperFunctions = new HelperFunctions();
     $data = $HelperFunctions->array_trim($data);
     $Evaluator = new Evaluator();
     $date = array_filter($data, $Evaluator->returnOnlyLettersNumbersUnderscore($data));
     $sql = "CREATE TABLE IF NOT EXISTS ` " . $file . " ` (";
     for ($i = 0; $i <= $CSVHandler->countColumns(); $i++) {
         if ($i == 0) {
             $sql .= "`" . $data[$i] . "` int(11) NOT NULL auto_increment";
         }
         $sql .= "`" . $data[$i] . "` varchar(255) NOT NULL default ''";
         if ($i == 0) {
             $sql .= "PRIMARY KEY  (`" . $data[$i] . "`)";
         }
     }
     $sql .= ")";
     $result = $this->executeGenericStatement($sql);
     if (empty($result)) {
         return NULL;
     }
 }
Example #2
0
 protected function ExportData(DATAHandler $h = NULL, LOGGROUP $grp, MASK $mask, INTERVAL $ivl = NULL, $resample = 0, array &$names, $opts = 0, $dmcb = NULL)
 {
     global $DEFAULT_MISSING_VALUE;
     $dm = new DOWNLOADMANAGER();
     if (!$h) {
         $h = new CSVHandler();
     }
     $filter = $this->CreateDataFilter($grp, $mask, $resample, $ivl->GetItemLimit());
     if (!$h->nullwriter) {
         $filter->AddFilter(new NULLCorrector($this->GetGroupOption($grp, "null_value", $DEFAULT_MISSING_VALUE)));
     }
     $data = $this->GetFilteredData($grp, $ivl->GetWindowStart(), $ivl->GetWindowEnd(), $filter);
     $columns = sizeof($names);
     $h->Start($columns);
     $h->DataHeaders($names);
     if ($dmcb != NULL) {
         $action = "start";
         $current_time = $ivl->GetWindowStart();
         $onepercent = ($ivl->GetWindowEnd() - $ivl->GetWindowStart()) / 100;
         $download = call_user_func_array($dmcb, array($action, ""));
     }
     foreach ($data as $time => $row) {
         $h->DataVector($time, $row);
         if ($dmcb != NULL) {
             $action = "progress";
             $thisupdate = time();
             $updateinterval = $thisupdate - $lastupdate;
             if ($time >= $current_time + $onepercent && $updateinterval >= 2) {
                 $current_time = $time;
                 $lastupdate = time();
                 $prog = round(($time - $ivl->GetWindowStart()) / $onepercent, 0);
                 if (!call_user_func_array($dmcb, array($action, $prog, $download))) {
                     $action = "finish";
                     call_user_func_array($dmcb, array($action, "cancelled"));
                     unset($dmcb);
                     break;
                 }
             }
         }
     }
     if ($dmcb != NULL) {
         $action = "finish";
         call_user_func_array($dmcb, array($action, "", $download));
     }
     $h->End();
 }