コード例 #1
0
ファイル: db_connect.php プロジェクト: kiarie/BDS
<?php

$db = new Sqlite3('messages');
$sql = <<<EOF
      CREATE TABLE COMPANY
      (ID INT PRIMARY KEY     NOT NULL,
      NAME           TEXT    NOT NULL,
      EMAIL            INT     NOT NULL,
      SUBJECT        TEXT      NOT NULL,
      MSGBODY         TEXT \t\tNOT NULL);
EOF;
$stmt = $db->exec($sql);
if (!$stmt) {
    echo $db->lastErrorMsg();
} else {
    echo "created successfully";
}
$db->close();
コード例 #2
0
foreach ($results['data'] as $result) {
    // break if you find a photo created later than the latest
    if (isset($latest_date) && (int) $result["created_time"] <= $latest_date) {
        break;
    }
    // escape properties in _POST into variables
    $name = $sqli->escapeString($result["user"]["username"]);
    $date = $sqli->escapeString($result["created_time"]);
    if ($result["location"]["name"]) {
        $location = $sqli->escapeString($result["location"]["name"]);
    } else {
        // find address from google maps?
        $latitude = $sqli->escapeString($result["location"]["latitude"]);
        $longitude = $sqli->escapeString($result["location"]["longitude"]);
        $location = '(location not given)';
    }
    $comments = $sqli->escapeString($result["caption"]["text"]);
    $file_https = preg_replace('/http:.*[^\\s]/', 'https://', $result["images"]["standard_resolution"]["url"]);
    $file_name = $sqli->escapeString($file_https);
    $date = date('m\\/d\\/y', $date);
    !isset($date) ? $date = date('m\\/d\\/y', NOW()) : '';
    $sql = "INSERT INTO uploads (`name`, `date`, `location`, `photo`, `email`, `comments`, `date_added`)\n          VALUES ('{$name}', '{$date}', '{$location}', '{$file_name}', 'NA', '{$comments}', NOW());";
    $sqli_result = $sqli->query($sql);
    if (!$sqli_result) {
        die('ispy insert not completed: ' . $sqli->lastErrorMsg);
    }
    // free result set
    // mysqli_free_result($mysqli_result);
}
$sqli->close();
コード例 #3
0
ファイル: Dump.php プロジェクト: exakat/exakat
    public function run()
    {
        if (!file_exists($this->config->projects_root . '/projects/' . $this->config->project)) {
            throw new NoSuchProject($this->config->project);
        }
        $res = $this->gremlin->query('g.V().hasLabel("Project").values("fullcode")');
        if ($res->results[0] !== $this->config->project) {
            throw new NotProjectInGraph($this->config->project, $res->results[0]);
        }
        // move this to .dump.sqlite then rename at the end, or any imtermediate time
        // Mention that some are not yet arrived in the snitch
        $this->sqliteFile = $this->config->projects_root . '/projects/' . $this->config->project . '/.dump.sqlite';
        $this->sqliteFileFinal = $this->config->projects_root . '/projects/' . $this->config->project . '/dump.sqlite';
        if (file_exists($this->sqliteFile)) {
            unlink($this->sqliteFile);
            display('Removing old .dump.sqlite');
        }
        $this->addSnitch();
        Analyzer::initDocs();
        Analyzer::$gremlinStatic = $this->gremlin;
        if ($this->config->update === true) {
            copy($this->sqliteFileFinal, $this->sqliteFile);
            $sqlite = new \Sqlite3($this->sqliteFile);
        } else {
            $sqlite = new \Sqlite3($this->sqliteFile);
            $this->getAtomCounts($sqlite);
            $this->collectStructures($sqlite);
            $sqlite->query('CREATE TABLE themas (  id INTEGER PRIMARY KEY AUTOINCREMENT,
                                                   thema STRING
                                                  )');
            $sqlite->query('CREATE TABLE results (  id INTEGER PRIMARY KEY AUTOINCREMENT,
                                                    fullcode STRING,
                                                    file STRING,
                                                    line INTEGER,
                                                    namespace STRING,
                                                    class STRING,
                                                    function STRING,
                                                    analyzer STRING,
                                                    severity STRING
                                                  )');
            $sqlite->query('CREATE TABLE resultsCounts (   id INTEGER PRIMARY KEY AUTOINCREMENT,
                                                           analyzer STRING,
                                                           count INTEGER DEFAULT -6)');
            display('Inited tables');
        }
        $sqlQuery = <<<SQL
DELETE FROM results WHERE analyzer = :analyzer
SQL;
        $this->cleanResults = $sqlite->prepare($sqlQuery);
        $sqlQuery = <<<SQL
REPLACE INTO results ("id", "fullcode", "file", "line", "namespace", "class", "function", "analyzer", "severity") 
             VALUES ( NULL, :fullcode, :file,  :line,  :namespace,  :class,  :function,  :analyzer,  :severity )
SQL;
        $this->stmtResults = $sqlite->prepare($sqlQuery);
        $sqlQuery = <<<SQL
REPLACE INTO resultsCounts ("id", "analyzer", "count") VALUES (NULL, :class, :count )
SQL;
        $this->stmtResultsCounts = $sqlite->prepare($sqlQuery);
        $themes = array();
        if ($this->config->thema !== null) {
            $thema = $this->config->thema;
            $themes = Analyzer::getThemeAnalyzers($thema);
            if (empty($themes)) {
                $r = Analyzer::getSuggestionThema($thema);
                if (count($r) > 0) {
                    echo 'did you mean : ', implode(', ', str_replace('_', '/', $r)), "\n";
                }
                throw new NoSuchThema($thema);
            }
            display('Processing thema : ' . $thema);
        } elseif ($this->config->program !== null) {
            $analyzer = $this->config->program;
            if (!Analyzer::getClass($analyzer)) {
                $r = Analyzer::getSuggestionClass($analyzer);
                if (count($r) > 0) {
                    echo 'did you mean : ', implode(', ', str_replace('_', '/', $r)), "\n";
                }
                throw new NoSuchAnalyzer($analyzer);
            }
            $themes = array($analyzer);
            display('Processing one analyzer : ' . $analyzer);
        } else {
            display('No analysis dump requested (-T <thema> | -P <Analyzer>)');
            $this->finish();
            return;
        }
        /*
        $res = $sqlite->query('SELECT COUNT(*) FROM themas WHERE thema="'.$thema.'"');
        $count = $res->fetchArray(\SQLITE3_NUM);
        if ($count === 1) {
            display("$thema was already run\n");
        } else {
            display("$thema was not already run\n");
        }
        die();
        print_r($themes);
        */
        $sqlitePath = $this->config->projects_root . '/projects/' . $this->config->project . '/datastore.sqlite';
        $counts = array();
        $datastore = new \Sqlite3($sqlitePath, \SQLITE3_OPEN_READONLY);
        $datastore->busyTimeout(5000);
        $res = $datastore->query('SELECT * FROM analyzed');
        while ($row = $res->fetchArray(\SQLITE3_ASSOC)) {
            $counts[$row['analyzer']] = $row['counts'];
        }
        $this->log->log('count analyzed : ' . count($counts) . "\n");
        $this->log->log('counts ' . implode(', ', $counts) . "\n");
        $datastore->close();
        unset($datastore);
        foreach ($themes as $id => $thema) {
            if (isset($counts[$thema])) {
                display($thema . ' : ' . ($counts[$thema] >= 0 ? 'Yes' : 'N/A') . "\n");
                $this->processResults($thema, $counts[$thema]);
                unset($themes[$id]);
            } else {
                display($thema . " : No\n");
            }
        }
        $this->log->log('Still ' . count($themes) . " to be processed\n");
        display('Still ' . count($themes) . " to be processed\n");
        if (count($themes) === 0) {
            if ($this->config->thema !== null) {
                $sqlite->query('INSERT INTO themas ("id", "thema") VALUES ( NULL, "' . $this->config->thema . '")');
            }
        }
        $this->finish();
    }