當前位置: 首頁>>代碼示例>>PHP>>正文


PHP SqlFormatter::splitQuery方法代碼示例

本文整理匯總了PHP中SqlFormatter::splitQuery方法的典型用法代碼示例。如果您正苦於以下問題:PHP SqlFormatter::splitQuery方法的具體用法?PHP SqlFormatter::splitQuery怎麽用?PHP SqlFormatter::splitQuery使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在SqlFormatter的用法示例。


在下文中一共展示了SqlFormatter::splitQuery方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testSplitQueryEmpty

 function testSplitQueryEmpty()
 {
     $sql = "SELECT 1;SELECT 2;\n-- This is a comment\n;SELECT 3";
     $expected = array("SELECT 1;", "SELECT 2;", "SELECT 3");
     $actual = SqlFormatter::splitQuery($sql);
     $this->assertEquals($expected, $actual);
 }
開發者ID:PieterSwitten,項目名稱:webandmobile,代碼行數:7,代碼來源:SqlFormatterTest.php

示例2: validate

 /**
  * @return bool
  * @throws ValidationFailedException
  */
 public function validate()
 {
     $queryArray = \SqlFormatter::splitQuery($this->queryString);
     $pattern = '/\\*/';
     if ($this->stringHasRegexInstance($queryArray, $pattern)) {
         throw new ValidationFailedException("Query has to have all wished columns defined, no '*' is allowed", 500);
     }
     return true;
 }
開發者ID:arnulfojr,項目名稱:qcharts,代碼行數:13,代碼來源:NoAsteriscValidator.php

示例3: validate

 /**
  * @return bool
  * @throws ValidationFailedException
  */
 public function validate()
 {
     $arrayOfQueries = \SqlFormatter::splitQuery($this->queryString);
     $queryString = array_map("strtolower", $arrayOfQueries);
     $tableNames = array_map("strtolower", $this->limits["table_names"]);
     $tableNamesString = $this->getTableNamesStringForRegex($tableNames);
     $regex = "/(from" . ValidTableNameValidator::ANY_SPACE_META_SEQUENCE_PATTERN . "({$tableNamesString}))/";
     $hasJoinCommand = "/join/";
     if ($this->stringHasRegexInstance($queryString, $hasJoinCommand)) {
         $regexJoinCommand = "/(join" . ValidTableNameValidator::ANY_SPACE_META_SEQUENCE_PATTERN . "({$tableNamesString}))/";
         $result = $this->stringHasRegexInstance($queryString, $regex) && $this->stringHasRegexInstance($queryString, $regexJoinCommand);
         if (!$result) {
             throw new ValidationFailedException("The given query does not contain a valid table in the Join statement.", 500);
         }
         return $result;
     }
     if (!$this->stringHasRegexInstance($queryString, $regex)) {
         $helper = "<em>Check that the tables specify the schema</em>";
         throw new ValidationFailedException("<p>The given query does not contain a valid table.</p>{$helper}", 500);
     }
     return true;
 }
開發者ID:arnulfojr,項目名稱:qcharts,代碼行數:26,代碼來源:ValidTableNameValidator.php

示例4: foreach

    <tr>
        <th>Original</th>
        <th>Split</th>
    </tr>
    <?php 
foreach ($split_statements as $sql) {
    ?>
    <tr>
        <td>
            <pre><?php 
    echo SqlFormatter::highlight($sql);
    ?>
</pre>
        </td>
        <td><?php 
    $queries = SqlFormatter::splitQuery($sql);
    echo "<ol>";
    foreach ($queries as $query) {
        echo "<li><pre>" . SqlFormatter::highlight($query) . "</pre></li>";
    }
    echo "</ol>";
    ?>
</td>
    </tr>
    <?php 
}
?>
</table>


<h1>Removing Comments</h1>
開發者ID:TeamA-ict,項目名稱:TeamA,代碼行數:31,代碼來源:examples.php

示例5: run

 public static function run(&$report)
 {
     $macros = $report->macros;
     foreach ($macros as $key => $value) {
         if (is_array($value)) {
             $first = true;
             foreach ($value as $key2 => $value2) {
                 $value[$key2] = mysql_real_escape_string(trim($value2));
                 $first = false;
             }
             $macros[$key] = $value;
         } else {
             $macros[$key] = mysql_real_escape_string($value);
         }
         if ($value === 'ALL') {
             $macros[$key . '_all'] = true;
         }
     }
     //add the config and environment settings as macros
     $macros['config'] = PhpReports::$config;
     $macros['environment'] = PhpReports::$config['environments'][$report->options['Environment']];
     //expand macros in query
     $sql = PhpReports::render($report->raw_query, $macros);
     $report->options['Query'] = $sql;
     $report->options['Query_Formatted'] = SqlFormatter::format($sql);
     //split into individual queries and run each one, saving the last result
     $queries = SqlFormatter::splitQuery($sql);
     $datasets = array();
     $explicit_datasets = preg_match('/--\\s+@dataset(\\s*=\\s*|\\s+)true/', $sql);
     foreach ($queries as $i => $query) {
         $is_last = $i === count($queries) - 1;
         //skip empty queries
         $query = trim($query);
         if (!$query) {
             continue;
         }
         $result = mysql_query($query, $report->conn);
         if (!$result) {
             throw new Exception("Query failed: " . mysql_error($report->conn));
         }
         //if this query had an assert=empty flag and returned results, throw error
         if (preg_match('/^--[\\s+]assert[\\s]*=[\\s]*empty[\\s]*\\n/', $query)) {
             if (mysql_fetch_assoc($result)) {
                 throw new Exception("Assert failed.  Query did not return empty results.");
             }
         }
         // If this query should be included as a dataset
         if (!$explicit_datasets && $is_last || preg_match('/--\\s+@dataset(\\s*=\\s*|\\s+)true/', $query)) {
             $dataset = array('rows' => array());
             while ($row = mysql_fetch_assoc($result)) {
                 $dataset['rows'][] = $row;
             }
             // Get dataset title if it has one
             if (preg_match('/--\\s+@title(\\s*=\\s*|\\s+)(.*)/', $query, $matches)) {
                 $dataset['title'] = $matches[2];
             }
             $datasets[] = $dataset;
         }
     }
     return $datasets;
 }
