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

Unified Diff: chrome/browser/predictors/autocomplete_action_predictor_table.cc

Issue 10546129: Adding validity checks to sql statements in AutocompleteActionPredictorTable. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/predictors/autocomplete_action_predictor_table.cc
diff --git a/chrome/browser/predictors/autocomplete_action_predictor_table.cc b/chrome/browser/predictors/autocomplete_action_predictor_table.cc
index 0e3a5d4b340bc29cc37d3cff83a39882f1383884..37b30f24f49b098750909398726e1307289e0a0a 100644
--- a/chrome/browser/predictors/autocomplete_action_predictor_table.cc
+++ b/chrome/browser/predictors/autocomplete_action_predictor_table.cc
@@ -100,6 +100,8 @@ void AutocompleteActionPredictorTable::GetAllRows(Rows* row_buffer) {
sql::Statement statement(DB()->GetCachedStatement(SQL_FROM_HERE,
base::StringPrintf(
"SELECT * FROM %s", kAutocompletePredictorTableName).c_str()));
+ if (!statement.is_valid())
dominich 2012/06/12 19:11:06 have you seen this happen?
Shishir 2012/06/12 19:35:22 Not here, but the API says that you should check v
dominich 2012/06/12 19:44:43 Done.
+ return;
Row row;
while (StepAndInitializeRow(&statement, &row))
@@ -140,6 +142,11 @@ void AutocompleteActionPredictorTable::AddAndUpdateRows(
"INSERT INTO %s "
"(id, user_text, url, number_of_hits, number_of_misses) "
"VALUES (?,?,?,?,?)", kAutocompletePredictorTableName).c_str()));
+ if (!statement.is_valid()) {
+ DB()->RollbackTransaction();
+ return;
+ }
+
BindRowToStatement(*it, &statement);
if (!statement.Run()) {
DB()->RollbackTransaction();
@@ -153,6 +160,11 @@ void AutocompleteActionPredictorTable::AddAndUpdateRows(
"UPDATE %s "
"SET id=?, user_text=?, url=?, number_of_hits=?, number_of_misses=?"
" WHERE id=?1", kAutocompletePredictorTableName).c_str()));
+ if (!statement.is_valid()) {
+ DB()->RollbackTransaction();
+ return;
+ }
+
BindRowToStatement(*it, &statement);
if (!statement.Run()) {
DB()->RollbackTransaction();
@@ -169,20 +181,24 @@ void AutocompleteActionPredictorTable::DeleteRows(
if (CantAccessDatabase())
return;
- sql::Statement statement(DB()->GetUniqueStatement(base::StringPrintf(
- "DELETE FROM %s WHERE id=?",
- kAutocompletePredictorTableName).c_str()));
-
if (!DB()->BeginTransaction())
return;
for (std::vector<Row::Id>::const_iterator it = id_list.begin();
it != id_list.end(); ++it) {
+ sql::Statement statement(DB()->GetCachedStatement(SQL_FROM_HERE,
dominich 2012/06/12 19:11:06 this doesn't change through the loop - which is wh
Shishir 2012/06/12 19:35:22 To be consistent with the rest of the code. We do
dominich 2012/06/12 19:44:43 Done.
+ base::StringPrintf(
+ "DELETE FROM %s WHERE id=?",
+ kAutocompletePredictorTableName).c_str()));
+ if (!statement.is_valid()) {
dominich 2012/06/12 19:11:06 how can the statement be valid before it's bound?
Shishir 2012/06/12 19:35:22 This function does not check SQL validity (IsSQLVa
dominich 2012/06/12 19:44:43 Done.
+ DB()->RollbackTransaction();
+ return;
+ }
+
statement.BindString(0, *it);
if (!statement.Run()) {
DB()->RollbackTransaction();
return;
}
- statement.Reset(true);
}
DB()->CommitTransaction();
}
@@ -195,6 +211,8 @@ void AutocompleteActionPredictorTable::DeleteAllRows() {
sql::Statement statement(DB()->GetCachedStatement(SQL_FROM_HERE,
base::StringPrintf("DELETE FROM %s",
kAutocompletePredictorTableName).c_str()));
+ if (!statement.is_valid())
dominich 2012/06/12 19:11:06 have you seen this happen?
Shishir 2012/06/12 19:35:22 Nope, but again the API suggests doing it From th
dominich 2012/06/12 19:44:43 Done.
+ return;
statement.Run();
}
@@ -233,7 +251,7 @@ void AutocompleteActionPredictorTable::LogDatabaseStats() {
sql::Statement count_statement(DB()->GetUniqueStatement(
base::StringPrintf("SELECT count(id) FROM %s",
kAutocompletePredictorTableName).c_str()));
- if (!count_statement.Step())
+ if (!count_statement.is_valid() || !count_statement.Step())
return;
UMA_HISTOGRAM_COUNTS("AutocompleteActionPredictor.DatabaseRowCount",
count_statement.ColumnInt(0));
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698