| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * Copyright (C) 2013 Apple Inc. All rights reserved. | 3 * Copyright (C) 2013 Apple Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 ASSERT(m_database->executionContext()->isContextThread()); | 62 ASSERT(m_database->executionContext()->isContextThread()); |
| 63 } | 63 } |
| 64 | 64 |
| 65 SQLTransactionBackendSync::~SQLTransactionBackendSync() | 65 SQLTransactionBackendSync::~SQLTransactionBackendSync() |
| 66 { | 66 { |
| 67 ASSERT(m_database->executionContext()->isContextThread()); | 67 ASSERT(m_database->executionContext()->isContextThread()); |
| 68 if (m_sqliteTransaction && m_sqliteTransaction->inProgress()) | 68 if (m_sqliteTransaction && m_sqliteTransaction->inProgress()) |
| 69 rollback(); | 69 rollback(); |
| 70 } | 70 } |
| 71 | 71 |
| 72 PassRefPtr<SQLResultSet> SQLTransactionBackendSync::executeSQL(const String& sql
Statement, const Vector<SQLValue>& arguments, ExceptionState& es) | 72 PassRefPtr<SQLResultSet> SQLTransactionBackendSync::executeSQL(const String& sql
Statement, const Vector<SQLValue>& arguments, ExceptionState& exceptionState) |
| 73 { | 73 { |
| 74 ASSERT(m_database->executionContext()->isContextThread()); | 74 ASSERT(m_database->executionContext()->isContextThread()); |
| 75 | 75 |
| 76 m_database->setLastErrorMessage(""); | 76 m_database->setLastErrorMessage(""); |
| 77 | 77 |
| 78 if (!m_database->opened()) { | 78 if (!m_database->opened()) { |
| 79 m_database->setLastErrorMessage("cannot executeSQL because the database
is not open"); | 79 m_database->setLastErrorMessage("cannot executeSQL because the database
is not open"); |
| 80 es.throwDOMException(UnknownError, SQLError::unknownErrorMessage); | 80 exceptionState.throwDOMException(UnknownError, SQLError::unknownErrorMes
sage); |
| 81 return 0; | 81 return 0; |
| 82 } | 82 } |
| 83 | 83 |
| 84 if (m_hasVersionMismatch) { | 84 if (m_hasVersionMismatch) { |
| 85 m_database->setLastErrorMessage("cannot executeSQL because there is a ve
rsion mismatch"); | 85 m_database->setLastErrorMessage("cannot executeSQL because there is a ve
rsion mismatch"); |
| 86 es.throwDOMException(VersionError, SQLError::versionErrorMessage); | 86 exceptionState.throwDOMException(VersionError, SQLError::versionErrorMes
sage); |
| 87 return 0; | 87 return 0; |
| 88 } | 88 } |
| 89 | 89 |
| 90 if (sqlStatement.isEmpty()) | 90 if (sqlStatement.isEmpty()) |
| 91 return 0; | 91 return 0; |
| 92 | 92 |
| 93 int permissions = DatabaseAuthorizer::ReadWriteMask; | 93 int permissions = DatabaseAuthorizer::ReadWriteMask; |
| 94 if (!m_database->databaseContext()->allowDatabaseAccess()) | 94 if (!m_database->databaseContext()->allowDatabaseAccess()) |
| 95 permissions |= DatabaseAuthorizer::NoAccessMask; | 95 permissions |= DatabaseAuthorizer::NoAccessMask; |
| 96 else if (m_readOnly) | 96 else if (m_readOnly) |
| 97 permissions |= DatabaseAuthorizer::ReadOnlyMask; | 97 permissions |= DatabaseAuthorizer::ReadOnlyMask; |
| 98 | 98 |
| 99 SQLStatementSync statement(sqlStatement, arguments, permissions); | 99 SQLStatementSync statement(sqlStatement, arguments, permissions); |
| 100 | 100 |
| 101 m_database->resetAuthorizer(); | 101 m_database->resetAuthorizer(); |
| 102 bool retryStatement = true; | 102 bool retryStatement = true; |
| 103 RefPtr<SQLResultSet> resultSet; | 103 RefPtr<SQLResultSet> resultSet; |
| 104 while (retryStatement) { | 104 while (retryStatement) { |
| 105 retryStatement = false; | 105 retryStatement = false; |
| 106 resultSet = statement.execute(m_database.get(), es); | 106 resultSet = statement.execute(m_database.get(), exceptionState); |
| 107 if (!resultSet) { | 107 if (!resultSet) { |
| 108 if (m_sqliteTransaction->wasRolledBackBySqlite()) | 108 if (m_sqliteTransaction->wasRolledBackBySqlite()) |
| 109 return 0; | 109 return 0; |
| 110 | 110 |
| 111 if (es.code() == QuotaExceededError) { | 111 if (exceptionState.code() == QuotaExceededError) { |
| 112 if (m_transactionClient->didExceedQuota(database())) { | 112 if (m_transactionClient->didExceedQuota(database())) { |
| 113 es.clearException(); | 113 exceptionState.clearException(); |
| 114 retryStatement = true; | 114 retryStatement = true; |
| 115 } else { | 115 } else { |
| 116 m_database->setLastErrorMessage("there was not enough remain
ing storage space"); | 116 m_database->setLastErrorMessage("there was not enough remain
ing storage space"); |
| 117 return 0; | 117 return 0; |
| 118 } | 118 } |
| 119 } | 119 } |
| 120 } | 120 } |
| 121 } | 121 } |
| 122 | 122 |
| 123 if (m_database->lastActionChangedDatabase()) | 123 if (m_database->lastActionChangedDatabase()) |
| 124 m_modifiedDatabase = true; | 124 m_modifiedDatabase = true; |
| 125 | 125 |
| 126 return resultSet.release(); | 126 return resultSet.release(); |
| 127 } | 127 } |
| 128 | 128 |
| 129 void SQLTransactionBackendSync::begin(ExceptionState& es) | 129 void SQLTransactionBackendSync::begin(ExceptionState& exceptionState) |
| 130 { | 130 { |
| 131 ASSERT(m_database->executionContext()->isContextThread()); | 131 ASSERT(m_database->executionContext()->isContextThread()); |
| 132 if (!m_database->opened()) { | 132 if (!m_database->opened()) { |
| 133 m_database->reportStartTransactionResult(1, SQLError::UNKNOWN_ERR, 0); | 133 m_database->reportStartTransactionResult(1, SQLError::UNKNOWN_ERR, 0); |
| 134 m_database->setLastErrorMessage("cannot begin transaction because the da
tabase is not open"); | 134 m_database->setLastErrorMessage("cannot begin transaction because the da
tabase is not open"); |
| 135 es.throwDOMException(UnknownError, SQLError::unknownErrorMessage); | 135 exceptionState.throwDOMException(UnknownError, SQLError::unknownErrorMes
sage); |
| 136 return; | 136 return; |
| 137 } | 137 } |
| 138 | 138 |
| 139 ASSERT(!m_database->sqliteDatabase().transactionInProgress()); | 139 ASSERT(!m_database->sqliteDatabase().transactionInProgress()); |
| 140 | 140 |
| 141 // Set the maximum usage for this transaction if this transactions is not re
ad-only. | 141 // Set the maximum usage for this transaction if this transactions is not re
ad-only. |
| 142 if (!m_readOnly) | 142 if (!m_readOnly) |
| 143 m_database->sqliteDatabase().setMaximumSize(m_database->maximumSize()); | 143 m_database->sqliteDatabase().setMaximumSize(m_database->maximumSize()); |
| 144 | 144 |
| 145 ASSERT(!m_sqliteTransaction); | 145 ASSERT(!m_sqliteTransaction); |
| 146 m_sqliteTransaction = adoptPtr(new SQLiteTransaction(m_database->sqliteDatab
ase(), m_readOnly)); | 146 m_sqliteTransaction = adoptPtr(new SQLiteTransaction(m_database->sqliteDatab
ase(), m_readOnly)); |
| 147 | 147 |
| 148 m_database->resetDeletes(); | 148 m_database->resetDeletes(); |
| 149 m_database->disableAuthorizer(); | 149 m_database->disableAuthorizer(); |
| 150 m_sqliteTransaction->begin(); | 150 m_sqliteTransaction->begin(); |
| 151 m_database->enableAuthorizer(); | 151 m_database->enableAuthorizer(); |
| 152 | 152 |
| 153 // Check if begin() succeeded. | 153 // Check if begin() succeeded. |
| 154 if (!m_sqliteTransaction->inProgress()) { | 154 if (!m_sqliteTransaction->inProgress()) { |
| 155 ASSERT(!m_database->sqliteDatabase().transactionInProgress()); | 155 ASSERT(!m_database->sqliteDatabase().transactionInProgress()); |
| 156 m_database->reportStartTransactionResult(2, SQLError::DATABASE_ERR, m_da
tabase->sqliteDatabase().lastError()); | 156 m_database->reportStartTransactionResult(2, SQLError::DATABASE_ERR, m_da
tabase->sqliteDatabase().lastError()); |
| 157 m_database->setLastErrorMessage("unable to begin transaction", | 157 m_database->setLastErrorMessage("unable to begin transaction", |
| 158 m_database->sqliteDatabase().lastError(), m_database->sqliteDatabase
().lastErrorMsg()); | 158 m_database->sqliteDatabase().lastError(), m_database->sqliteDatabase
().lastErrorMsg()); |
| 159 m_sqliteTransaction.clear(); | 159 m_sqliteTransaction.clear(); |
| 160 es.throwUninformativeAndGenericDOMException(SQLDatabaseError); | 160 exceptionState.throwUninformativeAndGenericDOMException(SQLDatabaseError
); |
| 161 return; | 161 return; |
| 162 } | 162 } |
| 163 | 163 |
| 164 // Note: We intentionally retrieve the actual version even with an empty exp
ected version. | 164 // Note: We intentionally retrieve the actual version even with an empty exp
ected version. |
| 165 // In multi-process browsers, we take this opportinutiy to update the cached
value for | 165 // In multi-process browsers, we take this opportinutiy to update the cached
value for |
| 166 // the actual version. In single-process browsers, this is just a map lookup
. | 166 // the actual version. In single-process browsers, this is just a map lookup
. |
| 167 String actualVersion; | 167 String actualVersion; |
| 168 if (!m_database->getActualVersionForTransaction(actualVersion)) { | 168 if (!m_database->getActualVersionForTransaction(actualVersion)) { |
| 169 m_database->reportStartTransactionResult(3, SQLError::DATABASE_ERR, m_da
tabase->sqliteDatabase().lastError()); | 169 m_database->reportStartTransactionResult(3, SQLError::DATABASE_ERR, m_da
tabase->sqliteDatabase().lastError()); |
| 170 m_database->setLastErrorMessage("unable to read version", | 170 m_database->setLastErrorMessage("unable to read version", |
| 171 m_database->sqliteDatabase().lastError(), m_database->sqliteDatabase
().lastErrorMsg()); | 171 m_database->sqliteDatabase().lastError(), m_database->sqliteDatabase
().lastErrorMsg()); |
| 172 rollback(); | 172 rollback(); |
| 173 es.throwUninformativeAndGenericDOMException(SQLDatabaseError); | 173 exceptionState.throwUninformativeAndGenericDOMException(SQLDatabaseError
); |
| 174 return; | 174 return; |
| 175 } | 175 } |
| 176 m_hasVersionMismatch = !m_database->expectedVersion().isEmpty() && (m_databa
se->expectedVersion() != actualVersion); | 176 m_hasVersionMismatch = !m_database->expectedVersion().isEmpty() && (m_databa
se->expectedVersion() != actualVersion); |
| 177 m_database->reportStartTransactionResult(0, -1, 0); // OK | 177 m_database->reportStartTransactionResult(0, -1, 0); // OK |
| 178 } | 178 } |
| 179 | 179 |
| 180 void SQLTransactionBackendSync::execute(ExceptionState& es) | 180 void SQLTransactionBackendSync::execute(ExceptionState& exceptionState) |
| 181 { | 181 { |
| 182 ASSERT(m_database->executionContext()->isContextThread()); | 182 ASSERT(m_database->executionContext()->isContextThread()); |
| 183 if (!m_database->opened() || (m_callback && !m_callback->handleEvent(SQLTran
sactionSync::from(this)))) { | 183 if (!m_database->opened() || (m_callback && !m_callback->handleEvent(SQLTran
sactionSync::from(this)))) { |
| 184 if (m_database->lastErrorMessage().isEmpty()) | 184 if (m_database->lastErrorMessage().isEmpty()) |
| 185 m_database->setLastErrorMessage("failed to execute transaction callb
ack"); | 185 m_database->setLastErrorMessage("failed to execute transaction callb
ack"); |
| 186 m_callback = 0; | 186 m_callback = 0; |
| 187 es.throwDOMException(UnknownError, SQLError::unknownErrorMessage); | 187 exceptionState.throwDOMException(UnknownError, SQLError::unknownErrorMes
sage); |
| 188 return; | 188 return; |
| 189 } | 189 } |
| 190 | 190 |
| 191 m_callback = 0; | 191 m_callback = 0; |
| 192 } | 192 } |
| 193 | 193 |
| 194 void SQLTransactionBackendSync::commit(ExceptionState& es) | 194 void SQLTransactionBackendSync::commit(ExceptionState& exceptionState) |
| 195 { | 195 { |
| 196 ASSERT(m_database->executionContext()->isContextThread()); | 196 ASSERT(m_database->executionContext()->isContextThread()); |
| 197 if (!m_database->opened()) { | 197 if (!m_database->opened()) { |
| 198 m_database->reportCommitTransactionResult(1, SQLError::UNKNOWN_ERR, 0); | 198 m_database->reportCommitTransactionResult(1, SQLError::UNKNOWN_ERR, 0); |
| 199 m_database->setLastErrorMessage("unable to commit transaction because th
e database is not open."); | 199 m_database->setLastErrorMessage("unable to commit transaction because th
e database is not open."); |
| 200 es.throwDOMException(UnknownError, SQLError::unknownErrorMessage); | 200 exceptionState.throwDOMException(UnknownError, SQLError::unknownErrorMes
sage); |
| 201 return; | 201 return; |
| 202 } | 202 } |
| 203 | 203 |
| 204 ASSERT(m_sqliteTransaction); | 204 ASSERT(m_sqliteTransaction); |
| 205 | 205 |
| 206 m_database->disableAuthorizer(); | 206 m_database->disableAuthorizer(); |
| 207 m_sqliteTransaction->commit(); | 207 m_sqliteTransaction->commit(); |
| 208 m_database->enableAuthorizer(); | 208 m_database->enableAuthorizer(); |
| 209 | 209 |
| 210 // If the commit failed, the transaction will still be marked as "in progres
s" | 210 // If the commit failed, the transaction will still be marked as "in progres
s" |
| 211 if (m_sqliteTransaction->inProgress()) { | 211 if (m_sqliteTransaction->inProgress()) { |
| 212 m_database->reportCommitTransactionResult(2, SQLError::DATABASE_ERR, m_d
atabase->sqliteDatabase().lastError()); | 212 m_database->reportCommitTransactionResult(2, SQLError::DATABASE_ERR, m_d
atabase->sqliteDatabase().lastError()); |
| 213 m_database->setLastErrorMessage("unable to commit transaction", | 213 m_database->setLastErrorMessage("unable to commit transaction", |
| 214 m_database->sqliteDatabase().lastError(), m_database->sqliteDatabase
().lastErrorMsg()); | 214 m_database->sqliteDatabase().lastError(), m_database->sqliteDatabase
().lastErrorMsg()); |
| 215 es.throwUninformativeAndGenericDOMException(SQLDatabaseError); | 215 exceptionState.throwUninformativeAndGenericDOMException(SQLDatabaseError
); |
| 216 return; | 216 return; |
| 217 } | 217 } |
| 218 | 218 |
| 219 m_sqliteTransaction.clear(); | 219 m_sqliteTransaction.clear(); |
| 220 | 220 |
| 221 // Vacuum the database if anything was deleted. | 221 // Vacuum the database if anything was deleted. |
| 222 if (m_database->hadDeletes()) | 222 if (m_database->hadDeletes()) |
| 223 m_database->incrementalVacuumIfNeeded(); | 223 m_database->incrementalVacuumIfNeeded(); |
| 224 | 224 |
| 225 // The commit was successful. If the transaction modified this database, not
ify the delegates. | 225 // The commit was successful. If the transaction modified this database, not
ify the delegates. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 236 if (m_sqliteTransaction) { | 236 if (m_sqliteTransaction) { |
| 237 m_sqliteTransaction->rollback(); | 237 m_sqliteTransaction->rollback(); |
| 238 m_sqliteTransaction.clear(); | 238 m_sqliteTransaction.clear(); |
| 239 } | 239 } |
| 240 m_database->enableAuthorizer(); | 240 m_database->enableAuthorizer(); |
| 241 | 241 |
| 242 ASSERT(!m_database->sqliteDatabase().transactionInProgress()); | 242 ASSERT(!m_database->sqliteDatabase().transactionInProgress()); |
| 243 } | 243 } |
| 244 | 244 |
| 245 } // namespace WebCore | 245 } // namespace WebCore |
| OLD | NEW |