Commit graph

340 commits

Author SHA1 Message Date
Reedy
d537d96868 Add numerous missing @throws to method documentation
Change-Id: Iba868e82a75fef7c7d011bc5be192bf059d037c0
2012-12-09 03:09:48 +00:00
Timo Tijhof
5603e1dd95 (bug 42598) Database: fname was not logged for BEGIN/COMMIT.
Relied on presence of whitespace. From git-blame looks like $commentedSql has been this way for a long time. Which is odd
since I've seen many commits since then specifically improving
callers of commit() and begin() to pass the __METHOD__, which
doesn't appear to have been logged anywhere up until now.

Change-Id: I48dc8b3f68a6764327b4b1a8f7c06c59a25a31bb
2012-12-02 02:58:50 +01:00
MarkAHershberger
34c9bca6a8 (bug 38110) provide a way to separate out schema changes
Allows update.php to be run when $wgAllowSchemaUpdates = false.

This is useful for non-WMF environments where strict DB permissions
allow database updates (which update.php performs), but no schema
changes (such as adding or dropping tables or indices which update.php
also performs).

It does this by adding the --schema and --noschema flags. Without
either of these flags, update.php will perform exactly as before.

With --noschema, all changes to the table structure or table additions
are skipped. Only data changes are made.

With --schema is used, no schema changes are made to the database, but
the schema changes are saved to a separate SQL file that can be run.

Change-Id: I96b4cfd4c02e9cbf46cc6a0499b87fb3b89020a0
2012-11-21 22:53:24 -05:00
Aaron Schulz
33eb67af1d [Database] Fixed case where trx idle callbacks might be lost.
* (bug 41656) LoadBalancer always commits if there are callbacks pending.
  This works by checking a new DatabaseBase::writesOrCallbacksPending() function.
* Made transaction idle callbacks run in autocommit mode. Generally callers already
  want autocommit mode or do quick begin()/commit() calls anyway. The docs already
  make stat that callbacks should close any connections they start, but this makes
  it harder for people to forget about implicit transactions. Since the callbacks
  often may happen in commitMasterChanges(), if transactions are left open, they
  might not get committed by anything afterwards.
* Added sanity exceptions and warnings if callbacks get lost for some reason.
* Renamed trxIdleCallbacks -> mTrxIdleCallbacks for consistency.

Change-Id: I00e1e0fcdd7deeee1fbac6d0f295160479cb8962
2012-11-16 02:45:17 +00:00
Antoine Musso
74869fe26d accessor for database delimiter
The command delimiter is a protected propery which prevents us form
getting it outside of Database scope. This patch add a public accessor
getDelimiter() so we can access it.

Change-Id: I676d7ed9765444366fdf3dddb07c535807dabf52
2012-10-25 12:39:32 +02:00
Niklas Laxström
3f68a44535 More informative debugging messages
Change-Id: Ib83dde07e8935e9ae3d864a12af7f93b68ee8f85
2012-10-23 15:23:22 +00:00
daniel
3c4ab2eb26 Warn when flushing inside an explicit transaction.
Until now, commit() with the "flush" flag would just commit the
transaction, no questions ask. Flushing however should only apply
to automatic transactions.

Change-Id: I621f145902cfdf201206b42c49c160aeeaf0e4ba
2012-10-17 11:31:12 +02:00
daniel
34e6fe188a Fix flush-like commit in DeferredUpdates.
In the presence of DBO_TRX, commit() may be used like a "flush".
Added a flag to trigger this mode to commit() and changed DeferredUpdates
to used the flush mode.

Change-Id: I529117618194a2669535f3c5c0fed07588597299
2012-10-09 15:34:47 +02:00
daniel
985368cb9a Silenice trx warnings from LoadBalancer.
This is a follow-up to Idbe4a903.

LoadBalancer::commitMasterChanges used to cause a warning if an implicite
transaction was in progress. This is now supressed.

Note that warnign when an automatic transaction is committed explicitely,
it does make sense to issue a warning. But that should not be done for summary
commits when closing a connection, etc.

Change-Id: Id68c3607f6b9d930c00422baa6658b0651f2e42e
2012-10-09 12:30:54 +02:00
Siebrand Mazeland
d4b046a893 Update docs for return and exception info
* Removed some inline tabs in the process.
* IDE fixed some incorrect leading spaces, too.

Change-Id: Ic9303eff6db4424ac3f1fa2816839692b43e6190
2012-10-09 09:41:58 +00:00
daniel
149c253704 Disable transaction warnings for automatic trx.
This tracks which transaction was opened automatically because of the
DBO_TRX flag, and then supresses any warnings about committing these
transactions implicitely, even if write operations were performed by
that transaction. To get warnings about implicitely committed writes
from automatic transactions, enable $wgDebugDBTransactions.

