Commit graph

426 commits

Author SHA1 Message Date
jenkins-bot
bd78869618 Merge "No yoda conditions" 2018-12-09 01:34:23 +00:00
jenkins-bot
d3ab48b673 Merge "rdbms: Pass required parameter" 2018-12-02 00:11:35 +00:00
Jakub Vrana
9e8a747233 rdbms: Pass required parameter
Found by PHPStan.

Change-Id: I8fbb64f7b5058b36381bccd5bc6a9d095b9ace15
2018-12-01 23:46:10 +00:00
Jakub Vrana
3fc3b9e578 Change typehint callback to callable
Found by PHPStan.

Change-Id: I77877a18131bd69996bad07f2ee1c5f3ba3ba2e7
2018-12-01 10:02:48 +01:00
Aaron Schulz
1c205f1822 rdbms: add ILBFactory::redefineLocalDomain method
This is intended for use with scripts like addWiki.php to avoid mismatched domain errors.

Bug: T209483
Change-Id: Ie24f83f4e0fad7b01690d2055e1529a4cb0275b5
2018-11-22 23:51:44 -08:00
Fomafix
3ee1560232 No yoda conditions
Replace
  if ( 42 === $foo )
by
  if ( $foo === 42 )

Change-Id: Ice320ef1ae64a59ed035c20134326b35d454f943
2018-11-21 17:54:39 +01:00
Alangi Derick
01000b0d48 rdbms: Add @deprecate tag to MaintainableDBConnRef class alias
Added as per when this was aliased to ease removal
in the future. It was there since REL_1.29.

Bug: T195576
Change-Id: Ia9061cb9592b39d0f6bac1c96f87c9b0346c105b
2018-11-05 18:55:20 +00:00
Marius Hoch
13f1ce8244 DatabaseSqlite::insert: Fix affected row count
Follow up to 633eb437a3

Bug: T208331
Change-Id: I142bb8c8abd43242d098932da212aa58323a0863
2018-10-31 17:13:45 +01:00
Aaron Schulz
633eb437a3 rdbms: clean up return values of IDatabase write methods
Also improved the atomicity and affected row count logic for
insert/replace with sqlite.

Also remove unused "fileHandle" code from insert().

Change-Id: If7b9148fd44f3a958899885753c7c86ba66bf193
2018-10-30 03:34:52 +00:00
Fomafix
512aa4e551 Use PHP 7 '??' operator instead of if-then-else
Change-Id: Ia86f8433f30a166d38ee63d0d1745b26740767b9
2018-10-27 23:46:13 +02:00
jenkins-bot
8e744f6f48 Merge "rdbms: add transaction comment to IDatabase::masterPosWait()" 2018-10-26 20:20:37 +00:00
Aaron Schulz
a58a9d5fce rdbms: add transaction comment to IDatabase::masterPosWait()
Change-Id: I95aa3b678b76cd06439d1feaba7f09a9c13f8931
2018-10-25 22:07:02 +00:00
jenkins-bot
14e0c6af83 Merge "rdbms: remove duplicate @params in IDatabase::select()" 2018-10-25 21:17:19 +00:00
Aaron Schulz
59573879f1 rdbms: avoid transaction status errors from ping() in rollback()
Change-Id: I38658cbf90518d9818824674da371637db15e156
2018-10-25 08:34:39 -07:00
Aaron Schulz
96ec2453f8 rdbms: remove duplicate @params in IDatabase::select()
Change-Id: I1b374cabb00d934d9203229c82a93197f03e9b05
2018-10-23 04:09:08 +00:00
Fomafix
43244db9a2 Use PHP 7 '??' operator instead of if-then-else
Change-Id: If9d4be5d88c8927f63cbb84dfc8181baf62ea3eb
2018-10-21 21:46:46 +02:00
Brad Jorsch
c5a5b02240 Database: Allow selectFieldValues() to accept SQL fragments
The documentation says "This must be a valid SQL fragment", but as
written it breaks if given anything other than a field name. It's easy
enough to fix by adding an alias to the internal select() call.

Bug: T201781
Change-Id: I76428af6d3aadc266254fdb24109a0ac2db3761f
2018-10-17 22:21:40 +00:00
Aaron Schulz
08a68482a4 rdbms: do not treat SAVEPOINT and RELEASE SAVEPOINT as write queries
Change-Id: Ib5d15d90260f30d08f3641a7fb36d82d363b012c
2018-10-16 22:36:06 -07:00
Aaron Schulz
b06f020217 rdbms: re-add DB domain sanity checks to LoadBalancer
Also clean up empty schema handling in DatabaseDomain

This reverts commit f23ac02f4f.

