| 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 * | 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 | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 | 52 |
| 53 SQLiteStatement::~SQLiteStatement() | 53 SQLiteStatement::~SQLiteStatement() |
| 54 { | 54 { |
| 55 finalize(); | 55 finalize(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 int SQLiteStatement::prepare() | 58 int SQLiteStatement::prepare() |
| 59 { | 59 { |
| 60 ASSERT(!m_isPrepared); | 60 ASSERT(!m_isPrepared); |
| 61 | 61 |
| 62 CString query = m_query.stripWhiteSpace().utf8(); |
| 63 |
| 64 ThreadState::SafePointScope scope(ThreadState::HeapPointersOnStack); |
| 62 MutexLocker databaseLock(m_database.databaseMutex()); | 65 MutexLocker databaseLock(m_database.databaseMutex()); |
| 63 if (m_database.isInterrupted()) | 66 if (m_database.isInterrupted()) |
| 64 return SQLITE_INTERRUPT; | 67 return SQLITE_INTERRUPT; |
| 65 | 68 |
| 66 CString query = m_query.stripWhiteSpace().utf8(); | |
| 67 | |
| 68 WTF_LOG(SQLDatabase, "SQL - prepare - %s", query.data()); | 69 WTF_LOG(SQLDatabase, "SQL - prepare - %s", query.data()); |
| 69 | 70 |
| 70 // Pass the length of the string including the null character to sqlite3_pre
pare_v2; | 71 // Pass the length of the string including the null character to sqlite3_pre
pare_v2; |
| 71 // this lets SQLite avoid an extra string copy. | 72 // this lets SQLite avoid an extra string copy. |
| 72 size_t lengthIncludingNullCharacter = query.length() + 1; | 73 size_t lengthIncludingNullCharacter = query.length() + 1; |
| 73 | 74 |
| 74 const char* tail = 0; | 75 const char* tail = 0; |
| 75 int error = sqlite3_prepare_v2(m_database.sqlite3Handle(), query.data(), len
gthIncludingNullCharacter, &m_statement, &tail); | 76 int error = sqlite3_prepare_v2(m_database.sqlite3Handle(), query.data(), len
gthIncludingNullCharacter, &m_statement, &tail); |
| 76 | 77 |
| 77 if (error != SQLITE_OK) | 78 if (error != SQLITE_OK) |
| 78 WTF_LOG(SQLDatabase, "sqlite3_prepare16 failed (%i)\n%s\n%s", error, que
ry.data(), sqlite3_errmsg(m_database.sqlite3Handle())); | 79 WTF_LOG(SQLDatabase, "sqlite3_prepare16 failed (%i)\n%s\n%s", error, que
ry.data(), sqlite3_errmsg(m_database.sqlite3Handle())); |
| 79 else if (tail && *tail) | 80 else if (tail && *tail) |
| 80 error = SQLITE_ERROR; | 81 error = SQLITE_ERROR; |
| 81 | 82 |
| 82 #ifndef NDEBUG | 83 #ifndef NDEBUG |
| 83 m_isPrepared = error == SQLITE_OK; | 84 m_isPrepared = error == SQLITE_OK; |
| 84 #endif | 85 #endif |
| 85 return error; | 86 return error; |
| 86 } | 87 } |
| 87 | 88 |
| 88 int SQLiteStatement::step() | 89 int SQLiteStatement::step() |
| 89 { | 90 { |
| 91 ThreadState::SafePointScope scope(ThreadState::HeapPointersOnStack); |
| 90 MutexLocker databaseLock(m_database.databaseMutex()); | 92 MutexLocker databaseLock(m_database.databaseMutex()); |
| 91 if (m_database.isInterrupted()) | 93 if (m_database.isInterrupted()) |
| 92 return SQLITE_INTERRUPT; | 94 return SQLITE_INTERRUPT; |
| 93 //ASSERT(m_isPrepared); | 95 //ASSERT(m_isPrepared); |
| 94 | 96 |
| 95 if (!m_statement) | 97 if (!m_statement) |
| 96 return SQLITE_OK; | 98 return SQLITE_OK; |
| 97 | 99 |
| 98 // The database needs to update its last changes count before each statement | 100 // The database needs to update its last changes count before each statement |
| 99 // in order to compute properly the lastChanges() return value. | 101 // in order to compute properly the lastChanges() return value. |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 ASSERT(col >= 0); | 267 ASSERT(col >= 0); |
| 266 if (!m_statement) | 268 if (!m_statement) |
| 267 if (prepareAndStep() != SQLITE_ROW) | 269 if (prepareAndStep() != SQLITE_ROW) |
| 268 return 0; | 270 return 0; |
| 269 if (columnCount() <= col) | 271 if (columnCount() <= col) |
| 270 return 0; | 272 return 0; |
| 271 return sqlite3_column_int64(m_statement, col); | 273 return sqlite3_column_int64(m_statement, col); |
| 272 } | 274 } |
| 273 | 275 |
| 274 } // namespace WebCore | 276 } // namespace WebCore |
| OLD | NEW |