This change is a follow-up to I1e746322 and the older I3f1dd5fd, and
should be considered an alternative to I3eacc5a9. The new warning
behavior is:

* when beginning a transaction, warn if there is a transaction pending
that has also been started explicitely by calling begin().

* when beginning a transaction and $wgDebugDBTransactions is on, log
any implicit commit of an automatic transaction if write operations
where performed within that transaction.

The idea is to provide warnings about nested explicite transactions
while staying quiet about implicite commits to automatic transactions.

Change-Id: Idbe4a9034b13413e351f432408d358a704f6b77d
2012-10-08 13:49:50 +02:00
Niklas Laxström
5823ca790e Shutup some trx warnings
It's been two weeks and there hasn't been enough
effort in fixing the reported issues to justify
the flooding of logs in twn.

Change-Id: I3eacc5a9220b451bb94c4aa5ae35de4095528542
2012-10-05 07:32:52 +00:00
Niklas Laxström
18078131c5 else { if } makes no sense
I complained about this in gerrit but looks like my
comment was not saved

Change-Id: Ie570bdaf89e93628de730102587064ee0495fb1b
2012-10-05 07:32:52 +00:00
jeroendedauw
52249a6d5c Improved documentation
Change-Id: If17de8dadefeb6a2fdfe7073ba84553c07cec229
2012-10-03 21:37:07 +02:00
daniel
5bfd85cf26 Warn about all nested transactions when testing.
This change causes implicit commits caused by consecutive calls to
Database::begin() without intermediate calls to Database::commit() to
be more easily tracable. The changes introduced are:

* $this->doCommit( $fname ) is now called unconcitionally if there is
  an open transaction. Previously, it was not called if there were no
  write operations performed in that transaction.

* A warning about implicite commits (nested transactions) is now issued
  if write operations were performed OR ther DBO_TRX flag is NOT set. This
  causes any unmatched calls to begin() to trigger an error in CLI mode,
  notably also within unit tests.

* Implicit commits of non-write transactions in DBO_TRX mode can now be
  logged by enabling $wgDebugDBTRansactions.

Besides this, this change improves the documentation of the transaction
control functions.

The rationale is that implicite commits should be more easily tracable
in production and development.

Change-Id: I1e746322c36a7c53b545bfe78e252a13cce44ea1
2012-09-26 12:38:44 +02:00
Aaron Schulz
597167dc48 Limit bad transactions warnings to those involving possible writes.
Change-Id: I3f1dd5fd34c5554619936471a2c9687a8f501006
2012-09-22 01:14:35 -07:00
daniel
877c8afc3e Trigger warning for bad use of transactions.
Mediawiki currently does not support nested transactions, which means that
starting a transaction while another is in progress will silently commit
the previous transaction, causing lots of potential inconsistency.

This change introduces checks that will log a warning whenever begin() is
used while a transaction is already in progress, and whenever commit() or
rollback() are used without a transaction being in progress.

NOTE: this exposes several places in the code where transactions have inadvertedly
be nested, or unmatched calls to begin() resp commit() are used. With
$wgDevelopmentWarnings enabled or I36583fb0 merged, this may cause tests to fail.
The following changes fix the issues in question: I80faf2ed, Ia225251e, Iff394f97,
and I20d90fed.

Change-Id: I8c0426e12b78edbd758b1f087c35dabd64498624
2012-09-19 21:00:05 -07:00
umherirrender
59e0647457 Allow array condition for HAVING in database interface
Current no use in core.

Change-Id: I8ed86c8238146285dd1caed4d8586c877cbecf44
2012-08-31 20:12:19 +02:00
Aaron
3f277e8744 Added post-commit callback support to DB classes.
* This can allow for autocommit job queue insertion without
  breaking existing transactions (which currently happens since
  job queue insert does begin/commit).

Change-Id: I021d4a73635168c05bbc1068912c2c6dbdf9cdc4
2012-08-29 13:01:38 -07:00
umherirrender
7a5f4b431d Allow array condition for Database::conditional
Change the one use of that method to use the new syntax.
Add some tests.

Change-Id: I9ad4e5b5e97d1d13cfd858105167ca5d20ffaf83
2012-08-25 20:24:59 +02:00
umherirrender
aff21af9ae Allow aliased field names with separated syntax
This introduce the syntax from aliased table names for aliased field
names into the abstract database layer:

array( 'alias' => 'field' ) gives 'field AS alias'