Bug: T193565
Change-Id: I95fde5c069f180ca888a023fade25ec81b846d44
2018-10-16 23:35:05 +00:00
jenkins-bot
b6fecdf6fe Merge "Log startAtomic()/endAtomic() to the query logger" 2018-10-13 01:45:09 +00:00
Tim Starling
ad32a557fc Log startAtomic()/endAtomic() to the query logger
Change-Id: Ife7e292ef42946ec1c5e9121b7be6a90301b3903
2018-10-13 01:20:32 +00:00
Aaron Schulz
fe0af6cad5 rdbms: Database::selectDB() update the domain and handle failure better
LoadBalancer uses Database::getDomainId() for deciding which keys to use
in the foreign connection handle arrays. This method should reflect any
changes made to the DB selection.

If the query fails, then do not change domain field. This is the sort of
approach that LoadBalancer is expects in openForeignConnection(). Also,
throw an exception when selectDB() fails.

The db/schema/prefix fields of Database no longer exist in favor of just
using the newer currentDomain field.

Also:
* Add IDatabase::selectDomain() method and made selectDB() wrap it.
* Extract the DB name from sqlite files if not explicitly provided.
* Fix inconsistent open() return values from Database subclasses.
* Make a relationSchemaQualifier() method to handle the concern of
  omitting schema names in queries. The means that getDomainId() can
  still return the right value, rather than confusingly omitt the schema.
* Make RevisionStore::checkDatabaseWikiId() account for the domain schema.
  Unlike d2a4d614fc, this does not incorrectly assume the storage is
  always for the current wiki domain. Also, LBFactorySingle sets the local
  domain so it is defined even in install.php.
* Make RevisionStoreDbTestBase actually set the LoadBalancer local domain.
* Make RevisionTest::testLoadFromTitle() account for the domain schema.

Bug: T193565
Change-Id: I6e51cd54c6da78830b38906b8c46789c79498ab5
2018-10-10 12:03:30 -07:00
jenkins-bot
b54698d680 Merge "Improve exception message in DatabaseDomain" 2018-10-09 18:21:55 +00:00
Gergő Tisza
cebdd50a49 Make unclosed transaction errors more useful
Move unclosed transaction error reporting to Database so it can
include information about the caller that started the transaction.

Change-Id: I834d957f172c03005de522f3029bb634b3c7220e
2018-10-09 17:50:17 +00:00
Aaron Schulz
d8e872562c Improve exception message in DatabaseDomain
Change-Id: Ib45497388d07b0531cfe1c06349105e47b9fad08
2018-10-09 17:34:16 +00:00
Tim Starling
9fbbce857c Fix guarding of MySQL's numRows()
It can be true for successful write queries, not just false.

f3a197e49b introduced a caller which calls numRows() on the return
value of CREATE TEMPORARY TABLE queries, and it improved guarding of
numRows() in the PostgreSQL and SQLite cases accordingly, but it
neglected MySQL.

Bug: T201900
Change-Id: I8ae754a2518d9e47b093c31c20d98daaba913513
2018-10-08 18:27:05 +11:00
Fomafix
1472f02b36 Phabricator: Use Tddddd instead of Bug ddddd in comments
Change-Id: Ic9fe03cab270bd6be738af346164ad5d31a0d780
2018-10-04 09:15:02 +02:00
jenkins-bot
6e0ac677d4 Merge "rdbms: clarify IDatabase::setTransactionListener() comment" 2018-10-04 02:46:19 +00:00
Brad Jorsch
bf30fcb714 Database: close() should not commit transactions
Transactional databases normally roll back when a connection is closed
with an open transaction rather than committing them, so MediaWiki
committing them is unexpected.

There are two cases being changed here: automatic transactions without
writes and manual transactions. For the former it shouldn't make a
difference if we commit or roll back since no writes were done anyway.
The latter has logged a message since MW 1.31 (I0992f9a8), and that
warning has not been logged in Wikimedia production in the past 60 days
so we should be ok there too.

Bug: T206147
Change-Id: Ieceef4deb49044db8f0622d38ee76c9d9f39704c
2018-10-03 14:55:43 -04:00
Aaron Schulz
46cf714ce7 rdbms: make * consistently act like in select/insertSelect methods
This now matches the documentation of insertSelect()

Bug: T202553
Change-Id: Ie6602fdd3b48b9136de7c65289c85ced5f5f2f1d
2018-10-01 14:31:53 -07:00
Aaron Schulz
ca57244eb0 rdbms: clarify IDatabase::setTransactionListener() comment
Change-Id: I6f494934b3602206943581c3c62f565bf42bd26f
2018-10-01 12:24:33 -07:00
jenkins-bot
a5fa7ece8a Merge "rdbms: Document a bunch of stuff about query verbs" 2018-10-01 15:55:38 +00:00
Umherirrender
a33827a61f Fix caller name in DatabaseMysqlBase::getMasterServerInfo/getServerId
Seeing {closure} in the logs as caller is not helpful