開發者ID:edu-bob,項目名稱:php-reports,代碼行數:61,代碼來源:MysqlReportType.php

示例6: run

 public static function run(&$report)
 {
     $report->conn->SetFetchMode(ADODB_FETCH_ASSOC);
     $rows = array();
     $macros = $report->macros;
     foreach ($macros as $key => $value) {
         if (is_array($value)) {
             $first = true;
             foreach ($value as $key2 => $value2) {
                 $value[$key2] = mysql_real_escape_string(trim($value2));
                 $first = false;
             }
             $macros[$key] = $value;
         } else {
             $macros[$key] = mysql_real_escape_string($value);
         }
         if ($value === 'ALL') {
             $macros[$key . '_all'] = true;
         }
     }
     //add the config and environment settings as macros
     $macros['config'] = PhpReports::$config;
     $macros['environment'] = PhpReports::$config['environments'][$report->options['Environment']];
     //expand macros in query
     $sql = PhpReports::render($report->raw_query, $macros);
     $report->options['Query'] = $sql;
     $report->options['Query_Formatted'] = SqlFormatter::format($sql);
     //split into individual queries and run each one, saving the last result
     $queries = SqlFormatter::splitQuery($sql);
     foreach ($queries as $query) {
         //skip empty queries
         $query = trim($query);
         if (!$query) {
             continue;
         }
         $result = $report->conn->Execute($query);
         if (!$result) {
             throw new Exception("Query failed: " . $report->conn->ErrorMsg());
         }
         //if this query had an assert=empty flag and returned results, throw error
         if (preg_match('/^--[\\s+]assert[\\s]*=[\\s]*empty[\\s]*\\n/', $query)) {
             if ($result->GetAssoc()) {
                 throw new Exception("Assert failed.  Query did not return empty results.");
             }
         }
     }
     return $result->GetArray();
 }
開發者ID:doekia,項目名稱:php-reports,代碼行數:48,代碼來源:AdoReportType.php

示例7: run

 public static function run(&$report)
 {
     $report->conn->SetFetchMode(ADODB_FETCH_ASSOC);
     $rows = array();
     $macros = $report->macros;
     foreach ($macros as $key => $value) {
         if (is_array($value)) {
             $first = true;
             foreach ($value as $key2 => $value2) {
                 $value[$key2] = mysql_real_escape_string(trim($value2));
                 $first = false;
             }
             $macros[$key] = $value;
         } else {
             $macros[$key] = mysql_real_escape_string($value);
         }
         if ($value === 'ALL') {
             $macros[$key . '_all'] = true;
         }
     }
     //add the config and environment settings as macros
     $macros['config'] = PhpReports::$config;
     $macros['environment'] = PhpReports::$config['environments'][$report->options['Environment']];
     $raw_sql = "";
     foreach ($report->raw_query as $qry) {
         if (is_array($qry)) {
             foreach ($qry as $key => $value) {
                 // TODO handle arrays better
                 if (!is_bool($value) && !is_array($value)) {
                     $qry[$key] = PhpReports::renderString($value, $macros);
                 }
             }
             //TODO This sux - need a class or something :-)
             $raw_sql .= PivotTableSQL($report->conn, $qry['tables'], $qry['rows'], $qry['columns'], $qry['where'], $qry['orderBy'], $qry['limit'], $qry['agg_field'], $qry['agg_label'], $qry['agg_fun'], $qry['include_agg_field'], $qry['show_count']);
         } else {
             $raw_sql .= $qry;
         }
     }
     //expand macros in query
     $sql = PhpReports::render($raw_sql, $macros);
     $report->options['Query'] = $sql;
     $report->options['Query_Formatted'] = SqlFormatter::format($sql);
     //split into individual queries and run each one, saving the last result
     $queries = SqlFormatter::splitQuery($sql);
     foreach ($queries as $query) {
         if (!is_array($query)) {
             //skip empty queries
             $query = trim($query);
             if (!$query) {
                 continue;
             }
             $result = $report->conn->Execute($query);
             if (!$result) {
                 throw new Exception("Query failed: " . $report->conn->ErrorMsg());
             }
             //if this query had an assert=empty flag and returned results, throw error
             if (preg_match('/^--[\\s+]assert[\\s]*=[\\s]*empty[\\s]*\\n/', $query)) {
                 if ($result->GetAssoc()) {
                     throw new Exception("Assert failed.  Query did not return empty results.");
                 }
             }
         }
     }
     return $result->GetArray();
 }
開發者ID:doekia,項目名稱:php-reports,代碼行數:65,代碼來源:AdoPivotReportType.php


注:本文中的SqlFormatter::splitQuery方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。