| 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 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 m_sqliteTransaction = wrapUnique(new SQLiteTransaction(m_database->sqliteDat
abase(), m_readOnly)); | 566 m_sqliteTransaction = wrapUnique(new SQLiteTransaction(m_database->sqliteDat
abase(), m_readOnly)); |
| 567 | 567 |
| 568 m_database->resetDeletes(); | 568 m_database->resetDeletes(); |
| 569 m_database->disableAuthorizer(); | 569 m_database->disableAuthorizer(); |
| 570 m_sqliteTransaction->begin(); | 570 m_sqliteTransaction->begin(); |
| 571 m_database->enableAuthorizer(); | 571 m_database->enableAuthorizer(); |
| 572 | 572 |
| 573 // Spec 4.3.2.1+2: Open a transaction to the database, jumping to the error
callback if that fails | 573 // Spec 4.3.2.1+2: Open a transaction to the database, jumping to the error
callback if that fails |
| 574 if (!m_sqliteTransaction->inProgress()) { | 574 if (!m_sqliteTransaction->inProgress()) { |
| 575 ASSERT(!m_database->sqliteDatabase().transactionInProgress()); | 575 ASSERT(!m_database->sqliteDatabase().transactionInProgress()); |
| 576 m_database->reportStartTransactionResult(2, SQLError::DATABASE_ERR, m_da
tabase->sqliteDatabase().lastError()); | 576 m_database->reportStartTransactionResult(2, SQLError::kDatabaseErr, m_da
tabase->sqliteDatabase().lastError()); |
| 577 m_transactionError = SQLErrorData::create(SQLError::DATABASE_ERR, "unabl
e to begin transaction", | 577 m_transactionError = SQLErrorData::create(SQLError::kDatabaseErr, "unabl
e to begin transaction", |
| 578 m_database->sqliteDatabase().lastError(), m_database->sqliteDatabase
().lastErrorMsg()); | 578 m_database->sqliteDatabase().lastError(), m_database->sqliteDatabase
().lastErrorMsg()); |
| 579 m_sqliteTransaction.reset(); | 579 m_sqliteTransaction.reset(); |
| 580 return nextStateForTransactionError(); | 580 return nextStateForTransactionError(); |
| 581 } | 581 } |
| 582 | 582 |
| 583 // Note: We intentionally retrieve the actual version even with an empty exp
ected version. | 583 // Note: We intentionally retrieve the actual version even with an empty exp
ected version. |
| 584 // In multi-process browsers, we take this opportinutiy to update the cached
value for | 584 // In multi-process browsers, we take this opportinutiy to update the cached
value for |
| 585 // the actual version. In single-process browsers, this is just a map lookup
. | 585 // the actual version. In single-process browsers, this is just a map lookup
. |
| 586 String actualVersion; | 586 String actualVersion; |
| 587 if (!m_database->getActualVersionForTransaction(actualVersion)) { | 587 if (!m_database->getActualVersionForTransaction(actualVersion)) { |
| 588 m_database->reportStartTransactionResult(3, SQLError::DATABASE_ERR, m_da
tabase->sqliteDatabase().lastError()); | 588 m_database->reportStartTransactionResult(3, SQLError::kDatabaseErr, m_da
tabase->sqliteDatabase().lastError()); |
| 589 m_transactionError = SQLErrorData::create(SQLError::DATABASE_ERR, "unabl
e to read version", | 589 m_transactionError = SQLErrorData::create(SQLError::kDatabaseErr, "unabl
e to read version", |
| 590 m_database->sqliteDatabase().lastError(), m_database->sqliteDatabase
().lastErrorMsg()); | 590 m_database->sqliteDatabase().lastError(), m_database->sqliteDatabase
().lastErrorMsg()); |
| 591 m_database->disableAuthorizer(); | 591 m_database->disableAuthorizer(); |
| 592 m_sqliteTransaction.reset(); | 592 m_sqliteTransaction.reset(); |
| 593 m_database->enableAuthorizer(); | 593 m_database->enableAuthorizer(); |
| 594 return nextStateForTransactionError(); | 594 return nextStateForTransactionError(); |
| 595 } | 595 } |
| 596 m_hasVersionMismatch = !m_database->expectedVersion().isEmpty() && (m_databa
se->expectedVersion() != actualVersion); | 596 m_hasVersionMismatch = !m_database->expectedVersion().isEmpty() && (m_databa
se->expectedVersion() != actualVersion); |
| 597 | 597 |
| 598 // Spec 4.3.2.3: Perform preflight steps, jumping to the error callback if t
hey fail | 598 // Spec 4.3.2.3: Perform preflight steps, jumping to the error callback if t
hey fail |
| 599 if (m_wrapper && !m_wrapper->performPreflight(this)) { | 599 if (m_wrapper && !m_wrapper->performPreflight(this)) { |
| 600 m_database->disableAuthorizer(); | 600 m_database->disableAuthorizer(); |
| 601 m_sqliteTransaction.reset(); | 601 m_sqliteTransaction.reset(); |
| 602 m_database->enableAuthorizer(); | 602 m_database->enableAuthorizer(); |
| 603 if (m_wrapper->sqlError()) { | 603 if (m_wrapper->sqlError()) { |
| 604 m_transactionError = SQLErrorData::create(*m_wrapper->sqlError()); | 604 m_transactionError = SQLErrorData::create(*m_wrapper->sqlError()); |
| 605 } else { | 605 } else { |
| 606 m_database->reportStartTransactionResult(4, SQLError::UNKNOWN_ERR, 0
); | 606 m_database->reportStartTransactionResult(4, SQLError::kUnknownErr, 0
); |
| 607 m_transactionError = SQLErrorData::create(SQLError::UNKNOWN_ERR, "un
known error occurred during transaction preflight"); | 607 m_transactionError = SQLErrorData::create(SQLError::kUnknownErr, "un
known error occurred during transaction preflight"); |
| 608 } | 608 } |
| 609 return nextStateForTransactionError(); | 609 return nextStateForTransactionError(); |
| 610 } | 610 } |
| 611 | 611 |
| 612 // Spec 4.3.2.4: Invoke the transaction callback with the new SQLTransaction
object | 612 // Spec 4.3.2.4: Invoke the transaction callback with the new SQLTransaction
object |
| 613 if (m_hasCallback) | 613 if (m_hasCallback) |
| 614 return SQLTransactionState::DeliverTransactionCallback; | 614 return SQLTransactionState::DeliverTransactionCallback; |
| 615 | 615 |
| 616 // If we have no callback to make, skip pass to the state after: | 616 // If we have no callback to make, skip pass to the state after: |
| 617 return SQLTransactionState::RunStatements; | 617 return SQLTransactionState::RunStatements; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 SQLTransactionState SQLTransactionBackend::nextStateForCurrentStatementError() | 699 SQLTransactionState SQLTransactionBackend::nextStateForCurrentStatementError() |
| 700 { | 700 { |
| 701 // Spec 4.3.2.6.6: error - Call the statement's error callback, but if there
was no error callback, | 701 // Spec 4.3.2.6.6: error - Call the statement's error callback, but if there
was no error callback, |
| 702 // or the transaction was rolled back, jump to the transaction error callbac
k | 702 // or the transaction was rolled back, jump to the transaction error callbac
k |
| 703 if (m_currentStatementBackend->hasStatementErrorCallback() && !m_sqliteTrans
action->wasRolledBackBySqlite()) | 703 if (m_currentStatementBackend->hasStatementErrorCallback() && !m_sqliteTrans
action->wasRolledBackBySqlite()) |
| 704 return SQLTransactionState::DeliverStatementCallback; | 704 return SQLTransactionState::DeliverStatementCallback; |
| 705 | 705 |
| 706 if (m_currentStatementBackend->sqlError()) { | 706 if (m_currentStatementBackend->sqlError()) { |
| 707 m_transactionError = SQLErrorData::create(*m_currentStatementBackend->sq
lError()); | 707 m_transactionError = SQLErrorData::create(*m_currentStatementBackend->sq
lError()); |
| 708 } else { | 708 } else { |
| 709 m_database->reportCommitTransactionResult(1, SQLError::DATABASE_ERR, 0); | 709 m_database->reportCommitTransactionResult(1, SQLError::kDatabaseErr, 0); |
| 710 m_transactionError = SQLErrorData::create(SQLError::DATABASE_ERR, "the s
tatement failed to execute"); | 710 m_transactionError = SQLErrorData::create(SQLError::kDatabaseErr, "the s
tatement failed to execute"); |
| 711 } | 711 } |
| 712 return nextStateForTransactionError(); | 712 return nextStateForTransactionError(); |
| 713 } | 713 } |
| 714 | 714 |
| 715 SQLTransactionState SQLTransactionBackend::postflightAndCommit() | 715 SQLTransactionState SQLTransactionBackend::postflightAndCommit() |
| 716 { | 716 { |
| 717 ASSERT(m_lockAcquired); | 717 ASSERT(m_lockAcquired); |
| 718 | 718 |
| 719 // Spec 4.3.2.7: Perform postflight steps, jumping to the error callback if
they fail. | 719 // Spec 4.3.2.7: Perform postflight steps, jumping to the error callback if
they fail. |
| 720 if (m_wrapper && !m_wrapper->performPostflight(this)) { | 720 if (m_wrapper && !m_wrapper->performPostflight(this)) { |
| 721 if (m_wrapper->sqlError()) { | 721 if (m_wrapper->sqlError()) { |
| 722 m_transactionError = SQLErrorData::create(*m_wrapper->sqlError()); | 722 m_transactionError = SQLErrorData::create(*m_wrapper->sqlError()); |
| 723 } else { | 723 } else { |
| 724 m_database->reportCommitTransactionResult(3, SQLError::UNKNOWN_ERR,
0); | 724 m_database->reportCommitTransactionResult(3, SQLError::kUnknownErr,
0); |
| 725 m_transactionError = SQLErrorData::create(SQLError::UNKNOWN_ERR, "un
known error occurred during transaction postflight"); | 725 m_transactionError = SQLErrorData::create(SQLError::kUnknownErr, "un
known error occurred during transaction postflight"); |
| 726 } | 726 } |
| 727 return nextStateForTransactionError(); | 727 return nextStateForTransactionError(); |
| 728 } | 728 } |
| 729 | 729 |
| 730 // Spec 4.3.2.7: Commit the transaction, jumping to the error callback if th
at fails. | 730 // Spec 4.3.2.7: Commit the transaction, jumping to the error callback if th
at fails. |
| 731 ASSERT(m_sqliteTransaction); | 731 ASSERT(m_sqliteTransaction); |
| 732 | 732 |
| 733 m_database->disableAuthorizer(); | 733 m_database->disableAuthorizer(); |
| 734 m_sqliteTransaction->commit(); | 734 m_sqliteTransaction->commit(); |
| 735 m_database->enableAuthorizer(); | 735 m_database->enableAuthorizer(); |
| 736 | 736 |
| 737 // If the commit failed, the transaction will still be marked as "in progres
s" | 737 // If the commit failed, the transaction will still be marked as "in progres
s" |
| 738 if (m_sqliteTransaction->inProgress()) { | 738 if (m_sqliteTransaction->inProgress()) { |
| 739 if (m_wrapper) | 739 if (m_wrapper) |
| 740 m_wrapper->handleCommitFailedAfterPostflight(this); | 740 m_wrapper->handleCommitFailedAfterPostflight(this); |
| 741 m_database->reportCommitTransactionResult(4, SQLError::DATABASE_ERR, m_d
atabase->sqliteDatabase().lastError()); | 741 m_database->reportCommitTransactionResult(4, SQLError::kDatabaseErr, m_d
atabase->sqliteDatabase().lastError()); |
| 742 m_transactionError = SQLErrorData::create(SQLError::DATABASE_ERR, "unabl
e to commit transaction", | 742 m_transactionError = SQLErrorData::create(SQLError::kDatabaseErr, "unabl
e to commit transaction", |
| 743 m_database->sqliteDatabase().lastError(), m_database->sqliteDatabase
().lastErrorMsg()); | 743 m_database->sqliteDatabase().lastError(), m_database->sqliteDatabase
().lastErrorMsg()); |
| 744 return nextStateForTransactionError(); | 744 return nextStateForTransactionError(); |
| 745 } | 745 } |
| 746 | 746 |
| 747 m_database->reportCommitTransactionResult(0, -1, 0); // OK | 747 m_database->reportCommitTransactionResult(0, -1, 0); // OK |
| 748 | 748 |
| 749 // Vacuum the database if anything was deleted. | 749 // Vacuum the database if anything was deleted. |
| 750 if (m_database->hadDeletes()) | 750 if (m_database->hadDeletes()) |
| 751 m_database->incrementalVacuumIfNeeded(); | 751 m_database->incrementalVacuumIfNeeded(); |
| 752 | 752 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 } | 824 } |
| 825 | 825 |
| 826 SQLTransactionState SQLTransactionBackend::sendToFrontendState() | 826 SQLTransactionState SQLTransactionBackend::sendToFrontendState() |
| 827 { | 827 { |
| 828 ASSERT(m_nextState != SQLTransactionState::Idle); | 828 ASSERT(m_nextState != SQLTransactionState::Idle); |
| 829 m_frontend->requestTransitToState(m_nextState); | 829 m_frontend->requestTransitToState(m_nextState); |
| 830 return SQLTransactionState::Idle; | 830 return SQLTransactionState::Idle; |
| 831 } | 831 } |
| 832 | 832 |
| 833 } // namespace blink | 833 } // namespace blink |
| OLD | NEW |