예제 #1
0
function majStatus($a_matos, $a_action)
{
    $qry = "Select groupe from materiel where materielID = {$a_matos}";
    $sqlCmdMatos = "update materiel set etat='{$a_action}' where materielID={$a_matos}";
    $sqlCmdGroupe = "update materiel set etat='{$a_action}' where groupe={$a_matos}";
    try {
        $db = new sqlite3($GLOBALS['dbaseName']);
        $result = $db->query($qry);
        $row = $result->fetchArray();
        $group = $row[0];
        if ($group == $a_matos) {
            $sqlCmd = $sqlCmdGroupe;
        } else {
            $sqlCmd = $sqlCmdMatos;
        }
        logMe("LIB : majStatus(\"{$sqlCmd}\")");
        $db->exec($sqlCmd);
        $db->close();
    } catch (Exception $e) {
        logme("ERROR : {$e}");
        return;
    }
}
예제 #2
0
    public function generate($dirName, $fileName = null)
    {
        $sqlite = new \sqlite3($dirName . '/dump.sqlite', \SQLITE3_OPEN_READONLY);
        $sqlQuery = <<<SQL
SELECT  id AS id,
        fullcode AS code, 
        file AS file, 
        line AS line,
        analyzer AS analyzer
    FROM results 
    WHERE analyzer IN {$this->themesList}

SQL;
        $res = $sqlite->query($sqlQuery);
        $config = Config::factory();
        $datastore = new Datastore($config);
        $items = array();
        while ($row = $res->fetchArray(SQLITE3_ASSOC)) {
            $ini = parse_ini_file($config->dir_root . '/human/en/' . $row['analyzer'] . '.ini');
            $row['error'] = $ini['name'];
            $a = Analyzer::getInstance($row['analyzer']);
            $row['severity'] = $a->getSeverity();
            $row['impact'] = $a->getTimeToFix();
            $row['recipes'] = $a->getThemes();
            $items[] = $row;
            $this->count();
        }
        if ($fileName === null) {
            $json = json_encode($items, JSON_PARTIAL_OUTPUT_ON_ERROR);
            // @todo Log if $json == false
            return $json;
        } else {
            file_put_contents($dirName . '/' . $fileName . '.' . self::FILE_EXTENSION, json_encode($items));
            return true;
        }
    }
예제 #3
0
/**
 * @param sqlite3 $db
 * @param string  $name
 * @param string  $type
 * @param string  $file
 */
