Changeset View
Changeset View
Standalone View
Standalone View
src/aphront/storage/connection/AphrontIsolatedDatabaseConnection.php
Show First 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | final class AphrontIsolatedDatabaseConnection | ||||
public function getAffectedRows() { | public function getAffectedRows() { | ||||
return $this->affectedRows; | return $this->affectedRows; | ||||
} | } | ||||
public function selectAllResults() { | public function selectAllResults() { | ||||
return $this->allResults; | return $this->allResults; | ||||
} | } | ||||
public function executeRawQuery($raw_query) { | public function executeQuery(PhutilQueryString $query) { | ||||
// NOTE: "[\s<>K]*" allows any number of (properly escaped) comments to | // NOTE: "[\s<>K]*" allows any number of (properly escaped) comments to | ||||
// appear prior to the allowed keyword, since this connection escapes | // appear prior to the allowed keyword, since this connection escapes | ||||
// them as "<K>" (above). | // them as "<K>" (above). | ||||
$display_query = $query->getMaskedString(); | |||||
$raw_query = $query->getUnmaskedString(); | |||||
$keywords = array( | $keywords = array( | ||||
'INSERT', | 'INSERT', | ||||
'UPDATE', | 'UPDATE', | ||||
'DELETE', | 'DELETE', | ||||
'START', | 'START', | ||||
'SAVEPOINT', | 'SAVEPOINT', | ||||
'COMMIT', | 'COMMIT', | ||||
'ROLLBACK', | 'ROLLBACK', | ||||
); | ); | ||||
$preg_keywords = array(); | $preg_keywords = array(); | ||||
foreach ($keywords as $key => $word) { | foreach ($keywords as $key => $word) { | ||||
$preg_keywords[] = preg_quote($word, '/'); | $preg_keywords[] = preg_quote($word, '/'); | ||||
} | } | ||||
$preg_keywords = implode('|', $preg_keywords); | $preg_keywords = implode('|', $preg_keywords); | ||||
if (!preg_match('/^[\s<>K]*('.$preg_keywords.')\s*/i', $raw_query)) { | if (!preg_match('/^[\s<>K]*('.$preg_keywords.')\s*/i', $raw_query)) { | ||||
throw new AphrontNotSupportedQueryException( | throw new AphrontNotSupportedQueryException( | ||||
pht( | pht( | ||||
"Database isolation currently only supports some queries. You are ". | "Database isolation currently only supports some queries. You are ". | ||||
"trying to issue a query which does not begin with an allowed ". | "trying to issue a query which does not begin with an allowed ". | ||||
"keyword (%s): '%s'.", | "keyword (%s): '%s'.", | ||||
implode(', ', $keywords), | implode(', ', $keywords), | ||||
$raw_query)); | $display_query)); | ||||
} | } | ||||
$this->transcript[] = $raw_query; | $this->transcript[] = $display_query; | ||||
// NOTE: This method is intentionally simplified for now, since we're only | // NOTE: This method is intentionally simplified for now, since we're only | ||||
// using it to stub out inserts/updates. In the future it will probably need | // using it to stub out inserts/updates. In the future it will probably need | ||||
// to grow more powerful. | // to grow more powerful. | ||||
$this->allResults = array(); | $this->allResults = array(); | ||||
// NOTE: We jitter the insert IDs to keep tests honest; a test should cover | // NOTE: We jitter the insert IDs to keep tests honest; a test should cover | ||||
Show All 21 Lines |