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

Side by Side Diff: third_party/WebKit/Source/modules/webdatabase/SQLStatementBackend.cpp

Issue 2068053002: Rename Blink constants generated from IDL files. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007, 2013 Apple Inc. All rights reserved. 2 * Copyright (C) 2007, 2013 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 * 7 *
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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 db->setAuthorizerPermissions(m_permissions); 128 db->setAuthorizerPermissions(m_permissions);
129 129
130 SQLiteDatabase* database = &db->sqliteDatabase(); 130 SQLiteDatabase* database = &db->sqliteDatabase();
131 131
132 SQLiteStatement statement(*database, m_statement); 132 SQLiteStatement statement(*database, m_statement);
133 int result = statement.prepare(); 133 int result = statement.prepare();
134 134
135 if (result != SQLResultOk) { 135 if (result != SQLResultOk) {
136 WTF_LOG(StorageAPI, "Unable to verify correctness of statement %s - erro r %i (%s)", m_statement.ascii().data(), result, database->lastErrorMsg()); 136 WTF_LOG(StorageAPI, "Unable to verify correctness of statement %s - erro r %i (%s)", m_statement.ascii().data(), result, database->lastErrorMsg());
137 if (result == SQLResultInterrupt) 137 if (result == SQLResultInterrupt)
138 m_error = SQLErrorData::create(SQLError::DATABASE_ERR, "could not pr epare statement", result, "interrupted"); 138 m_error = SQLErrorData::create(SQLError::kDatabaseErr, "could not pr epare statement", result, "interrupted");
139 else 139 else
140 m_error = SQLErrorData::create(SQLError::SYNTAX_ERR, "could not prep are statement", result, database->lastErrorMsg()); 140 m_error = SQLErrorData::create(SQLError::kSyntaxErr, "could not prep are statement", result, database->lastErrorMsg());
141 db->reportExecuteStatementResult(1, m_error->code(), result); 141 db->reportExecuteStatementResult(1, m_error->code(), result);
142 return false; 142 return false;
143 } 143 }
144 144
145 // FIXME: If the statement uses the ?### syntax supported by sqlite, the bin d parameter count is very likely off from the number of question marks. 145 // FIXME: If the statement uses the ?### syntax supported by sqlite, the bin d parameter count is very likely off from the number of question marks.
146 // If this is the case, they might be trying to do something fishy or malici ous 146 // If this is the case, they might be trying to do something fishy or malici ous
147 if (statement.bindParameterCount() != m_arguments.size()) { 147 if (statement.bindParameterCount() != m_arguments.size()) {
148 WTF_LOG(StorageAPI, "Bind parameter count doesn't match number of questi on marks"); 148 WTF_LOG(StorageAPI, "Bind parameter count doesn't match number of questi on marks");
149 m_error = SQLErrorData::create(SQLError::SYNTAX_ERR, "number of '?'s in statement string does not match argument count"); 149 m_error = SQLErrorData::create(SQLError::kSyntaxErr, "number of '?'s in statement string does not match argument count");
150 db->reportExecuteStatementResult(2, m_error->code(), 0); 150 db->reportExecuteStatementResult(2, m_error->code(), 0);
151 return false; 151 return false;
152 } 152 }
153 153
154 for (unsigned i = 0; i < m_arguments.size(); ++i) { 154 for (unsigned i = 0; i < m_arguments.size(); ++i) {
155 result = statement.bindValue(i + 1, m_arguments[i]); 155 result = statement.bindValue(i + 1, m_arguments[i]);
156 if (result == SQLResultFull) { 156 if (result == SQLResultFull) {
157 setFailureDueToQuota(db); 157 setFailureDueToQuota(db);
158 return false; 158 return false;
159 } 159 }
160 160
161 if (result != SQLResultOk) { 161 if (result != SQLResultOk) {
162 WTF_LOG(StorageAPI, "Failed to bind value index %i to statement for query '%s'", i + 1, m_statement.ascii().data()); 162 WTF_LOG(StorageAPI, "Failed to bind value index %i to statement for query '%s'", i + 1, m_statement.ascii().data());
163 db->reportExecuteStatementResult(3, SQLError::DATABASE_ERR, result); 163 db->reportExecuteStatementResult(3, SQLError::kDatabaseErr, result);
164 m_error = SQLErrorData::create(SQLError::DATABASE_ERR, "could not bi nd value", result, database->lastErrorMsg()); 164 m_error = SQLErrorData::create(SQLError::kDatabaseErr, "could not bi nd value", result, database->lastErrorMsg());
165 return false; 165 return false;
166 } 166 }
167 } 167 }
168 168
169 // Step so we can fetch the column names. 169 // Step so we can fetch the column names.
170 result = statement.step(); 170 result = statement.step();
171 if (result == SQLResultRow) { 171 if (result == SQLResultRow) {
172 int columnCount = statement.columnCount(); 172 int columnCount = statement.columnCount();
173 SQLResultSetRowList* rows = m_resultSet->rows(); 173 SQLResultSetRowList* rows = m_resultSet->rows();
174 174
175 for (int i = 0; i < columnCount; i++) 175 for (int i = 0; i < columnCount; i++)
176 rows->addColumn(statement.getColumnName(i)); 176 rows->addColumn(statement.getColumnName(i));
177 177
178 do { 178 do {
179 for (int i = 0; i < columnCount; i++) 179 for (int i = 0; i < columnCount; i++)
180 rows->addResult(statement.getColumnValue(i)); 180 rows->addResult(statement.getColumnValue(i));
181 181
182 result = statement.step(); 182 result = statement.step();
183 } while (result == SQLResultRow); 183 } while (result == SQLResultRow);
184 184
185 if (result != SQLResultDone) { 185 if (result != SQLResultDone) {
186 db->reportExecuteStatementResult(4, SQLError::DATABASE_ERR, result); 186 db->reportExecuteStatementResult(4, SQLError::kDatabaseErr, result);
187 m_error = SQLErrorData::create(SQLError::DATABASE_ERR, "could not it erate results", result, database->lastErrorMsg()); 187 m_error = SQLErrorData::create(SQLError::kDatabaseErr, "could not it erate results", result, database->lastErrorMsg());
188 return false; 188 return false;
189 } 189 }
190 } else if (result == SQLResultDone) { 190 } else if (result == SQLResultDone) {
191 // Didn't find anything, or was an insert 191 // Didn't find anything, or was an insert
192 if (db->lastActionWasInsert()) 192 if (db->lastActionWasInsert())
193 m_resultSet->setInsertId(database->lastInsertRowID()); 193 m_resultSet->setInsertId(database->lastInsertRowID());
194 } else if (result == SQLResultFull) { 194 } else if (result == SQLResultFull) {
195 // Return the Quota error - the delegate will be asked for more space an d this statement might be re-run 195 // Return the Quota error - the delegate will be asked for more space an d this statement might be re-run
196 setFailureDueToQuota(db); 196 setFailureDueToQuota(db);
197 return false; 197 return false;
198 } else if (result == SQLResultConstraint) { 198 } else if (result == SQLResultConstraint) {
199 db->reportExecuteStatementResult(6, SQLError::CONSTRAINT_ERR, result); 199 db->reportExecuteStatementResult(6, SQLError::kConstraintErr, result);
200 m_error = SQLErrorData::create(SQLError::CONSTRAINT_ERR, "could not exec ute statement due to a constaint failure", result, database->lastErrorMsg()); 200 m_error = SQLErrorData::create(SQLError::kConstraintErr, "could not exec ute statement due to a constaint failure", result, database->lastErrorMsg());
201 return false; 201 return false;
202 } else { 202 } else {
203 db->reportExecuteStatementResult(5, SQLError::DATABASE_ERR, result); 203 db->reportExecuteStatementResult(5, SQLError::kDatabaseErr, result);
204 m_error = SQLErrorData::create(SQLError::DATABASE_ERR, "could not execut e statement", result, database->lastErrorMsg()); 204 m_error = SQLErrorData::create(SQLError::kDatabaseErr, "could not execut e statement", result, database->lastErrorMsg());
205 return false; 205 return false;
206 } 206 }
207 207
208 // FIXME: If the spec allows triggers, and we want to be "accurate" in a dif ferent way, we'd use 208 // FIXME: If the spec allows triggers, and we want to be "accurate" in a dif ferent way, we'd use
209 // sqlite3_total_changes() here instead of sqlite3_changed, because that inc ludes rows modified from within a trigger 209 // sqlite3_total_changes() here instead of sqlite3_changed, because that inc ludes rows modified from within a trigger
210 // For now, this seems sufficient 210 // For now, this seems sufficient
211 m_resultSet->setRowsAffected(database->lastChanges()); 211 m_resultSet->setRowsAffected(database->lastChanges());
212 212
213 db->reportExecuteStatementResult(0, -1, 0); // OK 213 db->reportExecuteStatementResult(0, -1, 0); // OK
214 return true; 214 return true;
215 } 215 }
216 216
217 void SQLStatementBackend::setVersionMismatchedError(Database* database) 217 void SQLStatementBackend::setVersionMismatchedError(Database* database)
218 { 218 {
219 ASSERT(!m_error && !m_resultSet->isValid()); 219 ASSERT(!m_error && !m_resultSet->isValid());
220 database->reportExecuteStatementResult(7, SQLError::VERSION_ERR, 0); 220 database->reportExecuteStatementResult(7, SQLError::kVersionErr, 0);
221 m_error = SQLErrorData::create(SQLError::VERSION_ERR, "current version of th e database and `oldVersion` argument do not match"); 221 m_error = SQLErrorData::create(SQLError::kVersionErr, "current version of th e database and `oldVersion` argument do not match");
222 } 222 }
223 223
224 void SQLStatementBackend::setFailureDueToQuota(Database* database) 224 void SQLStatementBackend::setFailureDueToQuota(Database* database)
225 { 225 {
226 ASSERT(!m_error && !m_resultSet->isValid()); 226 ASSERT(!m_error && !m_resultSet->isValid());
227 database->reportExecuteStatementResult(8, SQLError::QUOTA_ERR, 0); 227 database->reportExecuteStatementResult(8, SQLError::kQuotaErr, 0);
228 m_error = SQLErrorData::create(SQLError::QUOTA_ERR, "there was not enough re maining storage space, or the storage quota was reached and the user declined to allow more space"); 228 m_error = SQLErrorData::create(SQLError::kQuotaErr, "there was not enough re maining storage space, or the storage quota was reached and the user declined to allow more space");
229 } 229 }
230 230
231 void SQLStatementBackend::clearFailureDueToQuota() 231 void SQLStatementBackend::clearFailureDueToQuota()
232 { 232 {
233 if (lastExecutionFailedDueToQuota()) 233 if (lastExecutionFailedDueToQuota())
234 m_error = nullptr; 234 m_error = nullptr;
235 } 235 }
236 236
237 bool SQLStatementBackend::lastExecutionFailedDueToQuota() const 237 bool SQLStatementBackend::lastExecutionFailedDueToQuota() const
238 { 238 {
239 return m_error && m_error->code() == SQLError::QUOTA_ERR; 239 return m_error && m_error->code() == SQLError::kQuotaErr;
240 } 240 }
241 241
242 } // namespace blink 242 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698