ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
sqlite3_utils.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <cstdio>
11 #include <cstdlib>
12 #include <string>
13 
14 #include "SQLite/sqlite3.h"
15 
16 namespace colmap {
17 
18 inline int SQLite3CallHelper(const int result_code,
19  const std::string& filename,
20  const int line_number) {
21  switch (result_code) {
22  case SQLITE_OK:
23  case SQLITE_ROW:
24  case SQLITE_DONE:
25  return result_code;
26  default:
27  fprintf(stderr, "SQLite error [%s, line %i]: %s\n",
28  filename.c_str(), line_number, sqlite3_errstr(result_code));
29  exit(EXIT_FAILURE);
30  }
31 }
32 
33 #define SQLITE3_CALL(func) SQLite3CallHelper(func, __FILE__, __LINE__)
34 
35 #define SQLITE3_EXEC(database, sql, callback) \
36  { \
37  char* err_msg = nullptr; \
38  const int result_code = \
39  sqlite3_exec(database, sql, callback, nullptr, &err_msg); \
40  if (result_code != SQLITE_OK) { \
41  fprintf(stderr, "SQLite error [%s, line %i]: %s\n", __FILE__, \
42  __LINE__, err_msg); \
43  sqlite3_free(err_msg); \
44  } \
45  }
46 
47 } // namespace colmap
std::string filename
int SQLite3CallHelper(const int result_code, const std::string &filename, const int line_number)
Definition: sqlite3_utils.h:18