| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com) | 3 * Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com) |
| 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 | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 } | 82 } |
| 83 | 83 |
| 84 if (isOpen()) | 84 if (isOpen()) |
| 85 m_openingThread = currentThread(); | 85 m_openingThread = currentThread(); |
| 86 else | 86 else |
| 87 m_openErrorMessage = "sqlite_open returned null"; | 87 m_openErrorMessage = "sqlite_open returned null"; |
| 88 | 88 |
| 89 if (!SQLiteStatement(*this, "PRAGMA temp_store = MEMORY;").executeCommand()) | 89 if (!SQLiteStatement(*this, "PRAGMA temp_store = MEMORY;").executeCommand()) |
| 90 DLOG(ERROR) << "SQLite database could not set temp_store to memory"; | 90 DLOG(ERROR) << "SQLite database could not set temp_store to memory"; |
| 91 | 91 |
| 92 // Foreign keys are not supported by WebDatabase. Make sure foreign key suppo
rt is consistent | 92 // Foreign keys are not supported by WebDatabase. Make sure foreign key |
| 93 // if SQLite has SQLITE_DEFAULT_FOREIGN_KEYS. | 93 // support is consistent if SQLite has SQLITE_DEFAULT_FOREIGN_KEYS. |
| 94 if (!SQLiteStatement(*this, "PRAGMA foreign_keys = OFF;").executeCommand()) | 94 if (!SQLiteStatement(*this, "PRAGMA foreign_keys = OFF;").executeCommand()) |
| 95 DLOG(ERROR) << "SQLite database could not turn off foreign_keys"; | 95 DLOG(ERROR) << "SQLite database could not turn off foreign_keys"; |
| 96 | 96 |
| 97 return isOpen(); | 97 return isOpen(); |
| 98 } | 98 } |
| 99 | 99 |
| 100 void SQLiteDatabase::close() { | 100 void SQLiteDatabase::close() { |
| 101 if (m_db) { | 101 if (m_db) { |
| 102 // FIXME: This is being called on the main thread during JS GC. <rdar://prob
lem/5739818> | 102 // FIXME: This is being called on the main thread during JS GC. |
| 103 // <rdar://problem/5739818> |
| 103 // ASSERT(currentThread() == m_openingThread); | 104 // ASSERT(currentThread() == m_openingThread); |
| 104 sqlite3* db = m_db; | 105 sqlite3* db = m_db; |
| 105 { | 106 { |
| 106 MutexLocker locker(m_databaseClosingMutex); | 107 MutexLocker locker(m_databaseClosingMutex); |
| 107 m_db = 0; | 108 m_db = 0; |
| 108 } | 109 } |
| 109 sqlite3_close(db); | 110 sqlite3_close(db); |
| 110 } | 111 } |
| 111 | 112 |
| 112 m_openingThread = 0; | 113 m_openingThread = 0; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 130 *this, "PRAGMA max_page_count = " + String::number(newMaxPageCount)); | 131 *this, "PRAGMA max_page_count = " + String::number(newMaxPageCount)); |
| 131 statement.prepare(); | 132 statement.prepare(); |
| 132 if (statement.step() != SQLResultRow) | 133 if (statement.step() != SQLResultRow) |
| 133 DLOG(ERROR) << "Failed to set maximum size of database to " << size | 134 DLOG(ERROR) << "Failed to set maximum size of database to " << size |
| 134 << " bytes"; | 135 << " bytes"; |
| 135 | 136 |
| 136 enableAuthorizer(true); | 137 enableAuthorizer(true); |
| 137 } | 138 } |
| 138 | 139 |
| 139 int SQLiteDatabase::pageSize() { | 140 int SQLiteDatabase::pageSize() { |
| 140 // Since the page size of a database is locked in at creation and therefore ca
nnot be dynamic, | 141 // Since the page size of a database is locked in at creation and therefore |
| 141 // we can cache the value for future use | 142 // cannot be dynamic, we can cache the value for future use. |
| 142 if (m_pageSize == -1) { | 143 if (m_pageSize == -1) { |
| 143 MutexLocker locker(m_authorizerLock); | 144 MutexLocker locker(m_authorizerLock); |
| 144 enableAuthorizer(false); | 145 enableAuthorizer(false); |
| 145 | 146 |
| 146 SQLiteStatement statement(*this, "PRAGMA page_size"); | 147 SQLiteStatement statement(*this, "PRAGMA page_size"); |
| 147 m_pageSize = statement.getColumnInt(0); | 148 m_pageSize = statement.getColumnInt(0); |
| 148 | 149 |
| 149 enableAuthorizer(true); | 150 enableAuthorizer(true); |
| 150 } | 151 } |
| 151 | 152 |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 } | 360 } |
| 360 | 361 |
| 361 bool SQLiteDatabase::turnOnIncrementalAutoVacuum() { | 362 bool SQLiteDatabase::turnOnIncrementalAutoVacuum() { |
| 362 SQLiteStatement statement(*this, "PRAGMA auto_vacuum"); | 363 SQLiteStatement statement(*this, "PRAGMA auto_vacuum"); |
| 363 int autoVacuumMode = statement.getColumnInt(0); | 364 int autoVacuumMode = statement.getColumnInt(0); |
| 364 int error = lastError(); | 365 int error = lastError(); |
| 365 | 366 |
| 366 // Finalize statement to not block potential VACUUM. | 367 // Finalize statement to not block potential VACUUM. |
| 367 statement.finalize(); | 368 statement.finalize(); |
| 368 | 369 |
| 369 // Check if we got an error while trying to get the value of the auto_vacuum f
lag. | 370 // Check if we got an error while trying to get the value of the auto_vacuum |
| 370 // If we got a SQLITE_BUSY error, then there's probably another transaction in | 371 // flag. If we got a SQLITE_BUSY error, then there's probably another |
| 371 // progress on this database. In this case, keep the current value of the | 372 // transaction in progress on this database. In this case, keep the current |
| 372 // auto_vacuum flag and try to set it to INCREMENTAL the next time we open thi
s | 373 // value of the auto_vacuum flag and try to set it to INCREMENTAL the next |
| 373 // database. If the error is not SQLITE_BUSY, then we probably ran into a more | 374 // time we open this database. If the error is not SQLITE_BUSY, then we |
| 374 // serious problem and should return false (to log an error message). | 375 // probably ran into a more serious problem and should return false (to log an |
| 376 // error message). |
| 375 if (error != SQLITE_ROW) | 377 if (error != SQLITE_ROW) |
| 376 return false; | 378 return false; |
| 377 | 379 |
| 378 switch (autoVacuumMode) { | 380 switch (autoVacuumMode) { |
| 379 case AutoVacuumIncremental: | 381 case AutoVacuumIncremental: |
| 380 return true; | 382 return true; |
| 381 case AutoVacuumFull: | 383 case AutoVacuumFull: |
| 382 return executeCommand("PRAGMA auto_vacuum = 2"); | 384 return executeCommand("PRAGMA auto_vacuum = 2"); |
| 383 case AutoVacuumNone: | 385 case AutoVacuumNone: |
| 384 default: | 386 default: |
| 385 if (!executeCommand("PRAGMA auto_vacuum = 2")) | 387 if (!executeCommand("PRAGMA auto_vacuum = 2")) |
| 386 return false; | 388 return false; |
| 387 runVacuumCommand(); | 389 runVacuumCommand(); |
| 388 error = lastError(); | 390 error = lastError(); |
| 389 return (error == SQLITE_OK); | 391 return (error == SQLITE_OK); |
| 390 } | 392 } |
| 391 } | 393 } |
| 392 | 394 |
| 393 } // namespace blink | 395 } // namespace blink |
| OLD | NEW |