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