Change-Id: I63adbfcf4944747670a3a30182f6bd5cb6d0e48b
2018-09-30 17:38:05 +00:00
Timo Tijhof
aeb6a92132 rdbms: Document a bunch of stuff about query verbs
The decision to treat COMMIT/BEGIN as a "read" in isWriteQuery()
for the benefit of ChronologyProtector was first introduced
in r47360 (8653947b, 2009).

* Re-order strings in isTransactableQuery() to match the regular
  expression in isWriteQuery() for quicker mental comparison

* Add missing visibility to DatabaseSqlite->isWriteQuery, matching
  the parent class implementation.

Bug: T201900
Change-Id: Ic90f6455a2e696ba9428ad5835d0f4be6a0d9a5c
2018-09-28 23:49:10 +00:00
Brian Wolff
528042054f Fix some phan-taint-check false positives
Change-Id: Ic5ccbb3f97722476bee7188b83b80cdc652d2a64
2018-09-21 17:27:44 -07:00
Umherirrender
acb2e720d8 Pass delimiter to preg_quote
This ensure that the regex is escaped correctly,
even when the quoted value never contains the delimiter

Change-Id: I2dc93fa0154d4506c276a30cab008bc2ac5e0687
2018-09-01 14:52:16 +02:00
jenkins-bot
badc95193a Merge "rdbms: fix a few IDEA warnings in Database" 2018-08-22 05:06:36 +00:00
jenkins-bot
da748c3a91 Merge "rdbms: fix IDEA warnings in DatabaseMssql.php" 2018-08-22 05:01:43 +00:00
Aaron Schulz
8053bc9e0d rdbms: fix a few IDEA warnings in Database
Change-Id: I1bdca5c643ff81eb822443b8e45f71f5f3fb2155
2018-08-21 21:25:48 -07:00
Aaron Schulz
2b5e59fad1 rdbms: fix IDEA warnings in DatabaseMssql.php
Change-Id: Iffef01cfac4c714c768190e375bc873a2d3eaf2f
2018-08-21 20:14:26 -07:00
Aaron Schulz
41a37d14fa rdbms: make Database::open() protected
This is not called externally and there is little reason for that to
change. The current caller pattern is to use factory(), possibly with
initConnection() afterwards, or to use a LoadBalancer to begin with.

Change-Id: Ib1fdd5c960f1ed877fcd17bcb99b999d5d894716
2018-08-21 18:34:51 -07:00
jenkins-bot
7da455154e Merge "rdbms: use Database::getDomainId for transaction logging calls" 2018-08-16 05:54:35 +00:00
jenkins-bot
cab845c8a1 Merge "rdbms: Disable DBConnRef::selectDB() for sanity" 2018-08-16 04:33:58 +00:00
petarpetkovic
b7a4e82545 Fix some of the common typos
* supress -> suppress (Except in backup_LogTest.php)
* recomend -> recommend
* becuase -> because
* accross -> across

Bug: T201491
Change-Id: I8faa4e6cc688b3ee204b3f79ab55eb7b65cc1fdd
2018-08-16 00:59:32 +02:00
Aaron Schulz
5358c41e86 rdbms: use Database::getDomainId for transaction logging calls
Change-Id: I360ca633b145dc8e510bb00b542ac44933283943
2018-08-15 01:29:39 -07:00
Aaron Schulz
5891967297 rdbms: Disable DBConnRef::selectDB() for sanity
Bug: T193565
Change-Id: I4276d1a7d77a019e0e60dab4b9ec36c93e418037
2018-08-15 03:03:51 +00:00
Aaron Schulz
d9fdc4098b rdbms: Avoid numRows() warnings for mysqli after table creation
Bug: T201900
Change-Id: Ie86a7b8e680d79ad3f9be6ca4ec260b0589e5d0e
2018-08-14 18:52:27 +00:00
Fomafix
0a0d5cb7f7 Fix typos
Bug: T201491
Change-Id: I25a27d11faabe2f5fa02950c7a4fb58b13fb3662
2018-08-14 09:52:19 +00:00
Aaron Schulz
f3a197e49b rdbms: add "maxReadRows" limit to TransactionProfiler
Change-Id: I008fc1857c7aa43d93f43361803d5e52c4ddf089
2018-08-13 13:30:08 -07:00
Aaron Schulz
ff7edd1038 Clarify IDatabase docs for upsert() and replace()
Change-Id: I0f23a77ba0837684c2151c33b9e93046dbc73b48
2018-08-01 10:34:17 -07:00