Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F13977583
D15661.id37747.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D15661.id37747.diff
View Options
diff --git a/src/aphront/storage/connection/AphrontDatabaseConnection.php b/src/aphront/storage/connection/AphrontDatabaseConnection.php
--- a/src/aphront/storage/connection/AphrontDatabaseConnection.php
+++ b/src/aphront/storage/connection/AphrontDatabaseConnection.php
@@ -8,6 +8,7 @@
implements PhutilQsprintfInterface {
private $transactionState;
+ private $readOnly;
abstract public function getInsertID();
abstract public function getAffectedRows();
@@ -37,6 +38,15 @@
return false;
}
+ public function setReadOnly($read_only) {
+ $this->readOnly = $read_only;
+ return $this;
+ }
+
+ public function getReadOnly() {
+ return $this->readOnly;
+ }
+
public function asyncQuery($raw_query) {
throw new Exception(pht('Async queries are not supported.'));
}
diff --git a/src/aphront/storage/connection/mysql/AphrontBaseMySQLDatabaseConnection.php b/src/aphront/storage/connection/mysql/AphrontBaseMySQLDatabaseConnection.php
--- a/src/aphront/storage/connection/mysql/AphrontBaseMySQLDatabaseConnection.php
+++ b/src/aphront/storage/connection/mysql/AphrontBaseMySQLDatabaseConnection.php
@@ -257,9 +257,17 @@
// (SELECT ...) UNION (SELECT ...)
$is_write = !preg_match('/^[(]*(SELECT|SHOW|EXPLAIN)\s/', $raw_query);
if ($is_write) {
+ if ($this->getReadOnly()) {
+ throw new Exception(
+ pht(
+ 'Attempting to issue a write query on a read-only '.
+ 'connection (to database "%s")!',
+ $this->getConfiguration('database')));
+ }
AphrontWriteGuard::willWrite();
return true;
}
+
return false;
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Oct 19, 7:14 PM (2 w, 5 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6730876
Default Alt Text
D15661.id37747.diff (1 KB)
Attached To
Mode
D15661: Add a read-only flag to database connections
Attached
Detach File
Event Timeline
Log In to Comment