Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(480)

Side by Side Diff: Source/core/platform/sql/SQLiteDatabase.cpp

Issue 22572005: Remove all uses of the ASCIILiteral class. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rm it from wtf Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 sqlite3_close(m_db); 88 sqlite3_close(m_db);
89 m_db = 0; 89 m_db = 0;
90 return false; 90 return false;
91 } 91 }
92 92
93 if (isOpen()) 93 if (isOpen())
94 m_openingThread = currentThread(); 94 m_openingThread = currentThread();
95 else 95 else
96 m_openErrorMessage = "sqlite_open returned null"; 96 m_openErrorMessage = "sqlite_open returned null";
97 97
98 if (!SQLiteStatement(*this, ASCIILiteral("PRAGMA temp_store = MEMORY;")).exe cuteCommand()) 98 if (!SQLiteStatement(*this, "PRAGMA temp_store = MEMORY;").executeCommand())
99 LOG_ERROR("SQLite database could not set temp_store to memory"); 99 LOG_ERROR("SQLite database could not set temp_store to memory");
100 100
101 return isOpen(); 101 return isOpen();
102 } 102 }
103 103
104 void SQLiteDatabase::close() 104 void SQLiteDatabase::close()
105 { 105 {
106 if (m_db) { 106 if (m_db) {
107 // FIXME: This is being called on the main thread during JS GC. <rdar:// problem/5739818> 107 // FIXME: This is being called on the main thread during JS GC. <rdar:// problem/5739818>
108 // ASSERT(currentThread() == m_openingThread); 108 // ASSERT(currentThread() == m_openingThread);
(...skipping 26 matching lines...) Expand all
135 135
136 bool SQLiteDatabase::isInterrupted() 136 bool SQLiteDatabase::isInterrupted()
137 { 137 {
138 ASSERT(!m_lockingMutex.tryLock()); 138 ASSERT(!m_lockingMutex.tryLock());
139 return m_interrupted; 139 return m_interrupted;
140 } 140 }
141 141
142 void SQLiteDatabase::setFullsync(bool fsync) 142 void SQLiteDatabase::setFullsync(bool fsync)
143 { 143 {
144 if (fsync) 144 if (fsync)
145 executeCommand(ASCIILiteral("PRAGMA fullfsync = 1;")); 145 executeCommand("PRAGMA fullfsync = 1;");
146 else 146 else
147 executeCommand(ASCIILiteral("PRAGMA fullfsync = 0;")); 147 executeCommand("PRAGMA fullfsync = 0;");
148 } 148 }
149 149
150 int64_t SQLiteDatabase::maximumSize() 150 int64_t SQLiteDatabase::maximumSize()
151 { 151 {
152 int64_t maxPageCount = 0; 152 int64_t maxPageCount = 0;
153 153
154 { 154 {
155 MutexLocker locker(m_authorizerLock); 155 MutexLocker locker(m_authorizerLock);
156 enableAuthorizer(false); 156 enableAuthorizer(false);
157 SQLiteStatement statement(*this, ASCIILiteral("PRAGMA max_page_count")); 157 SQLiteStatement statement(*this, "PRAGMA max_page_count");
158 maxPageCount = statement.getColumnInt64(0); 158 maxPageCount = statement.getColumnInt64(0);
159 enableAuthorizer(true); 159 enableAuthorizer(true);
160 } 160 }
161 161
162 return maxPageCount * pageSize(); 162 return maxPageCount * pageSize();
163 } 163 }
164 164
165 void SQLiteDatabase::setMaximumSize(int64_t size) 165 void SQLiteDatabase::setMaximumSize(int64_t size)
166 { 166 {
167 if (size < 0) 167 if (size < 0)
(...skipping 21 matching lines...) Expand all
189 } 189 }
190 190
191 int SQLiteDatabase::pageSize() 191 int SQLiteDatabase::pageSize()
192 { 192 {
193 // Since the page size of a database is locked in at creation and therefore cannot be dynamic, 193 // Since the page size of a database is locked in at creation and therefore cannot be dynamic,
194 // we can cache the value for future use 194 // we can cache the value for future use
195 if (m_pageSize == -1) { 195 if (m_pageSize == -1) {
196 MutexLocker locker(m_authorizerLock); 196 MutexLocker locker(m_authorizerLock);
197 enableAuthorizer(false); 197 enableAuthorizer(false);
198 198
199 SQLiteStatement statement(*this, ASCIILiteral("PRAGMA page_size")); 199 SQLiteStatement statement(*this, "PRAGMA page_size");
200 m_pageSize = statement.getColumnInt(0); 200 m_pageSize = statement.getColumnInt(0);
201 201
202 enableAuthorizer(true); 202 enableAuthorizer(true);
203 } 203 }
204 204
205 return m_pageSize; 205 return m_pageSize;
206 } 206 }
207 207
208 int64_t SQLiteDatabase::freeSpaceSize() 208 int64_t SQLiteDatabase::freeSpaceSize()
209 { 209 {
210 int64_t freelistCount = 0; 210 int64_t freelistCount = 0;
211 211
212 { 212 {
213 MutexLocker locker(m_authorizerLock); 213 MutexLocker locker(m_authorizerLock);
214 enableAuthorizer(false); 214 enableAuthorizer(false);
215 // Note: freelist_count was added in SQLite 3.4.1. 215 // Note: freelist_count was added in SQLite 3.4.1.
216 SQLiteStatement statement(*this, ASCIILiteral("PRAGMA freelist_count")); 216 SQLiteStatement statement(*this, "PRAGMA freelist_count");
217 freelistCount = statement.getColumnInt64(0); 217 freelistCount = statement.getColumnInt64(0);
218 enableAuthorizer(true); 218 enableAuthorizer(true);
219 } 219 }
220 220
221 return freelistCount * pageSize(); 221 return freelistCount * pageSize();
222 } 222 }
223 223
224 int64_t SQLiteDatabase::totalSize() 224 int64_t SQLiteDatabase::totalSize()
225 { 225 {
226 int64_t pageCount = 0; 226 int64_t pageCount = 0;
227 227
228 { 228 {
229 MutexLocker locker(m_authorizerLock); 229 MutexLocker locker(m_authorizerLock);
230 enableAuthorizer(false); 230 enableAuthorizer(false);
231 SQLiteStatement statement(*this, ASCIILiteral("PRAGMA page_count")); 231 SQLiteStatement statement(*this, "PRAGMA page_count");
232 pageCount = statement.getColumnInt64(0); 232 pageCount = statement.getColumnInt64(0);
233 enableAuthorizer(true); 233 enableAuthorizer(true);
234 } 234 }
235 235
236 return pageCount * pageSize(); 236 return pageCount * pageSize();
237 } 237 }
238 238
239 void SQLiteDatabase::setSynchronous(SynchronousPragma sync) 239 void SQLiteDatabase::setSynchronous(SynchronousPragma sync)
240 { 240 {
241 executeCommand("PRAGMA synchronous = " + String::number(sync)); 241 executeCommand("PRAGMA synchronous = " + String::number(sync));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 274
275 String statement = "SELECT name FROM sqlite_master WHERE type = 'table' AND name = '" + tablename + "';"; 275 String statement = "SELECT name FROM sqlite_master WHERE type = 'table' AND name = '" + tablename + "';";
276 276
277 SQLiteStatement sql(*this, statement); 277 SQLiteStatement sql(*this, statement);
278 sql.prepare(); 278 sql.prepare();
279 return sql.step() == SQLITE_ROW; 279 return sql.step() == SQLITE_ROW;
280 } 280 }
281 281
282 void SQLiteDatabase::clearAllTables() 282 void SQLiteDatabase::clearAllTables()
283 { 283 {
284 String query = ASCIILiteral("SELECT name FROM sqlite_master WHERE type='tabl e';"); 284 String query = "SELECT name FROM sqlite_master WHERE type='table';";
285 Vector<String> tables; 285 Vector<String> tables;
286 if (!SQLiteStatement(*this, query).returnTextResults(0, tables)) { 286 if (!SQLiteStatement(*this, query).returnTextResults(0, tables)) {
287 LOG(SQLDatabase, "Unable to retrieve list of tables from database"); 287 LOG(SQLDatabase, "Unable to retrieve list of tables from database");
288 return; 288 return;
289 } 289 }
290 290
291 for (Vector<String>::iterator table = tables.begin(); table != tables.end(); ++table ) { 291 for (Vector<String>::iterator table = tables.begin(); table != tables.end(); ++table ) {
292 if (*table == "sqlite_sequence") 292 if (*table == "sqlite_sequence")
293 continue; 293 continue;
294 if (!executeCommand("DROP TABLE " + *table)) 294 if (!executeCommand("DROP TABLE " + *table))
295 LOG(SQLDatabase, "Unable to drop table %s", (*table).ascii().data()) ; 295 LOG(SQLDatabase, "Unable to drop table %s", (*table).ascii().data()) ;
296 } 296 }
297 } 297 }
298 298
299 int SQLiteDatabase::runVacuumCommand() 299 int SQLiteDatabase::runVacuumCommand()
300 { 300 {
301 if (!executeCommand(ASCIILiteral("VACUUM;"))) 301 if (!executeCommand("VACUUM;"))
302 LOG(SQLDatabase, "Unable to vacuum database - %s", lastErrorMsg()); 302 LOG(SQLDatabase, "Unable to vacuum database - %s", lastErrorMsg());
303 return lastError(); 303 return lastError();
304 } 304 }
305 305
306 int SQLiteDatabase::runIncrementalVacuumCommand() 306 int SQLiteDatabase::runIncrementalVacuumCommand()
307 { 307 {
308 MutexLocker locker(m_authorizerLock); 308 MutexLocker locker(m_authorizerLock);
309 enableAuthorizer(false); 309 enableAuthorizer(false);
310 310
311 if (!executeCommand(ASCIILiteral("PRAGMA incremental_vacuum"))) 311 if (!executeCommand("PRAGMA incremental_vacuum"))
312 LOG(SQLDatabase, "Unable to run incremental vacuum - %s", lastErrorMsg() ); 312 LOG(SQLDatabase, "Unable to run incremental vacuum - %s", lastErrorMsg() );
313 313
314 enableAuthorizer(true); 314 enableAuthorizer(true);
315 return lastError(); 315 return lastError();
316 } 316 }
317 317
318 int64_t SQLiteDatabase::lastInsertRowID() 318 int64_t SQLiteDatabase::lastInsertRowID()
319 { 319 {
320 if (!m_db) 320 if (!m_db)
321 return 0; 321 return 0;
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 sqlite3_set_authorizer(m_db, NULL, 0); 461 sqlite3_set_authorizer(m_db, NULL, 0);
462 } 462 }
463 463
464 bool SQLiteDatabase::isAutoCommitOn() const 464 bool SQLiteDatabase::isAutoCommitOn() const
465 { 465 {
466 return sqlite3_get_autocommit(m_db); 466 return sqlite3_get_autocommit(m_db);
467 } 467 }
468 468
469 bool SQLiteDatabase::turnOnIncrementalAutoVacuum() 469 bool SQLiteDatabase::turnOnIncrementalAutoVacuum()
470 { 470 {
471 SQLiteStatement statement(*this, ASCIILiteral("PRAGMA auto_vacuum")); 471 SQLiteStatement statement(*this, "PRAGMA auto_vacuum");
472 int autoVacuumMode = statement.getColumnInt(0); 472 int autoVacuumMode = statement.getColumnInt(0);
473 int error = lastError(); 473 int error = lastError();
474 474
475 // Check if we got an error while trying to get the value of the auto_vacuum flag. 475 // Check if we got an error while trying to get the value of the auto_vacuum flag.
476 // If we got a SQLITE_BUSY error, then there's probably another transaction in 476 // If we got a SQLITE_BUSY error, then there's probably another transaction in
477 // progress on this database. In this case, keep the current value of the 477 // progress on this database. In this case, keep the current value of the
478 // auto_vacuum flag and try to set it to INCREMENTAL the next time we open t his 478 // auto_vacuum flag and try to set it to INCREMENTAL the next time we open t his
479 // database. If the error is not SQLITE_BUSY, then we probably ran into a mo re 479 // database. If the error is not SQLITE_BUSY, then we probably ran into a mo re
480 // serious problem and should return false (to log an error message). 480 // serious problem and should return false (to log an error message).
481 if (error != SQLITE_ROW) 481 if (error != SQLITE_ROW)
482 return false; 482 return false;
483 483
484 switch (autoVacuumMode) { 484 switch (autoVacuumMode) {
485 case AutoVacuumIncremental: 485 case AutoVacuumIncremental:
486 return true; 486 return true;
487 case AutoVacuumFull: 487 case AutoVacuumFull:
488 return executeCommand(ASCIILiteral("PRAGMA auto_vacuum = 2")); 488 return executeCommand("PRAGMA auto_vacuum = 2");
489 case AutoVacuumNone: 489 case AutoVacuumNone:
490 default: 490 default:
491 if (!executeCommand(ASCIILiteral("PRAGMA auto_vacuum = 2"))) 491 if (!executeCommand("PRAGMA auto_vacuum = 2"))
492 return false; 492 return false;
493 runVacuumCommand(); 493 runVacuumCommand();
494 error = lastError(); 494 error = lastError();
495 return (error == SQLITE_OK); 495 return (error == SQLITE_OK);
496 } 496 }
497 } 497 }
498 498
499 } // namespace WebCore 499 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/platform/network/HTTPParsers.cpp ('k') | Source/core/platform/text/DateTimeFormat.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698