| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google 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 are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 | 51 |
| 52 PassRefPtr<SQLTransactionSync> SQLTransactionSync::create(DatabaseSync* db, Pass
RefPtr<SQLTransactionSyncCallback> callback, bool readOnly) | 52 PassRefPtr<SQLTransactionSync> SQLTransactionSync::create(DatabaseSync* db, Pass
RefPtr<SQLTransactionSyncCallback> callback, bool readOnly) |
| 53 { | 53 { |
| 54 return adoptRef(new SQLTransactionSync(db, callback, readOnly)); | 54 return adoptRef(new SQLTransactionSync(db, callback, readOnly)); |
| 55 } | 55 } |
| 56 | 56 |
| 57 SQLTransactionSync::SQLTransactionSync(DatabaseSync* db, PassRefPtr<SQLTransacti
onSyncCallback> callback, bool readOnly) | 57 SQLTransactionSync::SQLTransactionSync(DatabaseSync* db, PassRefPtr<SQLTransacti
onSyncCallback> callback, bool readOnly) |
| 58 : m_database(db) | 58 : m_database(db) |
| 59 , m_callback(callback) | 59 , m_callback(callback) |
| 60 , m_readOnly(readOnly) | 60 , m_readOnly(readOnly) |
| 61 , m_hasVersionMismatch(false) |
| 61 , m_modifiedDatabase(false) | 62 , m_modifiedDatabase(false) |
| 62 , m_transactionClient(adoptPtr(new SQLTransactionClient())) | 63 , m_transactionClient(adoptPtr(new SQLTransactionClient())) |
| 63 { | 64 { |
| 64 ASSERT(m_database->scriptExecutionContext()->isContextThread()); | 65 ASSERT(m_database->scriptExecutionContext()->isContextThread()); |
| 65 } | 66 } |
| 66 | 67 |
| 67 SQLTransactionSync::~SQLTransactionSync() | 68 SQLTransactionSync::~SQLTransactionSync() |
| 68 { | 69 { |
| 69 ASSERT(m_database->scriptExecutionContext()->isContextThread()); | 70 ASSERT(m_database->scriptExecutionContext()->isContextThread()); |
| 70 if (m_sqliteTransaction && m_sqliteTransaction->inProgress()) | 71 if (m_sqliteTransaction && m_sqliteTransaction->inProgress()) |
| 71 rollback(); | 72 rollback(); |
| 72 } | 73 } |
| 73 | 74 |
| 74 PassRefPtr<SQLResultSet> SQLTransactionSync::executeSQL(const String& sqlStateme
nt, const Vector<SQLValue>& arguments, ExceptionCode& ec) | 75 PassRefPtr<SQLResultSet> SQLTransactionSync::executeSQL(const String& sqlStateme
nt, const Vector<SQLValue>& arguments, ExceptionCode& ec) |
| 75 { | 76 { |
| 76 ASSERT(m_database->scriptExecutionContext()->isContextThread()); | 77 ASSERT(m_database->scriptExecutionContext()->isContextThread()); |
| 77 if (!m_database->opened()) { | 78 if (!m_database->opened()) { |
| 78 ec = SQLException::UNKNOWN_ERR; | 79 ec = SQLException::UNKNOWN_ERR; |
| 79 return 0; | 80 return 0; |
| 80 } | 81 } |
| 81 | 82 |
| 82 if (!m_database->versionMatchesExpected()) { | 83 if (m_hasVersionMismatch) { |
| 83 ec = SQLException::VERSION_ERR; | 84 ec = SQLException::VERSION_ERR; |
| 84 return 0; | 85 return 0; |
| 85 } | 86 } |
| 86 | 87 |
| 87 if (sqlStatement.isEmpty()) | 88 if (sqlStatement.isEmpty()) |
| 88 return 0; | 89 return 0; |
| 89 | 90 |
| 90 int permissions = DatabaseAuthorizer::ReadWriteMask; | 91 int permissions = DatabaseAuthorizer::ReadWriteMask; |
| 91 if (!m_database->scriptExecutionContext()->allowDatabaseAccess()) | 92 if (!m_database->scriptExecutionContext()->allowDatabaseAccess()) |
| 92 permissions |= DatabaseAuthorizer::NoAccessMask; | 93 permissions |= DatabaseAuthorizer::NoAccessMask; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 m_sqliteTransaction->begin(); | 144 m_sqliteTransaction->begin(); |
| 144 m_database->enableAuthorizer(); | 145 m_database->enableAuthorizer(); |
| 145 | 146 |
| 146 // Check if begin() succeeded. | 147 // Check if begin() succeeded. |
| 147 if (!m_sqliteTransaction->inProgress()) { | 148 if (!m_sqliteTransaction->inProgress()) { |
| 148 ASSERT(!m_database->sqliteDatabase().transactionInProgress()); | 149 ASSERT(!m_database->sqliteDatabase().transactionInProgress()); |
| 149 m_sqliteTransaction.clear(); | 150 m_sqliteTransaction.clear(); |
| 150 return SQLException::DATABASE_ERR; | 151 return SQLException::DATABASE_ERR; |
| 151 } | 152 } |
| 152 | 153 |
| 154 // Note: We intentionally retrieve the actual version even with an empty exp
ected version. |
| 155 // In multi-process browsers, we take this opportinutiy to update the cached
value for |
| 156 // the actual version. In single-process browsers, this is just a map lookup
. |
| 157 String actualVersion; |
| 158 if (!m_database->getActualVersionForTransaction(actualVersion)) { |
| 159 rollback(); |
| 160 return SQLException::DATABASE_ERR; |
| 161 } |
| 162 m_hasVersionMismatch = !m_database->expectedVersion().isEmpty() |
| 163 && (m_database->expectedVersion() != actualVersion); |
| 153 return 0; | 164 return 0; |
| 154 } | 165 } |
| 155 | 166 |
| 156 ExceptionCode SQLTransactionSync::execute() | 167 ExceptionCode SQLTransactionSync::execute() |
| 157 { | 168 { |
| 158 ASSERT(m_database->scriptExecutionContext()->isContextThread()); | 169 ASSERT(m_database->scriptExecutionContext()->isContextThread()); |
| 159 if (!m_database->opened() || (m_callback && !m_callback->handleEvent(this)))
{ | 170 if (!m_database->opened() || (m_callback && !m_callback->handleEvent(this)))
{ |
| 160 m_callback = 0; | 171 m_callback = 0; |
| 161 return SQLException::UNKNOWN_ERR; | 172 return SQLException::UNKNOWN_ERR; |
| 162 } | 173 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 m_sqliteTransaction.clear(); | 214 m_sqliteTransaction.clear(); |
| 204 } | 215 } |
| 205 m_database->enableAuthorizer(); | 216 m_database->enableAuthorizer(); |
| 206 | 217 |
| 207 ASSERT(!m_database->sqliteDatabase().transactionInProgress()); | 218 ASSERT(!m_database->sqliteDatabase().transactionInProgress()); |
| 208 } | 219 } |
| 209 | 220 |
| 210 } // namespace WebCore | 221 } // namespace WebCore |
| 211 | 222 |
| 212 #endif // ENABLE(DATABASE) | 223 #endif // ENABLE(DATABASE) |
| OLD | NEW |