function add_to_index($db, $name, $type, $file)
{
    static $i = 0;
    $db->query('INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES ("' . $name . '", "' . $type . '", "' . $file . '")');
    echo ++$i . '. Added "' . $name . '" as a ' . $type . ' in file ' . $file . PHP_EOL;
}
예제 #4
0
파일: RoboFile.php 프로젝트: exakat/exakat
    public function checkAnalyzers()
    {
        $sqlite = new sqlite3('data/analyzers.sqlite');
        // analyzers in Unassigned
        $res = $sqlite->query('SELECT analyzers.folder || "/" || analyzers.name as name FROM categories 
JOIN analyzers_categories 
    ON categories.id = analyzers_categories.id_categories
JOIN analyzers 
    ON analyzers_categories.id_analyzer = analyzers.id
        WHERE categories.name="Unassigned"');
        $total = 0;
        while ($row = $res->fetchArray()) {
            ++$total;
            print ' + ' . $row['name'] . "\n";
        }
        print $total . "analyzers in Unassigned\n";
        // categories with orphans
        $res = $sqlite->query('SELECT analyzers_categories.id_analyzer, analyzers_categories.id_categories FROM categories 
JOIN analyzers_categories 
    ON categories.id = analyzers_categories.id_categories
JOIN analyzers 
    ON analyzers_categories.id_analyzer = analyzers.id
        WHERE analyzers.id IS NULL');
        $total = 0;
        while ($row = $res->fetchArray()) {
            ++$total;
            print_r($row);
            //            $res = $sqlite->query('DELETE FROM analyzers_categories WHERE id_analyzer='.$row['id_analyzer'].' AND id_categories = '.$row['id_categories']);
        }
        print $total . " categories have orphans\n";
        // analyzers in no categories
        $res = $sqlite->query('SELECT analyzers_categories.id_analyzer, analyzers_categories.id_categories FROM analyzers 
JOIN analyzers_categories 
    ON analyzers.id = analyzers_categories.id_analyzer
JOIN categories 
    ON analyzers_categories.id_categories = categories.id
        WHERE categories.id IS NULL');
        $total = 0;
        while ($row = $res->fetchArray()) {
            ++$total;
            print_r($row);
            //            $res = $sqlite->query('DELETE FROM analyzers_categories WHERE id_analyzer='.$row['id_analyzer'].' AND id_categories = '.$row['id_categories']);
        }
        print $total . " analyzers are orphans\n";
        // check for analyzers in Files
        $total = 0;
        $res = $sqlite->query('SELECT analyzers.folder || "/" || analyzers.name as name FROM analyzers');
        while ($row = $res->fetchArray()) {
            ++$total;
            if (!file_exists('library/Exakat/Analyzer/' . $row['name'] . '.php')) {
                print $row['name'] . " has no exakat code\n";
            }
            if (!file_exists('human/en/' . $row['name'] . '.ini')) {
                print $row['name'] . " has no documentation\n";
            } else {
                $ini = parse_ini_file('human/en/' . $row['name'] . '.ini');
                if (!isset($ini['name'])) {
                    print 'human/en/' . $row['name'] . '.ini' . " is not set\n";
                }
                if (!isset($ini['exakatSince'])) {
                    print 'human/en/' . $row['name'] . '.ini' . " has no exakatSince\n";
                }
                if (strpos($ini['description'], '<?php') === false) {
                    print 'human/en/' . $row['name'] . '.ini' . " has no example in the docs\n";
                }
                $title = str_replace(array('PHP', 'autoload', 'const', 'HTTP'), '', $ini['name']);
                $title = preg_replace('#__\\S+#', '', $title);
                $title = preg_replace('#\\S+::#', '', $title);
                $title = preg_replace('#\\*_\\S+#', '', $title);
                $title = preg_replace('#\\S+\\(\\)#', '', $title);
                if ($title !== ucwords(strtolower($title)) && !preg_match('$^ext/$', $ini['name'])) {
                    print 'human/en/' . $row['name'] . '.ini' . " name is not Capital Worded ({$ini['name']})\n";
                }
                // else all is fine
            }
            if (!file_exists('tests/analyzer/Test/' . $row['name'] . '.php')) {
                print $row['name'] . " has no Test\n";
            }
        }
        print "\n" . $total . " analyzers are in the base\n";
        $analyzes = array('Analyze', 'Dead Code', 'Security', 'CompatibilityPHP53', 'CompatibilityPHP54', 'CompatibilityPHP55', 'CompatibilityPHP56', 'CompatibilityPHP70', 'CompatibilityPHP71');
        $analyzeList = '("' . implode('", "', $analyzes) . '")';
        $res = $sqlite->query('SELECT DISTINCT analyzers.folder || "/" || analyzers.name as name FROM analyzers 
JOIN analyzers_categories 
    ON analyzers.id = analyzers_categories.id_analyzer
JOIN categories 
    ON analyzers_categories.id_categories = categories.id
        WHERE categories.name IN ' . $analyzeList . ' AND 
              (analyzers.severity IS NULL OR 
              analyzers.timetofix IS NULL)
    ORDER BY name');
        $total = 0;
        while ($row = $res->fetchArray()) {
            ++$total;
            print " + " . $row['name'] . "\n";
        }
        print $total . " analyzers have no Severity or TimeToFix\n";
        // Checking that severity and timetofix are only using the right values
        $analyzes = array('Analyze', 'Dead Code', 'Security', 'CompatibilityPHP53', 'CompatibilityPHP54', 'CompatibilityPHP55', 'CompatibilityPHP56', 'CompatibilityPHP70', 'CompatibilityPHP71');
        $analyzeList = '("' . implode('", "', $analyzes) . '")';
        include __DIR__ . '/library/Exakat/Analyzer/Analyzer.php';
        $oClass = new ReflectionClass('\\Exakat\\Analyzer\\Analyzer');
        $analyzerConstants = array_keys($oClass->getConstants());
        $severityList = "'" . implode("', '", array_filter($analyzerConstants, function ($x) {
            return substr($x, 0, 2) === 'S_';
        })) . "'";
        $timeToFixList = "'" . implode("', '", array_filter($analyzerConstants, function ($x) {
            return substr($x, 0, 2) === 'T_';
        })) . "'";
        $res = $sqlite->query('SELECT DISTINCT analyzers.folder || "/" || analyzers.name as name, severity || " " || timetofix AS s FROM analyzers 
JOIN analyzers_categories 
    ON analyzers.id = analyzers_categories.id_analyzer
JOIN categories 
    ON analyzers_categories.id_categories = categories.id
        WHERE categories.name IN ' . $analyzeList . ' AND 
              (analyzers.severity NOT IN (' . $severityList . ') OR 
              analyzers.timetofix NOT IN (' . $timeToFixList . '))
    ORDER BY name');
        $total = 0;
        while ($row = $res->fetchArray()) {
            ++$total;
            print " + " . $row['name'] . ' ' . $row['s'] . "\n";
        }
        print $total . " analyzers have unknown Severity or TimeToFix\n";
        // cleaning
        $sqlite->query('VACUUM');
        print "Vaccumed\n\n";
    }
예제 #5
0
 function upgrade($db = false)
 {
     if ($this->request->is('post')) {
         $this->loadModel('Configurator');
         $this->disableCache();
         Configure::write('debug', 0);
         $this->autoRender = false;
         //get all the data from the old database
         $hostname = $this->request->data["hostname"];
         $username = $this->request->data["username"];
         $password = $this->request->data["password"];
         $database = $this->request->data["database"];
         //connect to old database
         $mysqli = new mysqli("{$hostname}", "{$username}", "{$password}", "{$database}");
         if ($mysqli->connect_errno) {
             $status = "Failed to connect to MySQL: " . $mysqli->connect_error;
             $ret = array('status' => $status);
         } else {
             $status = 'true';
             $mysql['users'] = $mysqli->query("SELECT * FROM `users` ORDER BY `users`.`id` ASC");
             if ($mysql['users']) {
                 while ($row = $mysql['users']->fetch_array(MYSQLI_ASSOC)) {
                     $users[] = $row;
                 }
             } else {
                 $status = '<br>Table \'users\' not found!';
             }
             //fetch servers
             $mysql['servers'] = $mysqli->query("SELECT * FROM `servers` ORDER BY `servers`.`id` ASC");
             if ($mysql['servers']) {
                 while ($row = $mysql['servers']->fetch_array(MYSQLI_ASSOC)) {
                     $servers[] = $row;
                 }
             } else {
                 $status .= '<br>Table \'servers\' not found!';
             }
             //fetch roles
             $mysql['roles'] = $mysqli->query("SELECT * FROM `roles` ORDER BY `roles`.`id` ASC");
             if ($mysql['roles']) {
                 while ($row = $mysql['roles']->fetch_array(MYSQLI_ASSOC)) {
                     $roles[] = $row;
                 }
             } else {
                 $status .= '<br>Table \'roles\' not found!';
             }
             $mysql['servers_users'] = $mysqli->query("SELECT * FROM `servers_users` ORDER BY `servers_users`.`id` ASC");
             if ($mysql['servers_users']) {
                 while ($row = $mysql['servers_users']->fetch_array(MYSQLI_ASSOC)) {
                     $servers_users[] = $row;
                 }
             } else {
                 $status .= '<br>Table \'servers_users\' not found!<br>Did you choose the correct database?';
             }
             //insert into mysql database
             if ($db == 'mysql') {
                 $this->Configurator->saveDb('Database/Mysql', $hostname, $username, $password, $database);
                 //import new database layout
                 function executeSQLScript($db, $fileName)
                 {
                     $statements = file_get_contents($fileName);
                     $statements = explode(';', $statements);
                     foreach ($statements as $statement) {
                         if (trim($statement) != '') {
                             $db->query($statement);
                         }
                     }
                 }
                 $test = executeSQLScript($mysqli, WWW_ROOT . 'app.sql');
                 $mysqli->query("TRUNCATE TABLE  `space_servers_users`");
                 $mysqli->query("TRUNCATE TABLE  `space_servers`");
                 $mysqli->query("TRUNCATE TABLE  `space_users`");
                 $mysqli->query("TRUNCATE TABLE  `space_roles`");
                 foreach ($users as $u) {
                     $query = "INSERT INTO  `space_users` (`id` ,`favourite_server` ,`username` ,`password` ,`created` ,`modified` ,`theme` ,`language` ,`is_super` ,`active`) VALUES ('{$u['id']}',  '{$u['favourite_server']}',  '{$u['username']}',  '{$u['password']}', NULL , NULL ,  '{$u['theme']}',  '{$u['language']}',  '{$u['is_super']}',  NULL);";
                     $mysqli->query($query);
                 }
                 foreach ($servers as $s) {
                     if (preg_match("/localhost/", $s['address']) || preg_match("/127.0.0.1/", $s['address']) || preg_match("/::1/", $s['address'])) {
                         $s['external_address'] = file_get_contents("http://icanhazip.com/");
                     } else {
                         $s['external_address'] = $s['address'];
                     }
                     $query = "INSERT INTO  `space_servers` (`id` ,`title` ,`address` ,`password` ,`port1` ,`port2` ,`default_role` ,`external_address`) VALUES ('{$s['id']}',  '{$s['title']}',  '{$s['address']}',  '{$s['password']}',  '{$s['port1']}',  '{$s['port2']}',  '{$s['default_role']}',  '{$s['external_address']}');";
                     $mysqli->query($query);
                 }
                 foreach ($roles as $r) {
                     $query = "INSERT INTO  `space_roles` (`id` ,`title` ,`pages` ,`global` ,`dash` ,`users` ,`plugins` ,`worlds` ,`servers` ,`settings` ,`fallback`) VALUES ('{$r['id']}',  '{$r['title']}',  '{$r['pages']}',  '{$r['global']}',  '{$r['dash']}',  '{$r['users']}',  '{$r['plugins']}',  '{$r['worlds']}',  '{$r['servers']}',  '{$r['settings']}',  '{$r['fallback']}');";
                     $mysqli->query($query);
                 }
                 foreach ($servers_users as $su) {
                     $query = "INSERT INTO  `servers_users` (`id` ,`user_id` ,`server_id` ,`role_id`) VALUES ('{$su['id']}',  '{$su['user_id']}',  '{$su['server_id']}',  '{$su['role_id']}');";
                     $mysqli->query($query);
                 }
             } else {
                 if ($db == 'sqlite') {
                     $this->Configurator->saveDb("Database/Sqlite", "", "", "", '../spacebukkit.sqlite');
                     $db = new sqlite3('../spacebukkit.sqlite');
                     //clear all tables
                     $db->query("DELETE FROM  `space_servers_users`");
                     $db->query("DELETE FROM  `space_users`");
                     $db->query("DELETE FROM  `space_servers`");
                     $db->query("DELETE FROM  `space_roles`");
                     //import old db
                     foreach ($users as $u) {
                         $db->query("INSERT INTO  `space_users` (`id` ,`favourite_server` ,`username` ,`password` ,`created` ,`modified` ,`theme` ,`language` ,`is_super` ,`active`) VALUES ('{$u['id']}',  '{$u['favourite_server']}',  '{$u['username']}',  '{$u['password']}', NULL , NULL ,  '{$u['theme']}',  '{$u['language']}',  '{$u['is_super']}',  NULL);");
                     }
                     foreach ($servers as $s) {
                         if (preg_match("/localhost/", $s['address']) || preg_match("/127.0.0.1/", $s['address']) || preg_match("/::1/", $s['address'])) {
                             $s['external_address'] = file_get_contents("http://icanhazip.com/");
                         } else {
                             $s['external_address'] = $s['address'];
                             $db->query("INSERT INTO  `space_servers` (`id` ,`title` ,`address` ,`password` ,`port1` ,`port2` ,`default_role` ,`external_address`) VALUES ('{$s['id']}',  '{$s['title']}',  '{$s['address']}',  '{$s['password']}',  '{$s['port1']}',  '{$s['port2']}',  '{$s['default_role']}',  '{$s['external_address']}');");
                         }
                         foreach ($roles as $r) {
                             $db->query("INSERT INTO  `space_roles` (`id` ,`title` ,`pages` ,`global` ,`dash` ,`users` ,`plugins` ,`worlds` ,`servers` ,`settings` ,`fallback`) VALUES ('{$r['id']}',  '{$r['title']}',  '{$r['pages']}',  '{$r['global']}',  '{$r['dash']}',  '{$r['users']}',  '{$r['plugins']}',  '{$r['worlds']}',  '{$r['servers']}',  '{$r['settings']}',  '{$r['fallback']}');");
                         }
                         foreach ($servers_users as $su) {
                             $db->query("INSERT INTO  `servers_users` (`id` ,`user_id` ,`server_id` ,`role_id`) VALUES ('{$su['id']}',  '{$su['user_id']}',  '{$su['server_id']}',  '{$su['role_id']}');");
                         }
                     }
                 }
             }
             echo $status;
         }
     } else {
         $this->layout = 'install';
     }
 }
예제 #6
0
//
/* Chart Data Variable*/
$MyData = new pData();
/* DB filename Variable*/
$dbname = "/media/databases/temphumidata.db";
/* Get 24 hours ago timestamp */
$timestamp = strtotime('now') - 720 * 60 * 60;
/* Format timestamp for DB */
$monthago = date("Y-m-d H:i:s", $timestamp);
/* DB results */
$timestamp = $temperature = $humidity = "";
////////////////////////////////////////////////////////////////
// Get information from SQLITE3 Database
//
/* Get connection to statement */
$db = new sqlite3($dbname);
/* Prepared Statement creation */
$statement = $db->prepare('SELECT * FROM weather WHERE timestamp > :id;');
/* Bind Value to prepared statement */
$statement->bindValue(':id', $monthago);
/* Results array */
$results = $statement->execute();
/* While loop to extract results array for charting */
while ($row = $results->fetchArray()) {
    $timestamp[] = $row["timestamp"];
    $temperature[] = $row["temperature"];
    $humidity[] = $row["humidity"];
}
/* Close DB Connection */
$db->close();
////////////////////////////////////////////////////////////////
예제 #7
0
<?php

$tableToChange = 'pages';
$db = new sqlite3("content.db");
$rs = $db->query('select showDate, expDate, id from ' . $tableToChange . ' where date(showDate) > date(expDate)');
if ($rs) {
    while ($row = $rs->fetchArray()) {
        var_dump($row);
        echo "\n\n Fixing... \n\n";
        $db->exec('update ' . $tableToChange . ' set showDate="' . $row['expdate'] . '", expDate="' . $row['showdate'] . '" where id=' . $row['id']);
        echo "Fixed";
    }
}
예제 #8
0
<?php

$num = 100004313234244;
// notice this exceeds 32 bits
$conn = new sqlite3(':memory:');
$conn->query('CREATE TABLE users (id INTEGER NOT NULL, num INTEGER NOT NULL, PRIMARY KEY(id))');
$stmt = $conn->prepare('insert into users (id, num) values (:id, :num)');
$stmt->bindValue(':id', 1, SQLITE3_INTEGER);
$stmt->bindValue(':num', $num, SQLITE3_INTEGER);
$stmt->execute();
$stmt = $conn->query('SELECT num FROM users');
$result = $stmt->fetchArray();
var_dump($num, $result[0]);
예제 #9
0
    $avgTemp += $arr['temp'];
}
function StartTimer()
{
    $time = microtime();
    $time = explode(' ', $time);
    $time = $time[1] + $time[0];
    $start = $time;
    return $start;
}
function StopTimer($startTime)
{
    $time = microtime();
    $time = explode(' ', $time);
    $time = $time[1] + $time[0];
    $finish = $time;
    return round($finish - $startTime, 4);
}
$database = new sqlite3('database/templogreg.db');
if (!$database) {
    $error = file_exists($yourfile) ? "Impossible to open, check permissions" : "Impossible to create, check permissions";
    die($error);
}
/*$structure = $database->query('PRAGMA table_info(temps);');
			while ($row = $structure->fetchArray()) {
			print_r($row);
			}
			*/
// 2015-09-01 22:20:09 because that's the last timestamp in the database
$statement = $database->prepare("SELECT ID, timestamp, temp FROM temps WHERE timestamp > datetime('2015-09-01 22:20:09', :time)");
$statement->bindValue(':time', '-' . $interval . ' hours');
예제 #10
0
파일: timing.php 프로젝트: exakat/exakat
    if (!preg_match("#Final\t([0-9\\.]+)\t([0-9\\.]+)#is", $content, $r)) {
        continue;
    }
    $final = $r[2];
    if (!file_exists("projects/{$project}/log/stat.log")) {
        continue;
    }
    $content = file_get_contents("projects/{$project}/log/stat.log");
    if (!preg_match("#tokens_count : (\\d+)#is", $content, $r)) {
        continue;
    }
    $size = (int) $r[1];
    if (!file_exists("projects/{$project}/datastore.sqlite")) {
        continue;
    }
    $sqlite = new sqlite3("projects/{$project}/datastore.sqlite");
    $res = $sqlite->query('SELECT * FROM hash WHERE key = "tokens"');
    $initialSize = $res->fetchArray()['value'];
    if ($initialSize == 0) {
        print "php exakat project -v -p {$project}\n";
        continue;
    }
    $res = array($project, $initialSize, $size, $buildRoot, $tokenizer, $analyze, $final);
    $regression->addData(floor($final), [floor($size)]);
    if ($initialSize < $size) {
        print "Tokens grown : {$project}\n";
    }
    fputcsv($fp, $res);
    ++$total;
}
print "Did {$total} files\n";