OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 // |
| 5 // Typesafe composition of SQL query strings. |
| 6 |
| 7 #ifndef CHROME_BROWSER_SYNC_UTIL_QUERY_HELPERS_H_ |
| 8 #define CHROME_BROWSER_SYNC_UTIL_QUERY_HELPERS_H_ |
| 9 |
| 10 #include <limits> |
| 11 #include <string> |
| 12 #include <vector> |
| 13 |
| 14 #include "base/basictypes.h" |
| 15 #include "base/logging.h" |
| 16 #include "chrome/browser/sync/util/sync_types.h" |
| 17 #include "third_party/sqlite/preprocessed/sqlite3.h" |
| 18 |
| 19 // Sometimes threads contend on the DB lock itself, especially when one thread |
| 20 // is calling SaveChanges. In the worst case scenario, the user can put his |
| 21 // laptop to sleep during db contention, and wake up the laptop days later, so |
| 22 // infinity seems like the best choice here. |
| 23 const int kDirectoryBackingStoreBusyTimeoutMs = std::numeric_limits<int>::max(); |
| 24 |
| 25 enum SqliteNullType { |
| 26 SQLITE_NULL_VALUE |
| 27 }; |
| 28 |
| 29 int SqliteOpen(PathString filename, sqlite3** ppDb); |
| 30 |
| 31 sqlite3_stmt* PrepareQuery(sqlite3* dbhandle, const char* query); |
| 32 #if !PATHSTRING_IS_STD_STRING |
| 33 sqlite3_stmt* BindArg(sqlite3_stmt*, const PathString&, int index); |
| 34 sqlite3_stmt* BindArg(sqlite3_stmt*, const PathChar*, int index); |
| 35 #endif |
| 36 sqlite3_stmt* BindArg(sqlite3_stmt*, const std::string&, int index); |
| 37 sqlite3_stmt* BindArg(sqlite3_stmt*, const char*, int index); |
| 38 sqlite3_stmt* BindArg(sqlite3_stmt*, int32, int index); |
| 39 sqlite3_stmt* BindArg(sqlite3_stmt*, int64, int index); |
| 40 sqlite3_stmt* BindArg(sqlite3_stmt*, double, int index); |
| 41 sqlite3_stmt* BindArg(sqlite3_stmt*, bool, int index); |
| 42 sqlite3_stmt* BindArg(sqlite3_stmt*, const std::vector<uint8>&, int index); |
| 43 sqlite3_stmt* BindArg(sqlite3_stmt*, SqliteNullType, int index); |
| 44 |
| 45 #if !PATHSTRING_IS_STD_STRING |
| 46 void GetColumn(sqlite3_stmt*, int index, PathString* value); |
| 47 #endif |
| 48 void GetColumn(sqlite3_stmt*, int index, std::string* value); |
| 49 void GetColumn(sqlite3_stmt*, int index, int32* value); |
| 50 void GetColumn(sqlite3_stmt*, int index, int64* value); |
| 51 void GetColumn(sqlite3_stmt*, int index, double* value); |
| 52 void GetColumn(sqlite3_stmt*, int index, bool* value); |
| 53 void GetColumn(sqlite3_stmt*, int index, std::vector<uint8>* value); |
| 54 |
| 55 bool DoesTableExist(sqlite3* dbhandle, const std::string& tablename); |
| 56 |
| 57 // Prepares a query with a WHERE clause that filters the values by the items |
| 58 // passed inside of the Vector. |
| 59 // Example: |
| 60 // |
| 61 // vector<PathString> v; |
| 62 // v.push_back("abc"); |
| 63 // v.push_back("123"); |
| 64 // PrepareQuery(dbhandle, "SELECT * FROM table", "column_name", v.begin(), |
| 65 // v.end(), "ORDER BY id"); |
| 66 // |
| 67 // will produce the following query. |
| 68 // |
| 69 // SELECT * FROM table WHERE column_name = 'abc' OR column_name = '123' ORDER BY |
| 70 // id. |
| 71 // |
| 72 template<typename ItemIterator> |
| 73 sqlite3_stmt* PrepareQueryWhereColumnIn(sqlite3* dbhandle, |
| 74 const std::string& query_head, |
| 75 const std::string& filtername, |
| 76 ItemIterator begin, ItemIterator end, |
| 77 const std::string& query_options) { |
| 78 std::string query; |
| 79 query.reserve(512); |
| 80 query += query_head; |
| 81 const char* joiner = " WHERE "; |
| 82 for (ItemIterator it = begin; it != end; ++it) { |
| 83 query += joiner; |
| 84 query += filtername; |
| 85 query += " = ?"; |
| 86 joiner = " OR "; |
| 87 } |
| 88 query += " "; |
| 89 query += query_options; |
| 90 sqlite3_stmt* statement = NULL; |
| 91 const char* query_tail; |
| 92 if (SQLITE_OK != sqlite3_prepare(dbhandle, query.data(), |
| 93 CountBytes(query), &statement, |
| 94 &query_tail)) { |
| 95 LOG(ERROR) << query << "\n" << sqlite3_errmsg(dbhandle); |
| 96 } |
| 97 int index = 1; |
| 98 for (ItemIterator it = begin; it != end; ++it) { |
| 99 BindArg(statement, *it, index); |
| 100 ++index; |
| 101 } |
| 102 return statement; |
| 103 } |
| 104 |
| 105 template <typename Type1> |
| 106 inline sqlite3_stmt* PrepareQuery(sqlite3* dbhandle, const char* query, |
| 107 const Type1& arg1) { |
| 108 return BindArg(PrepareQuery(dbhandle, query), arg1, 1); |
| 109 } |
| 110 |
| 111 template <typename Type1, typename Type2> |
| 112 inline sqlite3_stmt* PrepareQuery(sqlite3* dbhandle, const char* query, |
| 113 const Type1& arg1, const Type2& arg2) { |
| 114 return BindArg(PrepareQuery(dbhandle, query, arg1), arg2, 2); |
| 115 } |
| 116 |
| 117 template <typename Type1, typename Type2, typename Type3> |
| 118 inline sqlite3_stmt* PrepareQuery(sqlite3* dbhandle, const char* query, |
| 119 const Type1& arg1, const Type2& arg2, |
| 120 const Type3& arg3) { |
| 121 return BindArg(PrepareQuery(dbhandle, query, arg1, arg2), arg3, 3); |
| 122 } |
| 123 |
| 124 template <typename Type1, typename Type2, typename Type3, typename Type4> |
| 125 inline sqlite3_stmt* PrepareQuery(sqlite3* dbhandle, const char* query, |
| 126 const Type1& arg1, const Type2& arg2, |
| 127 const Type3& arg3, const Type4& arg4) { |
| 128 return BindArg(PrepareQuery(dbhandle, query, arg1, arg2, arg3), arg4, 4); |
| 129 } |
| 130 |
| 131 template <typename Type1, typename Type2, typename Type3, typename Type4, |
| 132 typename Type5> |
| 133 inline sqlite3_stmt* PrepareQuery(sqlite3* dbhandle, const char* query, |
| 134 const Type1& arg1, const Type2& arg2, |
| 135 const Type3& arg3, const Type4& arg4, |
| 136 const Type5& arg5) { |
| 137 return BindArg(PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4), |
| 138 arg5, 5); |
| 139 } |
| 140 |
| 141 template <typename Type1, typename Type2, typename Type3, typename Type4, |
| 142 typename Type5, typename Type6> |
| 143 inline sqlite3_stmt* PrepareQuery(sqlite3* dbhandle, const char* query, |
| 144 const Type1& arg1, const Type2& arg2, |
| 145 const Type3& arg3, const Type4& arg4, |
| 146 const Type5& arg5, const Type6& arg6) { |
| 147 return BindArg(PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5), |
| 148 arg6, 6); |
| 149 } |
| 150 |
| 151 template <typename Type1, typename Type2, typename Type3, typename Type4, |
| 152 typename Type5, typename Type6, typename Type7> |
| 153 inline sqlite3_stmt* PrepareQuery(sqlite3* dbhandle, const char* query, |
| 154 const Type1& arg1, const Type2& arg2, |
| 155 const Type3& arg3, const Type4& arg4, |
| 156 const Type5& arg5, const Type6& arg6, |
| 157 const Type7& arg7) { |
| 158 return BindArg(PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5, |
| 159 arg6), |
| 160 arg7, 7); |
| 161 } |
| 162 |
| 163 template <typename Type1, typename Type2, typename Type3, typename Type4, |
| 164 typename Type5, typename Type6, typename Type7, typename Type8> |
| 165 inline sqlite3_stmt* PrepareQuery(sqlite3* dbhandle, const char* query, |
| 166 const Type1& arg1, const Type2& arg2, |
| 167 const Type3& arg3, const Type4& arg4, |
| 168 const Type5& arg5, const Type6& arg6, |
| 169 const Type7& arg7, const Type8& arg8) { |
| 170 return BindArg(PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5, |
| 171 arg6, arg7), |
| 172 arg8, 8); |
| 173 } |
| 174 |
| 175 template <typename Type1, typename Type2, typename Type3, typename Type4, |
| 176 typename Type5, typename Type6, typename Type7, typename Type8, |
| 177 typename Type9> |
| 178 inline sqlite3_stmt* PrepareQuery(sqlite3* dbhandle, const char* query, |
| 179 const Type1& arg1, const Type2& arg2, |
| 180 const Type3& arg3, const Type4& arg4, |
| 181 const Type5& arg5, const Type6& arg6, |
| 182 const Type7& arg7, const Type8& arg8, |
| 183 const Type9& arg9) { |
| 184 return BindArg(PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5, |
| 185 arg6, arg7, arg8), |
| 186 arg9, 9); |
| 187 } |
| 188 |
| 189 template <typename Type1, typename Type2, typename Type3, typename Type4, |
| 190 typename Type5, typename Type6, typename Type7, typename Type8, |
| 191 typename Type9, typename Type10> |
| 192 inline sqlite3_stmt* PrepareQuery(sqlite3* dbhandle, const char* query, |
| 193 const Type1& arg1, const Type2& arg2, |
| 194 const Type3& arg3, const Type4& arg4, |
| 195 const Type5& arg5, const Type6& arg6, |
| 196 const Type7& arg7, const Type8& arg8, |
| 197 const Type9& arg9, const Type10& arg10) { |
| 198 return BindArg(PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5, |
| 199 arg6, arg7, arg8, arg9), |
| 200 arg10, 10); |
| 201 } |
| 202 |
| 203 template <typename Type1, typename Type2, typename Type3, typename Type4, |
| 204 typename Type5, typename Type6, typename Type7, typename Type8, |
| 205 typename Type9, typename Type10, typename Type11> |
| 206 inline sqlite3_stmt* PrepareQuery(sqlite3* dbhandle, const char* query, |
| 207 const Type1& arg1, const Type2& arg2, |
| 208 const Type3& arg3, const Type4& arg4, |
| 209 const Type5& arg5, const Type6& arg6, |
| 210 const Type7& arg7, const Type8& arg8, |
| 211 const Type9& arg9, const Type10& arg10, |
| 212 const Type11& arg11) { |
| 213 return BindArg(PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5, |
| 214 arg6, arg7, arg8, arg9, arg10), |
| 215 arg11, 11); |
| 216 } |
| 217 |
| 218 template <typename Type1, typename Type2, typename Type3, typename Type4, |
| 219 typename Type5, typename Type6, typename Type7, typename Type8, |
| 220 typename Type9, typename Type10, typename Type11, typename Type12> |
| 221 inline sqlite3_stmt* PrepareQuery(sqlite3* dbhandle, const char* query, |
| 222 const Type1& arg1, const Type2& arg2, |
| 223 const Type3& arg3, const Type4& arg4, |
| 224 const Type5& arg5, const Type6& arg6, |
| 225 const Type7& arg7, const Type8& arg8, |
| 226 const Type9& arg9, const Type10& arg10, |
| 227 const Type11& arg11, const Type12& arg12) { |
| 228 return BindArg(PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5, |
| 229 arg6, arg7, arg8, arg9, arg10, arg11), |
| 230 arg12, 12); |
| 231 } |
| 232 |
| 233 template <typename Type1, typename Type2, typename Type3, typename Type4, |
| 234 typename Type5, typename Type6, typename Type7, typename Type8, |
| 235 typename Type9, typename Type10, typename Type11, typename Type12, |
| 236 typename Type13> |
| 237 inline sqlite3_stmt* PrepareQuery(sqlite3* dbhandle, const char* query, |
| 238 const Type1& arg1, const Type2& arg2, |
| 239 const Type3& arg3, const Type4& arg4, |
| 240 const Type5& arg5, const Type6& arg6, |
| 241 const Type7& arg7, const Type8& arg8, |
| 242 const Type9& arg9, const Type10& arg10, |
| 243 const Type11& arg11, const Type12& arg12, |
| 244 const Type13& arg13) { |
| 245 return BindArg(PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5, |
| 246 arg6, arg7, arg8, arg9, arg10, arg11, arg12), |
| 247 arg13, 13); |
| 248 } |
| 249 |
| 250 template <typename Type1, typename Type2, typename Type3, typename Type4, |
| 251 typename Type5, typename Type6, typename Type7, typename Type8, |
| 252 typename Type9, typename Type10, typename Type11, typename Type12, |
| 253 typename Type13, typename Type14> |
| 254 inline sqlite3_stmt* PrepareQuery(sqlite3* dbhandle, const char* query, |
| 255 const Type1& arg1, const Type2& arg2, |
| 256 const Type3& arg3, const Type4& arg4, |
| 257 const Type5& arg5, const Type6& arg6, |
| 258 const Type7& arg7, const Type8& arg8, |
| 259 const Type9& arg9, const Type10& arg10, |
| 260 const Type11& arg11, const Type12& arg12, |
| 261 const Type13& arg13, const Type14& arg14) { |
| 262 return BindArg(PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5, |
| 263 arg6, arg7, arg8, arg9, arg10, arg11, arg12, |
| 264 arg13), |
| 265 arg14, 14); |
| 266 } |
| 267 |
| 268 template <typename Type1, typename Type2, typename Type3, typename Type4, |
| 269 typename Type5, typename Type6, typename Type7, typename Type8, |
| 270 typename Type9, typename Type10, typename Type11, typename Type12, |
| 271 typename Type13, typename Type14, typename Type15> |
| 272 inline sqlite3_stmt* PrepareQuery(sqlite3* dbhandle, const char* query, |
| 273 const Type1& arg1, const Type2& arg2, |
| 274 const Type3& arg3, const Type4& arg4, |
| 275 const Type5& arg5, const Type6& arg6, |
| 276 const Type7& arg7, const Type8& arg8, |
| 277 const Type9& arg9, const Type10& arg10, |
| 278 const Type11& arg11, const Type12& arg12, |
| 279 const Type13& arg13, const Type14& arg14, |
| 280 const Type15& arg15) { |
| 281 return BindArg(PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5, |
| 282 arg6, arg7, arg8, arg9, arg10, arg11, arg12, |
| 283 arg13, arg14), |
| 284 arg15, 15); |
| 285 } |
| 286 |
| 287 template <typename Type1, typename Type2, typename Type3, typename Type4, |
| 288 typename Type5, typename Type6, typename Type7, typename Type8, |
| 289 typename Type9, typename Type10, typename Type11, typename Type12, |
| 290 typename Type13, typename Type14, typename Type15, typename Type16> |
| 291 inline sqlite3_stmt* PrepareQuery(sqlite3* dbhandle, const char* query, |
| 292 const Type1& arg1, const Type2& arg2, |
| 293 const Type3& arg3, const Type4& arg4, |
| 294 const Type5& arg5, const Type6& arg6, |
| 295 const Type7& arg7, const Type8& arg8, |
| 296 const Type9& arg9, const Type10& arg10, |
| 297 const Type11& arg11, const Type12& arg12, |
| 298 const Type13& arg13, const Type14& arg14, |
| 299 const Type15& arg15, const Type16& arg16) { |
| 300 return BindArg(PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5, |
| 301 arg6, arg7, arg8, arg9, arg10, arg11, arg12, |
| 302 arg13, arg14, arg15), |
| 303 arg16, 16); |
| 304 } |
| 305 |
| 306 template <typename Type1, typename Type2, typename Type3, typename Type4, |
| 307 typename Type5, typename Type6, typename Type7, typename Type8, |
| 308 typename Type9, typename Type10, typename Type11, typename Type12, |
| 309 typename Type13, typename Type14, typename Type15, typename Type16, |
| 310 typename Type17> |
| 311 inline sqlite3_stmt* PrepareQuery(sqlite3* dbhandle, const char* query, |
| 312 const Type1& arg1, const Type2& arg2, |
| 313 const Type3& arg3, const Type4& arg4, |
| 314 const Type5& arg5, const Type6& arg6, |
| 315 const Type7& arg7, const Type8& arg8, |
| 316 const Type9& arg9, const Type10& arg10, |
| 317 const Type11& arg11, const Type12& arg12, |
| 318 const Type13& arg13, const Type14& arg14, |
| 319 const Type15& arg15, const Type16& arg16, |
| 320 const Type17& arg17) { |
| 321 return BindArg(PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5, |
| 322 arg6, arg7, arg8, arg9, arg10, arg11, arg12, |
| 323 arg13, arg14, arg15, arg16), |
| 324 arg17, 17); |
| 325 } |
| 326 |
| 327 void ExecOrDie(sqlite3* dbhandle, const char* query); |
| 328 |
| 329 // Finalizes (deletes) the query before returning. |
| 330 void ExecOrDie(sqlite3* dbhandle, const char* query, sqlite3_stmt* statement); |
| 331 |
| 332 template <typename Type1, typename Type2, typename Type3, typename Type4, |
| 333 typename Type5, typename Type6, typename Type7, typename Type8, |
| 334 typename Type9, typename Type10> |
| 335 inline void ExecOrDie(sqlite3* dbhandle, const char* query, |
| 336 const Type1& arg1, const Type2& arg2, |
| 337 const Type3& arg3, const Type4& arg4, |
| 338 const Type5& arg5, const Type6& arg6, |
| 339 const Type7& arg7, const Type8& arg8, |
| 340 const Type9& arg9, const Type10& arg10) { |
| 341 return ExecOrDie(dbhandle, query, |
| 342 PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5, |
| 343 arg6, arg7, arg8, arg9, arg10)); |
| 344 } |
| 345 |
| 346 template <typename Type1, typename Type2, typename Type3, typename Type4, |
| 347 typename Type5, typename Type6, typename Type7, typename Type8, |
| 348 typename Type9> |
| 349 inline void ExecOrDie(sqlite3* dbhandle, const char* query, |
| 350 const Type1& arg1, const Type2& arg2, |
| 351 const Type3& arg3, const Type4& arg4, |
| 352 const Type5& arg5, const Type6& arg6, |
| 353 const Type7& arg7, const Type8& arg8, |
| 354 const Type9& arg9) { |
| 355 return ExecOrDie(dbhandle, query, |
| 356 PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5, |
| 357 arg6, arg7, arg8, arg9)); |
| 358 } |
| 359 |
| 360 template <typename Type1, typename Type2, typename Type3, typename Type4, |
| 361 typename Type5, typename Type6, typename Type7, typename Type8> |
| 362 inline void ExecOrDie(sqlite3* dbhandle, const char* query, |
| 363 const Type1& arg1, const Type2& arg2, |
| 364 const Type3& arg3, const Type4& arg4, |
| 365 const Type5& arg5, const Type6& arg6, |
| 366 const Type7& arg7, const Type8& arg8) { |
| 367 return ExecOrDie(dbhandle, query, |
| 368 PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5, |
| 369 arg6, arg7, arg8)); |
| 370 } |
| 371 |
| 372 template <typename Type1, typename Type2, typename Type3, typename Type4, |
| 373 typename Type5, typename Type6, typename Type7> |
| 374 inline void ExecOrDie(sqlite3* dbhandle, const char* query, |
| 375 const Type1& arg1, const Type2& arg2, |
| 376 const Type3& arg3, const Type4& arg4, |
| 377 const Type5& arg5, const Type6& arg6, |
| 378 const Type7& arg7) { |
| 379 return ExecOrDie(dbhandle, query, |
| 380 PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5, |
| 381 arg6, arg7)); |
| 382 } |
| 383 |
| 384 template <typename Type1, typename Type2, typename Type3, typename Type4, |
| 385 typename Type5, typename Type6> |
| 386 inline void ExecOrDie(sqlite3* dbhandle, const char* query, |
| 387 const Type1& arg1, const Type2& arg2, |
| 388 const Type3& arg3, const Type4& arg4, |
| 389 const Type5& arg5, const Type6& arg6) { |
| 390 return ExecOrDie(dbhandle, query, PrepareQuery(dbhandle, query, arg1, arg2, |
| 391 arg3, arg4, arg5, arg6)); |
| 392 } |
| 393 |
| 394 template <typename Type1, typename Type2, typename Type3, typename Type4, |
| 395 typename Type5> |
| 396 inline void ExecOrDie(sqlite3* dbhandle, const char* query, |
| 397 const Type1& arg1, const Type2& arg2, |
| 398 const Type3& arg3, const Type4& arg4, |
| 399 const Type5& arg5) { |
| 400 return ExecOrDie(dbhandle, query, PrepareQuery(dbhandle, query, arg1, arg2, |
| 401 arg3, arg4, arg5)); |
| 402 } |
| 403 |
| 404 template <typename Type1, typename Type2, typename Type3, typename Type4> |
| 405 inline void ExecOrDie(sqlite3* dbhandle, const char* query, |
| 406 const Type1& arg1, const Type2& arg2, |
| 407 const Type3& arg3, const Type4& arg4) { |
| 408 return ExecOrDie(dbhandle, query, PrepareQuery(dbhandle, query, arg1, arg2, |
| 409 arg3, arg4)); |
| 410 } |
| 411 |
| 412 template <typename Type1, typename Type2, typename Type3> |
| 413 inline void ExecOrDie(sqlite3* dbhandle, const char* query, |
| 414 const Type1& arg1, const Type2& arg2, |
| 415 const Type3& arg3) { |
| 416 return ExecOrDie(dbhandle, query, PrepareQuery(dbhandle, query, arg1, arg2, |
| 417 arg3)); |
| 418 } |
| 419 |
| 420 template <typename Type1, typename Type2> |
| 421 inline void ExecOrDie(sqlite3* dbhandle, const char* query, |
| 422 const Type1& arg1, const Type2& arg2) { |
| 423 return ExecOrDie(dbhandle, query, PrepareQuery(dbhandle, query, arg1, arg2)); |
| 424 } |
| 425 |
| 426 template <typename Type1> |
| 427 inline void ExecOrDie(sqlite3* dbhandle, const char* query, |
| 428 const Type1& arg1) { |
| 429 return ExecOrDie(dbhandle, query, PrepareQuery(dbhandle, query, arg1)); |
| 430 } |
| 431 |
| 432 |
| 433 int Exec(sqlite3* dbhandle, const char* query); |
| 434 // Finalizes (deletes) the query before returning. |
| 435 int Exec(sqlite3* dbhandle, const char* query, sqlite3_stmt* statement); |
| 436 |
| 437 template <typename Type1, typename Type2, typename Type3, typename Type4, |
| 438 typename Type5, typename Type6, typename Type7, typename Type8, |
| 439 typename Type9, typename Type10, typename Type11, typename Type12, |
| 440 typename Type13, typename Type14, typename Type15, typename Type16, |
| 441 typename Type17> |
| 442 inline int Exec(sqlite3* dbhandle, const char* query, |
| 443 const Type1& arg1, const Type2& arg2, |
| 444 const Type3& arg3, const Type4& arg4, |
| 445 const Type5& arg5, const Type6& arg6, |
| 446 const Type7& arg7, const Type8& arg8, |
| 447 const Type9& arg9, const Type10& arg10, |
| 448 const Type11& arg11, const Type12& arg12, |
| 449 const Type13& arg13, const Type14& arg14, |
| 450 const Type15& arg15, const Type16& arg16, |
| 451 const Type17& arg17) { |
| 452 return Exec(dbhandle, query, |
| 453 PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5, |
| 454 arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, |
| 455 arg14, arg15, arg16, arg17)); |
| 456 } |
| 457 |
| 458 template <typename Type1, typename Type2, typename Type3, typename Type4, |
| 459 typename Type5, typename Type6, typename Type7, typename Type8, |
| 460 typename Type9, typename Type10, typename Type11, typename Type12, |
| 461 typename Type13, typename Type14, typename Type15, typename Type16> |
| 462 inline int Exec(sqlite3* dbhandle, const char* query, |
| 463 const Type1& arg1, const Type2& arg2, |
| 464 const Type3& arg3, const Type4& arg4, |
| 465 const Type5& arg5, const Type6& arg6, |
| 466 const Type7& arg7, const Type8& arg8, |
| 467 const Type9& arg9, const Type10& arg10, |
| 468 const Type11& arg11, const Type12& arg12, |
| 469 const Type13& arg13, const Type14& arg14, |
| 470 const Type15& arg15, const Type16& arg16) { |
| 471 return Exec(dbhandle, query, |
| 472 PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5, |
| 473 arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, |
| 474 arg14, arg15, arg16)); |
| 475 } |
| 476 |
| 477 template <typename Type1, typename Type2, typename Type3, typename Type4, |
| 478 typename Type5, typename Type6, typename Type7, typename Type8, |
| 479 typename Type9, typename Type10, typename Type11, typename Type12, |
| 480 typename Type13, typename Type14, typename Type15> |
| 481 inline int Exec(sqlite3* dbhandle, const char* query, |
| 482 const Type1& arg1, const Type2& arg2, |
| 483 const Type3& arg3, const Type4& arg4, |
| 484 const Type5& arg5, const Type6& arg6, |
| 485 const Type7& arg7, const Type8& arg8, |
| 486 const Type9& arg9, const Type10& arg10, |
| 487 const Type11& arg11, const Type12& arg12, |
| 488 const Type13& arg13, const Type14& arg14, |
| 489 const Type15& arg15) { |
| 490 return Exec(dbhandle, query, |
| 491 PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5, |
| 492 arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, |
| 493 arg14, arg15)); |
| 494 } |
| 495 |
| 496 template <typename Type1, typename Type2, typename Type3, typename Type4, |
| 497 typename Type5, typename Type6, typename Type7, typename Type8, |
| 498 typename Type9, typename Type10, typename Type11, typename Type12, |
| 499 typename Type13, typename Type14> |
| 500 inline int Exec(sqlite3* dbhandle, const char* query, |
| 501 const Type1& arg1, const Type2& arg2, |
| 502 const Type3& arg3, const Type4& arg4, |
| 503 const Type5& arg5, const Type6& arg6, |
| 504 const Type7& arg7, const Type8& arg8, |
| 505 const Type9& arg9, const Type10& arg10, |
| 506 const Type11& arg11, const Type12& arg12, |
| 507 const Type13& arg13, const Type14& arg14) { |
| 508 return Exec(dbhandle, query, |
| 509 PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5, |
| 510 arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, |
| 511 arg14)); |
| 512 } |
| 513 |
| 514 template <typename Type1, typename Type2, typename Type3, typename Type4, |
| 515 typename Type5, typename Type6, typename Type7, typename Type8, |
| 516 typename Type9, typename Type10, typename Type11, typename Type12, |
| 517 typename Type13> |
| 518 inline int Exec(sqlite3* dbhandle, const char* query, |
| 519 const Type1& arg1, const Type2& arg2, |
| 520 const Type3& arg3, const Type4& arg4, |
| 521 const Type5& arg5, const Type6& arg6, |
| 522 const Type7& arg7, const Type8& arg8, |
| 523 const Type9& arg9, const Type10& arg10, |
| 524 const Type11& arg11, const Type12& arg12, |
| 525 const Type13& arg13) { |
| 526 return Exec(dbhandle, query, |
| 527 PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5, |
| 528 arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13)); |
| 529 } |
| 530 |
| 531 template <typename Type1, typename Type2, typename Type3, typename Type4, |
| 532 typename Type5, typename Type6, typename Type7, typename Type8, |
| 533 typename Type9, typename Type10, typename Type11, typename Type12> |
| 534 inline int Exec(sqlite3* dbhandle, const char* query, |
| 535 const Type1& arg1, const Type2& arg2, |
| 536 const Type3& arg3, const Type4& arg4, |
| 537 const Type5& arg5, const Type6& arg6, |
| 538 const Type7& arg7, const Type8& arg8, |
| 539 const Type9& arg9, const Type10& arg10, |
| 540 const Type11& arg11, const Type12& arg12) { |
| 541 return Exec(dbhandle, query, |
| 542 PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5, |
| 543 arg6, arg7, arg8, arg9, arg10, arg11, arg12)); |
| 544 } |
| 545 |
| 546 template <typename Type1, typename Type2, typename Type3, typename Type4, |
| 547 typename Type5, typename Type6, typename Type7, typename Type8, |
| 548 typename Type9, typename Type10, typename Type11> |
| 549 inline int Exec(sqlite3* dbhandle, const char* query, |
| 550 const Type1& arg1, const Type2& arg2, |
| 551 const Type3& arg3, const Type4& arg4, |
| 552 const Type5& arg5, const Type6& arg6, |
| 553 const Type7& arg7, const Type8& arg8, |
| 554 const Type9& arg9, const Type10& arg10, |
| 555 const Type11& arg11) { |
| 556 return Exec(dbhandle, query, |
| 557 PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5, |
| 558 arg6, arg7, arg8, arg9, arg10, arg11)); |
| 559 } |
| 560 |
| 561 template <typename Type1, typename Type2, typename Type3, typename Type4, |
| 562 typename Type5, typename Type6, typename Type7, typename Type8, |
| 563 typename Type9, typename Type10> |
| 564 inline int Exec(sqlite3* dbhandle, const char* query, |
| 565 const Type1& arg1, const Type2& arg2, |
| 566 const Type3& arg3, const Type4& arg4, |
| 567 const Type5& arg5, const Type6& arg6, |
| 568 const Type7& arg7, const Type8& arg8, |
| 569 const Type9& arg9, const Type10& arg10) { |
| 570 return Exec(dbhandle, query, |
| 571 PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5, |
| 572 arg6, arg7, arg8, arg9, arg10)); |
| 573 } |
| 574 |
| 575 template <typename Type1, typename Type2, typename Type3, typename Type4, |
| 576 typename Type5, typename Type6, typename Type7, typename Type8, |
| 577 typename Type9> |
| 578 inline int Exec(sqlite3* dbhandle, const char* query, |
| 579 const Type1& arg1, const Type2& arg2, |
| 580 const Type3& arg3, const Type4& arg4, |
| 581 const Type5& arg5, const Type6& arg6, |
| 582 const Type7& arg7, const Type8& arg8, |
| 583 const Type9& arg9) { |
| 584 return Exec(dbhandle, query, |
| 585 PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5, |
| 586 arg6, arg7, arg8, arg9)); |
| 587 } |
| 588 |
| 589 template <typename Type1, typename Type2, typename Type3, typename Type4, |
| 590 typename Type5, typename Type6, typename Type7, typename Type8> |
| 591 inline int Exec(sqlite3* dbhandle, const char* query, |
| 592 const Type1& arg1, const Type2& arg2, |
| 593 const Type3& arg3, const Type4& arg4, |
| 594 const Type5& arg5, const Type6& arg6, |
| 595 const Type7& arg7, const Type8& arg8) { |
| 596 return Exec(dbhandle, query, |
| 597 PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5, |
| 598 arg6, arg7, arg8)); |
| 599 } |
| 600 |
| 601 template <typename Type1, typename Type2, typename Type3, typename Type4, |
| 602 typename Type5, typename Type6, typename Type7> |
| 603 inline int Exec(sqlite3* dbhandle, const char* query, |
| 604 const Type1& arg1, const Type2& arg2, |
| 605 const Type3& arg3, const Type4& arg4, |
| 606 const Type5& arg5, const Type6& arg6, |
| 607 const Type7& arg7) { |
| 608 return Exec(dbhandle, query, |
| 609 PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5, |
| 610 arg6, arg7)); |
| 611 } |
| 612 |
| 613 template <typename Type1, typename Type2, typename Type3, typename Type4, |
| 614 typename Type5, typename Type6> |
| 615 inline int Exec(sqlite3* dbhandle, const char* query, |
| 616 const Type1& arg1, const Type2& arg2, |
| 617 const Type3& arg3, const Type4& arg4, |
| 618 const Type5& arg5, const Type6& arg6) { |
| 619 return Exec(dbhandle, query, PrepareQuery(dbhandle, query, arg1, arg2, |
| 620 arg3, arg4, arg5, arg6)); |
| 621 } |
| 622 |
| 623 template <typename Type1, typename Type2, typename Type3, typename Type4, |
| 624 typename Type5> |
| 625 inline int Exec(sqlite3* dbhandle, const char* query, |
| 626 const Type1& arg1, const Type2& arg2, |
| 627 const Type3& arg3, const Type4& arg4, |
| 628 const Type5& arg5) { |
| 629 return Exec(dbhandle, query, PrepareQuery(dbhandle, query, arg1, arg2, |
| 630 arg3, arg4, arg5)); |
| 631 } |
| 632 |
| 633 template <typename Type1, typename Type2, typename Type3, typename Type4> |
| 634 inline int Exec(sqlite3* dbhandle, const char* query, |
| 635 const Type1& arg1, const Type2& arg2, |
| 636 const Type3& arg3, const Type4& arg4) { |
| 637 return Exec(dbhandle, query, PrepareQuery(dbhandle, query, arg1, arg2, |
| 638 arg3, arg4)); |
| 639 } |
| 640 |
| 641 template <typename Type1, typename Type2, typename Type3> |
| 642 inline int Exec(sqlite3* dbhandle, const char* query, |
| 643 const Type1& arg1, const Type2& arg2, |
| 644 const Type3& arg3) { |
| 645 return Exec(dbhandle, query, PrepareQuery(dbhandle, query, arg1, arg2, |
| 646 arg3)); |
| 647 } |
| 648 |
| 649 template <typename Type1, typename Type2> |
| 650 inline int Exec(sqlite3* dbhandle, const char* query, |
| 651 const Type1& arg1, const Type2& arg2) { |
| 652 return Exec(dbhandle, query, PrepareQuery(dbhandle, query, arg1, arg2)); |
| 653 } |
| 654 |
| 655 template <typename Type1> |
| 656 inline int Exec(sqlite3* dbhandle, const char* query, |
| 657 const Type1& arg1) { |
| 658 return Exec(dbhandle, query, PrepareQuery(dbhandle, query, arg1)); |
| 659 } |
| 660 |
| 661 |
| 662 // Holds an sqlite3_stmt* and automatically finalizes when passes out of scope. |
| 663 class ScopedStatement { |
| 664 public: |
| 665 explicit ScopedStatement(sqlite3_stmt* statement = 0) |
| 666 : statement_(statement) { } |
| 667 ~ScopedStatement(); |
| 668 |
| 669 sqlite3_stmt* get() const { return statement_; } |
| 670 |
| 671 // Finalizes currently held statement and sets to new one. |
| 672 void reset(sqlite3_stmt* statement); |
| 673 protected: |
| 674 sqlite3_stmt* statement_; |
| 675 |
| 676 DISALLOW_COPY_AND_ASSIGN(ScopedStatement); |
| 677 }; |
| 678 |
| 679 |
| 680 // Holds an sqlite3_stmt* and automatically resets when passes out of scope. |
| 681 class ScopedStatementResetter { |
| 682 public: |
| 683 explicit ScopedStatementResetter(sqlite3_stmt* statement) |
| 684 : statement_(statement) { } |
| 685 ~ScopedStatementResetter(); |
| 686 |
| 687 protected: |
| 688 sqlite3_stmt* const statement_; |
| 689 |
| 690 DISALLOW_COPY_AND_ASSIGN(ScopedStatementResetter); |
| 691 }; |
| 692 |
| 693 // Useful for encoding any sequence of bytes into a string that can be used in |
| 694 // a table name. Kind of like hex encoding, except that A is zero and P is 15. |
| 695 std::string APEncode(const std::string& in); |
| 696 std::string APDecode(const std::string& in); |
| 697 |
| 698 #endif // CHROME_BROWSER_SYNC_UTIL_QUERY_HELPERS_H_ |
OLD | NEW |