MediaWiki master
GeneralizedSql.php
Go to the documentation of this file.
1<?php
6namespace Wikimedia\Rdbms;
7
17 private $rawSql;
19 private $prefix;
20
22 private $genericSql;
23
28 public function __construct( $rawSql, $prefix ) {
29 $this->rawSql = $rawSql;
30 $this->prefix = $prefix;
31 }
32
36 public function stringify() {
37 if ( $this->genericSql !== null ) {
38 return $this->genericSql;
39 }
40
41 $this->genericSql = $this->prefix .
42 substr( QueryBuilderFromRawSql::generalizeSQL( $this->rawSql ), 0, 255 );
43
44 return $this->genericSql;
45 }
46
50 public function getRawSql() {
51 return $this->rawSql;
52 }
53
59 public static function newFromQuery( Query $query, $prefix ) {
60 $generalizedSql = new self( $query->getSQL(), $prefix );
61
62 $cleanedSql = $query->getCleanedSql();
63 if ( $cleanedSql != '' ) {
64 // Generalized SQL already provided; no need to use regexes
65 $generalizedSql->genericSql = $prefix . $cleanedSql;
66 }
67
68 return $generalizedSql;
69 }
70}
Lazy-loaded wrapper for simplification and scrubbing of SQL queries for profiling.
static newFromQuery(Query $query, $prefix)
Holds information on Query to be executed.
Definition Query.php:17
getCleanedSql()
Get the cleaned/sanitized SQL statement text for logging.
Definition Query.php:116