| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2008, 2013 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008, 2013 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 // is also destructing. | 426 // is also destructing. |
| 427 | 427 |
| 428 m_wrapper = nullptr; | 428 m_wrapper = nullptr; |
| 429 } | 429 } |
| 430 | 430 |
| 431 AbstractSQLStatement* SQLTransactionBackend::currentStatement() | 431 AbstractSQLStatement* SQLTransactionBackend::currentStatement() |
| 432 { | 432 { |
| 433 return m_currentStatementBackend->frontend(); | 433 return m_currentStatementBackend->frontend(); |
| 434 } | 434 } |
| 435 | 435 |
| 436 PassRefPtr<SQLError> SQLTransactionBackend::transactionError() | 436 SQLErrorData* SQLTransactionBackend::transactionError() |
| 437 { | 437 { |
| 438 return m_transactionError; | 438 return m_transactionError.get(); |
| 439 } | 439 } |
| 440 | 440 |
| 441 void SQLTransactionBackend::setShouldRetryCurrentStatement(bool shouldRetry) | 441 void SQLTransactionBackend::setShouldRetryCurrentStatement(bool shouldRetry) |
| 442 { | 442 { |
| 443 ASSERT(!m_shouldRetryCurrentStatement); | 443 ASSERT(!m_shouldRetryCurrentStatement); |
| 444 m_shouldRetryCurrentStatement = shouldRetry; | 444 m_shouldRetryCurrentStatement = shouldRetry; |
| 445 } | 445 } |
| 446 | 446 |
| 447 SQLTransactionBackend::StateFunction SQLTransactionBackend::stateFunctionFor(SQL
TransactionState state) | 447 SQLTransactionBackend::StateFunction SQLTransactionBackend::stateFunctionFor(SQL
TransactionState state) |
| 448 { | 448 { |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 | 566 |
| 567 m_database->resetDeletes(); | 567 m_database->resetDeletes(); |
| 568 m_database->disableAuthorizer(); | 568 m_database->disableAuthorizer(); |
| 569 m_sqliteTransaction->begin(); | 569 m_sqliteTransaction->begin(); |
| 570 m_database->enableAuthorizer(); | 570 m_database->enableAuthorizer(); |
| 571 | 571 |
| 572 // Spec 4.3.2.1+2: Open a transaction to the database, jumping to the error
callback if that fails | 572 // Spec 4.3.2.1+2: Open a transaction to the database, jumping to the error
callback if that fails |
| 573 if (!m_sqliteTransaction->inProgress()) { | 573 if (!m_sqliteTransaction->inProgress()) { |
| 574 ASSERT(!m_database->sqliteDatabase().transactionInProgress()); | 574 ASSERT(!m_database->sqliteDatabase().transactionInProgress()); |
| 575 m_database->reportStartTransactionResult(2, SQLError::DATABASE_ERR, m_da
tabase->sqliteDatabase().lastError()); | 575 m_database->reportStartTransactionResult(2, SQLError::DATABASE_ERR, m_da
tabase->sqliteDatabase().lastError()); |
| 576 m_transactionError = SQLError::create(SQLError::DATABASE_ERR, "unable to
begin transaction", | 576 m_transactionError = SQLErrorData::create(SQLError::DATABASE_ERR, "unabl
e to begin transaction", |
| 577 m_database->sqliteDatabase().lastError(), m_database->sqliteDatabase
().lastErrorMsg()); | 577 m_database->sqliteDatabase().lastError(), m_database->sqliteDatabase
().lastErrorMsg()); |
| 578 m_sqliteTransaction.clear(); | 578 m_sqliteTransaction.clear(); |
| 579 return nextStateForTransactionError(); | 579 return nextStateForTransactionError(); |
| 580 } | 580 } |
| 581 | 581 |
| 582 // Note: We intentionally retrieve the actual version even with an empty exp
ected version. | 582 // Note: We intentionally retrieve the actual version even with an empty exp
ected version. |
| 583 // In multi-process browsers, we take this opportinutiy to update the cached
value for | 583 // In multi-process browsers, we take this opportinutiy to update the cached
value for |
| 584 // the actual version. In single-process browsers, this is just a map lookup
. | 584 // the actual version. In single-process browsers, this is just a map lookup
. |
| 585 String actualVersion; | 585 String actualVersion; |
| 586 if (!m_database->getActualVersionForTransaction(actualVersion)) { | 586 if (!m_database->getActualVersionForTransaction(actualVersion)) { |
| 587 m_database->reportStartTransactionResult(3, SQLError::DATABASE_ERR, m_da
tabase->sqliteDatabase().lastError()); | 587 m_database->reportStartTransactionResult(3, SQLError::DATABASE_ERR, m_da
tabase->sqliteDatabase().lastError()); |
| 588 m_transactionError = SQLError::create(SQLError::DATABASE_ERR, "unable to
read version", | 588 m_transactionError = SQLErrorData::create(SQLError::DATABASE_ERR, "unabl
e to read version", |
| 589 m_database->sqliteDatabase().lastError(), m_database->sqliteDatabase
().lastErrorMsg()); | 589 m_database->sqliteDatabase().lastError(), m_database->sqliteDatabase
().lastErrorMsg()); |
| 590 m_database->disableAuthorizer(); | 590 m_database->disableAuthorizer(); |
| 591 m_sqliteTransaction.clear(); | 591 m_sqliteTransaction.clear(); |
| 592 m_database->enableAuthorizer(); | 592 m_database->enableAuthorizer(); |
| 593 return nextStateForTransactionError(); | 593 return nextStateForTransactionError(); |
| 594 } | 594 } |
| 595 m_hasVersionMismatch = !m_database->expectedVersion().isEmpty() && (m_databa
se->expectedVersion() != actualVersion); | 595 m_hasVersionMismatch = !m_database->expectedVersion().isEmpty() && (m_databa
se->expectedVersion() != actualVersion); |
| 596 | 596 |
| 597 // Spec 4.3.2.3: Perform preflight steps, jumping to the error callback if t
hey fail | 597 // Spec 4.3.2.3: Perform preflight steps, jumping to the error callback if t
hey fail |
| 598 if (m_wrapper && !m_wrapper->performPreflight(this)) { | 598 if (m_wrapper && !m_wrapper->performPreflight(this)) { |
| 599 m_database->disableAuthorizer(); | 599 m_database->disableAuthorizer(); |
| 600 m_sqliteTransaction.clear(); | 600 m_sqliteTransaction.clear(); |
| 601 m_database->enableAuthorizer(); | 601 m_database->enableAuthorizer(); |
| 602 m_transactionError = m_wrapper->sqlError(); | 602 if (m_wrapper->sqlError()) { |
| 603 if (!m_transactionError) { | 603 m_transactionError = SQLErrorData::create(*m_wrapper->sqlError()); |
| 604 } else { |
| 604 m_database->reportStartTransactionResult(4, SQLError::UNKNOWN_ERR, 0
); | 605 m_database->reportStartTransactionResult(4, SQLError::UNKNOWN_ERR, 0
); |
| 605 m_transactionError = SQLError::create(SQLError::UNKNOWN_ERR, "unknow
n error occurred during transaction preflight"); | 606 m_transactionError = SQLErrorData::create(SQLError::UNKNOWN_ERR, "un
known error occurred during transaction preflight"); |
| 606 } | 607 } |
| 607 return nextStateForTransactionError(); | 608 return nextStateForTransactionError(); |
| 608 } | 609 } |
| 609 | 610 |
| 610 // Spec 4.3.2.4: Invoke the transaction callback with the new SQLTransaction
object | 611 // Spec 4.3.2.4: Invoke the transaction callback with the new SQLTransaction
object |
| 611 if (m_hasCallback) | 612 if (m_hasCallback) |
| 612 return SQLTransactionState::DeliverTransactionCallback; | 613 return SQLTransactionState::DeliverTransactionCallback; |
| 613 | 614 |
| 614 // If we have no callback to make, skip pass to the state after: | 615 // If we have no callback to make, skip pass to the state after: |
| 615 return SQLTransactionState::RunStatements; | 616 return SQLTransactionState::RunStatements; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 return nextStateForCurrentStatementError(); | 693 return nextStateForCurrentStatementError(); |
| 693 } | 694 } |
| 694 | 695 |
| 695 SQLTransactionState SQLTransactionBackend::nextStateForCurrentStatementError() | 696 SQLTransactionState SQLTransactionBackend::nextStateForCurrentStatementError() |
| 696 { | 697 { |
| 697 // Spec 4.3.2.6.6: error - Call the statement's error callback, but if there
was no error callback, | 698 // Spec 4.3.2.6.6: error - Call the statement's error callback, but if there
was no error callback, |
| 698 // or the transaction was rolled back, jump to the transaction error callbac
k | 699 // or the transaction was rolled back, jump to the transaction error callbac
k |
| 699 if (m_currentStatementBackend->hasStatementErrorCallback() && !m_sqliteTrans
action->wasRolledBackBySqlite()) | 700 if (m_currentStatementBackend->hasStatementErrorCallback() && !m_sqliteTrans
action->wasRolledBackBySqlite()) |
| 700 return SQLTransactionState::DeliverStatementCallback; | 701 return SQLTransactionState::DeliverStatementCallback; |
| 701 | 702 |
| 702 m_transactionError = m_currentStatementBackend->sqlError(); | 703 if (m_currentStatementBackend->sqlError()) { |
| 703 if (!m_transactionError) { | 704 m_transactionError = SQLErrorData::create(*m_currentStatementBackend->sq
lError()); |
| 705 } else { |
| 704 m_database->reportCommitTransactionResult(1, SQLError::DATABASE_ERR, 0); | 706 m_database->reportCommitTransactionResult(1, SQLError::DATABASE_ERR, 0); |
| 705 m_transactionError = SQLError::create(SQLError::DATABASE_ERR, "the state
ment failed to execute"); | 707 m_transactionError = SQLErrorData::create(SQLError::DATABASE_ERR, "the s
tatement failed to execute"); |
| 706 } | 708 } |
| 707 return nextStateForTransactionError(); | 709 return nextStateForTransactionError(); |
| 708 } | 710 } |
| 709 | 711 |
| 710 SQLTransactionState SQLTransactionBackend::postflightAndCommit() | 712 SQLTransactionState SQLTransactionBackend::postflightAndCommit() |
| 711 { | 713 { |
| 712 ASSERT(m_lockAcquired); | 714 ASSERT(m_lockAcquired); |
| 713 | 715 |
| 714 // Spec 4.3.2.7: Perform postflight steps, jumping to the error callback if
they fail. | 716 // Spec 4.3.2.7: Perform postflight steps, jumping to the error callback if
they fail. |
| 715 if (m_wrapper && !m_wrapper->performPostflight(this)) { | 717 if (m_wrapper && !m_wrapper->performPostflight(this)) { |
| 716 m_transactionError = m_wrapper->sqlError(); | 718 if (m_wrapper->sqlError()) { |
| 717 if (!m_transactionError) { | 719 m_transactionError = SQLErrorData::create(*m_wrapper->sqlError()); |
| 720 } else { |
| 718 m_database->reportCommitTransactionResult(3, SQLError::UNKNOWN_ERR,
0); | 721 m_database->reportCommitTransactionResult(3, SQLError::UNKNOWN_ERR,
0); |
| 719 m_transactionError = SQLError::create(SQLError::UNKNOWN_ERR, "unknow
n error occurred during transaction postflight"); | 722 m_transactionError = SQLErrorData::create(SQLError::UNKNOWN_ERR, "un
known error occurred during transaction postflight"); |
| 720 } | 723 } |
| 721 return nextStateForTransactionError(); | 724 return nextStateForTransactionError(); |
| 722 } | 725 } |
| 723 | 726 |
| 724 // Spec 4.3.2.7: Commit the transaction, jumping to the error callback if th
at fails. | 727 // Spec 4.3.2.7: Commit the transaction, jumping to the error callback if th
at fails. |
| 725 ASSERT(m_sqliteTransaction); | 728 ASSERT(m_sqliteTransaction); |
| 726 | 729 |
| 727 m_database->disableAuthorizer(); | 730 m_database->disableAuthorizer(); |
| 728 m_sqliteTransaction->commit(); | 731 m_sqliteTransaction->commit(); |
| 729 m_database->enableAuthorizer(); | 732 m_database->enableAuthorizer(); |
| 730 | 733 |
| 731 // If the commit failed, the transaction will still be marked as "in progres
s" | 734 // If the commit failed, the transaction will still be marked as "in progres
s" |
| 732 if (m_sqliteTransaction->inProgress()) { | 735 if (m_sqliteTransaction->inProgress()) { |
| 733 if (m_wrapper) | 736 if (m_wrapper) |
| 734 m_wrapper->handleCommitFailedAfterPostflight(this); | 737 m_wrapper->handleCommitFailedAfterPostflight(this); |
| 735 m_database->reportCommitTransactionResult(4, SQLError::DATABASE_ERR, m_d
atabase->sqliteDatabase().lastError()); | 738 m_database->reportCommitTransactionResult(4, SQLError::DATABASE_ERR, m_d
atabase->sqliteDatabase().lastError()); |
| 736 m_transactionError = SQLError::create(SQLError::DATABASE_ERR, "unable to
commit transaction", | 739 m_transactionError = SQLErrorData::create(SQLError::DATABASE_ERR, "unabl
e to commit transaction", |
| 737 m_database->sqliteDatabase().lastError(), m_database->sqliteDatabase
().lastErrorMsg()); | 740 m_database->sqliteDatabase().lastError(), m_database->sqliteDatabase
().lastErrorMsg()); |
| 738 return nextStateForTransactionError(); | 741 return nextStateForTransactionError(); |
| 739 } | 742 } |
| 740 | 743 |
| 741 m_database->reportCommitTransactionResult(0, -1, 0); // OK | 744 m_database->reportCommitTransactionResult(0, -1, 0); // OK |
| 742 | 745 |
| 743 // Vacuum the database if anything was deleted. | 746 // Vacuum the database if anything was deleted. |
| 744 if (m_database->hadDeletes()) | 747 if (m_database->hadDeletes()) |
| 745 m_database->incrementalVacuumIfNeeded(); | 748 m_database->incrementalVacuumIfNeeded(); |
| 746 | 749 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 818 } | 821 } |
| 819 | 822 |
| 820 SQLTransactionState SQLTransactionBackend::sendToFrontendState() | 823 SQLTransactionState SQLTransactionBackend::sendToFrontendState() |
| 821 { | 824 { |
| 822 ASSERT(m_nextState != SQLTransactionState::Idle); | 825 ASSERT(m_nextState != SQLTransactionState::Idle); |
| 823 m_frontend->requestTransitToState(m_nextState); | 826 m_frontend->requestTransitToState(m_nextState); |
| 824 return SQLTransactionState::Idle; | 827 return SQLTransactionState::Idle; |
| 825 } | 828 } |
| 826 | 829 |
| 827 } // namespace WebCore | 830 } // namespace WebCore |
| OLD | NEW |