This patch also includes changes to query pages, api and some more
places to show, how the new syntax looks in "production".

This allow us to remove the "AS" for Non-PostgreSQL databases, if we
want that.

Change-Id: I5f0de1c2f29092c173aec3de93ffdef436799e8d
2012-08-15 15:16:09 +02:00
Demon
72e00dfb19 Merge "(bug 38406) Properly quote table names in DatabaseBase::tableName()" 2012-08-14 17:42:20 +00:00
Aaron Schulz
eb16f5898d [Database] Various DB cleanups.
* Removed unused and obsolete set() and safeQuery() functions.
* Removed unused deprecated constructor functions.
* Removed unused limitResultForUpdate() cruft function.
* Removed unused standardSelectDistinct(), it's better to just follow the standard for all queries.
* Removed other cruft functions unused by core/extensions.
* Made some internal functions protected.

Change-Id: I90be88ea740834a417a17d7751f1be7bac4eae4e
2012-08-08 11:00:48 -07:00
Alexandre Emsenhuber
a6c47b6098 (bug 38406) Properly quote table names in DatabaseBase::tableName()
Currently the logic is the following:
$database = ( $format == 'quoted' || $this->isQuotedIdentifier( $database ) ? $database : $this->addIdentifierQuotes( $database ) );
This means that $database will *not* be quoted if $format is set to 'quoted',
which is the opposite of what we want here. Instead I just copied the code
used to quote $table just below and replace the variable.

This causes SQL syntax errors when the shared table name contain hyphens
since it is not quoted.

No RELEASE-NOTES entry since this should be backported to 1.19 once merged.

Patchset #2: added some tests
Patchset #3: fix tests for SQLite

Change-Id: Idda844cb470454a9a22001a31b6692de49892ca2
2012-07-18 14:54:47 +02:00
Aaron Schulz
a021ffc9ce [Database] mark some methods as explicitly public
Change-Id: I95fca6d346ae812c22b88b577477be02b5a0676b
2012-07-17 10:59:19 +02:00
Antoine Musso
aab43dd495 escape tags and entity in doxygen comments
When inserting XML elements inline <such as this one>, doxygen chokes
about it not being known. Simply enclosing the tag in double quotes
prevents doxygen from emitting a warning.

Also enclosed a few invalid functions calls such as \. and double quoted
the HTML entities such as &foobar;

Change-Id: I4019637145e683c2bec3d17b2fd98b0c50a932f1
2012-07-10 17:08:32 +02:00
saper
646a9490f7 (bug 27283) SqlBagOStuff breaks PostgreSQL txns
* SqlBagOStuff should not turn off automatic transaction
    control just like that. Keep previous
    connection for PostgreSQL and SQLite

* 94633ff448 introduced
    rollback on error to restore sanity
    for the connection. Don't do this
    if you are in the middle of INSERT IGNORE
    and we have a savepoint open.

    Making sure query syntax errors don't
    get silenced by our "wonderful" implementation
    of INSERT IGNORE is bug 35572.

Change-Id: I841b03895e1189c47307fefb1516c4c7c4102e25
2012-06-14 23:33:11 +02:00
Aaron
ff187ea7cc [SiteStatsUpdate] Reduced contention by using a new lockIsFree() DB function.
* Note: follows up a4b3979160
* Cleanup up transaction statements a bit; transactions don't effect the lock calls
* Also made DatabaseMysql::unlock() actually return a bool

Change-Id: Iade2efa94165b6918eae0863716cc163f36a07b8
2012-05-10 15:48:58 -07:00
Alexandre Emsenhuber
1d3934e1ad (bug 36568) Fixed "Illegal string offset 'LIMIT'" warnings in updater
No RELEASE-NOTES entry since this is going to be backported and RELEASE-NOTES-1.19 is out of sync.

Change-Id: I1ec6c824677606ac6f93cc43345942e4de8bd3f4
2012-05-07 15:52:55 +02:00
umherirrender
f8101287bd Do not treat EXPLAIN as write query
Change-Id: Idb15955b94ee6977f3a4692df44d445d3450b1a5
2012-05-05 11:24:07 +02:00
Alexandre Emsenhuber
78a56a67ba Added missing GPLv2 headers in includes/db.
Change-Id: Ib8fe301c6db77603e411113cea5a39c25c664961
2012-04-26 10:47:10 +02:00
Sam Reed
34c77067c3 Bug 35162 - Change in Database api break extension MSSQLBackCompat
$canonicalDBTypes is probably superfluous information, but doesn't harm as a shortcut

Ping r108051

(imported from SVN)

