| 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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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)); |
| 242 } | 242 } |
| 243 | 243 |
| 244 void SQLiteDatabase::setBusyTimeout(int ms) | 244 void SQLiteDatabase::setBusyTimeout(int ms) |
| 245 { | 245 { |
| 246 if (m_db) | 246 if (m_db) |
| 247 sqlite3_busy_timeout(m_db, ms); | 247 sqlite3_busy_timeout(m_db, ms); |
| 248 else | 248 else |
| 249 LOG(SQLDatabase, "BusyTimeout set on non-open database"); | 249 LOG_INFO(SQLDatabase, "BusyTimeout set on non-open database"); |
| 250 } | 250 } |
| 251 | 251 |
| 252 void SQLiteDatabase::setBusyHandler(int(*handler)(void*, int)) | 252 void SQLiteDatabase::setBusyHandler(int(*handler)(void*, int)) |
| 253 { | 253 { |
| 254 if (m_db) | 254 if (m_db) |
| 255 sqlite3_busy_handler(m_db, handler, NULL); | 255 sqlite3_busy_handler(m_db, handler, NULL); |
| 256 else | 256 else |
| 257 LOG(SQLDatabase, "Busy handler set on non-open database"); | 257 LOG_INFO(SQLDatabase, "Busy handler set on non-open database"); |
| 258 } | 258 } |
| 259 | 259 |
| 260 bool SQLiteDatabase::executeCommand(const String& sql) | 260 bool SQLiteDatabase::executeCommand(const String& sql) |
| 261 { | 261 { |
| 262 return SQLiteStatement(*this, sql).executeCommand(); | 262 return SQLiteStatement(*this, sql).executeCommand(); |
| 263 } | 263 } |
| 264 | 264 |
| 265 bool SQLiteDatabase::returnsAtLeastOneResult(const String& sql) | 265 bool SQLiteDatabase::returnsAtLeastOneResult(const String& sql) |
| 266 { | 266 { |
| 267 return SQLiteStatement(*this, sql).returnsAtLeastOneResult(); | 267 return SQLiteStatement(*this, sql).returnsAtLeastOneResult(); |
| 268 } | 268 } |
| 269 | 269 |
| 270 bool SQLiteDatabase::tableExists(const String& tablename) | 270 bool SQLiteDatabase::tableExists(const String& tablename) |
| 271 { | 271 { |
| 272 if (!isOpen()) | 272 if (!isOpen()) |
| 273 return false; | 273 return false; |
| 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 = ASCIILiteral("SELECT name FROM sqlite_master WHERE type='tabl
e';"); |
| 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_INFO(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_INFO(SQLDatabase, "Unable to drop table %s", (*table).ascii().da
ta()); |
| 296 } | 296 } |
| 297 } | 297 } |
| 298 | 298 |
| 299 int SQLiteDatabase::runVacuumCommand() | 299 int SQLiteDatabase::runVacuumCommand() |
| 300 { | 300 { |
| 301 if (!executeCommand(ASCIILiteral("VACUUM;"))) | 301 if (!executeCommand(ASCIILiteral("VACUUM;"))) |
| 302 LOG(SQLDatabase, "Unable to vacuum database - %s", lastErrorMsg()); | 302 LOG_INFO(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(ASCIILiteral("PRAGMA incremental_vacuum"))) |
| 312 LOG(SQLDatabase, "Unable to run incremental vacuum - %s", lastErrorMsg()
); | 312 LOG_INFO(SQLDatabase, "Unable to run incremental vacuum - %s", lastError
Msg()); |
| 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; |
| 322 return sqlite3_last_insert_rowid(m_db); | 322 return sqlite3_last_insert_rowid(m_db); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 default: | 490 default: |
| 491 if (!executeCommand(ASCIILiteral("PRAGMA auto_vacuum = 2"))) | 491 if (!executeCommand(ASCIILiteral("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 |
| OLD | NEW |