| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 } | 75 } |
| 76 | 76 |
| 77 } // namespace | 77 } // namespace |
| 78 | 78 |
| 79 namespace blink { | 79 namespace blink { |
| 80 | 80 |
| 81 SQLiteStatement::SQLiteStatement(SQLiteDatabase& db, const String& sql) | 81 SQLiteStatement::SQLiteStatement(SQLiteDatabase& db, const String& sql) |
| 82 : m_database(db), | 82 : m_database(db), |
| 83 m_query(sql), | 83 m_query(sql), |
| 84 m_statement(0) | 84 m_statement(0) |
| 85 #if ENABLE(ASSERT) | |
| 86 , | |
| 87 m_isPrepared(false) | |
| 88 #endif | |
| 89 { | 85 { |
| 90 } | 86 } |
| 91 | 87 |
| 92 SQLiteStatement::~SQLiteStatement() { | 88 SQLiteStatement::~SQLiteStatement() { |
| 93 finalize(); | 89 finalize(); |
| 94 } | 90 } |
| 95 | 91 |
| 96 int SQLiteStatement::prepare() { | 92 int SQLiteStatement::prepare() { |
| 97 ASSERT(!m_isPrepared); | 93 ASSERT(!m_isPrepared); |
| 98 | 94 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 120 } | 116 } |
| 121 m_statement = *statement; | 117 m_statement = *statement; |
| 122 | 118 |
| 123 if (error != SQLITE_OK) | 119 if (error != SQLITE_OK) |
| 124 SQL_DVLOG(1) << "sqlite3_prepare16 failed (" << error << ")\n" | 120 SQL_DVLOG(1) << "sqlite3_prepare16 failed (" << error << ")\n" |
| 125 << query.data() << "\n" | 121 << query.data() << "\n" |
| 126 << sqlite3_errmsg(m_database.sqlite3Handle()); | 122 << sqlite3_errmsg(m_database.sqlite3Handle()); |
| 127 else if (*tail && **tail) | 123 else if (*tail && **tail) |
| 128 error = SQLITE_ERROR; | 124 error = SQLITE_ERROR; |
| 129 | 125 |
| 130 #if ENABLE(ASSERT) | 126 #if DCHECK_IS_ON() |
| 131 m_isPrepared = error == SQLITE_OK; | 127 m_isPrepared = error == SQLITE_OK; |
| 132 #endif | 128 #endif |
| 133 return restrictError(error); | 129 return restrictError(error); |
| 134 } | 130 } |
| 135 | 131 |
| 136 int SQLiteStatement::step() { | 132 int SQLiteStatement::step() { |
| 137 SafePointScope scope(BlinkGC::HeapPointersOnStack); | 133 SafePointScope scope(BlinkGC::HeapPointersOnStack); |
| 138 // ASSERT(m_isPrepared); | 134 // ASSERT(m_isPrepared); |
| 139 | 135 |
| 140 if (!m_statement) | 136 if (!m_statement) |
| 141 return SQLITE_OK; | 137 return SQLITE_OK; |
| 142 | 138 |
| 143 // The database needs to update its last changes count before each statement | 139 // The database needs to update its last changes count before each statement |
| 144 // in order to compute properly the lastChanges() return value. | 140 // in order to compute properly the lastChanges() return value. |
| 145 m_database.updateLastChangesCount(); | 141 m_database.updateLastChangesCount(); |
| 146 | 142 |
| 147 SQL_DVLOG(1) << "SQL - step - " << m_query; | 143 SQL_DVLOG(1) << "SQL - step - " << m_query; |
| 148 int error = sqlite3_step(m_statement); | 144 int error = sqlite3_step(m_statement); |
| 149 if (error != SQLITE_DONE && error != SQLITE_ROW) { | 145 if (error != SQLITE_DONE && error != SQLITE_ROW) { |
| 150 SQL_DVLOG(1) << "sqlite3_step failed (" << error << " )\nQuery - " | 146 SQL_DVLOG(1) << "sqlite3_step failed (" << error << " )\nQuery - " |
| 151 << m_query << "\nError - " | 147 << m_query << "\nError - " |
| 152 << sqlite3_errmsg(m_database.sqlite3Handle()); | 148 << sqlite3_errmsg(m_database.sqlite3Handle()); |
| 153 } | 149 } |
| 154 | 150 |
| 155 return restrictError(error); | 151 return restrictError(error); |
| 156 } | 152 } |
| 157 | 153 |
| 158 int SQLiteStatement::finalize() { | 154 int SQLiteStatement::finalize() { |
| 159 #if ENABLE(ASSERT) | 155 #if DCHECK_IS_ON() |
| 160 m_isPrepared = false; | 156 m_isPrepared = false; |
| 161 #endif | 157 #endif |
| 162 if (!m_statement) | 158 if (!m_statement) |
| 163 return SQLITE_OK; | 159 return SQLITE_OK; |
| 164 SQL_DVLOG(1) << "SQL - finalize - " << m_query; | 160 SQL_DVLOG(1) << "SQL - finalize - " << m_query; |
| 165 int result = sqlite3_finalize(m_statement); | 161 int result = sqlite3_finalize(m_statement); |
| 166 m_statement = 0; | 162 m_statement = 0; |
| 167 return restrictError(result); | 163 return restrictError(result); |
| 168 } | 164 } |
| 169 | 165 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 ASSERT(col >= 0); | 302 ASSERT(col >= 0); |
| 307 if (!m_statement) | 303 if (!m_statement) |
| 308 if (prepareAndStep() != SQLITE_ROW) | 304 if (prepareAndStep() != SQLITE_ROW) |
| 309 return 0; | 305 return 0; |
| 310 if (columnCount() <= col) | 306 if (columnCount() <= col) |
| 311 return 0; | 307 return 0; |
| 312 return sqlite3_column_int64(m_statement, col); | 308 return sqlite3_column_int64(m_statement, col); |
| 313 } | 309 } |
| 314 | 310 |
| 315 } // namespace blink | 311 } // namespace blink |
| OLD | NEW |