Change-Id: I09ecf56d984405506f654919a822a939e5a9b1ee
2012-03-21 15:56:33 -07:00
Roan Kattouw
0fca9a7991 Revert r107309, r113601, r113704, r113742, r113792, r113838, r113859, r113893, r113894, r113952, r114047, r114252, r114256, r114257. This reverts the remaining 'new' revisions in core.
All of these revisions are tagged with 'gerritmigration' and will be resubmitted into Gerrit after the Gerrit switchover. See also http://lists.wikimedia.org/pipermail/wikitech-l/2012-March/059124.html
2012-03-21 00:16:50 +00:00
Sam Reed
c6f38f8bf6 Bug 35162 - Change in Database api break extension MSSQLBackCompat
$canonicalDBTypes is probably superfluous information, but doesn't harm as a shortcut

Ping r108051
2012-03-11 23:40:33 +00:00
Marcin Cieślak
cfb8e9a251 Handle PostgreSQL transaction errors and improve schema detection
* Introduce $wgDebugDBTransactions facility to help
  figure out what's going on with transactions.
  Currently PostgreSQL only.

  PostgresTransactionState can be easily be made more general 
  to trace all sorts of state machinery.

* Improve r113408: we don't need to full reconnect on error,
  rollback is enough. 
  
  Rolling back breaks search_path, as PostgreSQL
  can manage sessions settings under transaction therefore
  we need to improve schema sniffing introduced in r82674

* Introduce few schema handling functions. This could
  probably be generalized for other databases like DB2 and Oracle.

* Fix bug 15816 - Add a switch for SETting the search_path

  We try to avoid touching search_path at all unless
  really necessary. Even in this case we append MediaWiki
  core schema to the front of the list.

* No longer add $wgDBmwschema to PostgreSQL role search_path
  in the installer. This is no longer necessary as 
  setting schema on connect should ReallyWorkNow(tm).

* Get rid as much as possible of $wgDBmwschema and
  bring us one step closer to fix bug 16794 (wgSharedDB
  support). 
  
  All references to core MediaWiki schema in PostgreSQL
  specific code should now use Database::getCoreSchema() 
  unless we know what we are doing. 

Followup-To: r113408 r82674
2012-03-09 17:24:57 +00:00
Alexandre Emsenhuber
58d34d95f3 DatabaseBase::selectRow() return a simple object, not a ResultWrapper instance 2012-03-03 20:22:18 +00:00
Aaron Schulz
fbf3db96db [DatabaseBase] Made encodeExpiry() recognize 'infinity' and added a decodeExpiry() function 2012-03-03 11:49:02 +00:00
Antoine Musso
ba07c37ea0 Bug 34818 improves regex to capture DB error message
Patch by christian at quelltextlich dot at
2012-03-01 13:11:25 +00:00
Max Semenik
a8f718267e Follow-up r112565: fix code duplication 2012-02-28 14:42:08 +00:00
Sam Reed
c760826b64 Documentations! 2012-02-14 04:05:49 +00:00
Sam Reed
76246b9bf5 More return documentation 2012-02-09 21:33:27 +00:00
Sam Reed
7b25f8231f Fixing some of the "@return true" or "@return false", need to be "@return bool" and then the metadata can say true if foo, false if bar
Other documentation improvements
2012-02-09 19:30:01 +00:00
Sam Reed
e1d83d5721 Fixing some of the "@return true" or "@return false", need to be "@return bool" and then the metadata can say true if foo, false if bar
Other documentation improvements
2012-02-09 18:01:54 +00:00
Sam Reed
138ddc452f Fixing some of the "@return true" or "@return false", need to be "@return bool" and then the metadata can say true if foo, false if bar
Other documentation improvements
2012-02-09 17:42:35 +00:00
Antoine Musso
fc6bc233be Fix doxygen docs before REL1_19 branching 2012-02-01 20:53:38 +00:00
Alexandre Emsenhuber
d109eae77f Pass some more __METHOD__ to DatabaseBase::begin() and DatabaseBase::commit() 2012-01-18 12:10:16 +00:00
Sam Reed
ebf916f3fb Give sql.php eval.php type scrollback 2012-01-12 22:57:51 +00:00
Sam Reed
5f2222c87c Followup r108768, callign the right callback helps too 2012-01-12 22:35:48 +00:00
Sam Reed
0a0cff26aa Add $inputCsllback to sourceStream(), to return full lines back to the calling function
Will be used soooon
2012-01-12 22:10:24 +00:00
Aaron Schulz
5a6559d8b1 Reverted r108743 per CR comment. This should at least be discussed first. 2012-01-12 19:41:18 +00:00