Skip to content

pragma_t::integrity_check

Yevgeniy Zakharov edited this page Oct 13, 2021 · 4 revisions

pragma_t::integrity_check

(1)

template<class R = std::string>
R integrity_check();

(2)

template<class R>
R integrity_check(int n);

(3)

template<class R, class T>
R integrity_check(T table_name);

integrity_check is a member function of pragma_t class and is used to call PRAGMA integrity_check. Originally SQLite has three options to call integrity_check:

  • PRAGMA integrity_check
  • PRAGMA integrity_check(N)
  • PRAGMA integrity_check(TABLENAME)

The first overload calls the first option, the second overload calls the second one and the third overload calls the third one.

The first overload is the shortest and the simplest:

auto checkResult = storage.pragma.integrity_check();  // decltype(checkResult) is std::string

Usually integrity_check returns one row with 'ok' string so getting a string may be enough. But when database is corrupted integrity_check can return more than one row so the best way is to obtain results as a vector of strings:

auto checkResult = storage.pragma.integrity_check<std::vector<std::string>>();  // decltype(checkResult) is std::vector<std::string>

You may ask 'Why default return type is not std::vector<std::string>?'. It is because of initial commit of this function. It was created with std::string return type and it is implemented right now this way to keep backward compatibility.

The second overload calls PRAGMA integrity_check(N) where N is int argument you pass. This overload does not have default return type so you have to specify it by yourself. std::string and std::vector<std::string> are allowed.

Example:

auto stringResult = storage.pragma.integrity_check<std::string>(10);
//  or
auto vectorResult = storage.pragma.integrity_check<std::vector<std::string>>(10);

The third overload calls PRAGMA integrity_check(TABLENAME) where TABLENAME is the only argument you pass. It has a template type so you can pass any object which has std::ostream& std::operator<< overload. The simplest options are std::string, std::string_view or C string literal (const char*). Also you need to specify return type as a template argument explicitly just like the second overload.

Example:

auto stringResult = storage.pragma.integrity_check<std::string>("users");
//  or
auto vectorResult = storage.pragma.integrity_check<std::vector<std::string>>("users");

Note

You may want to pass custom types as return parameters configured using statement_binder and row_extractor but it will not work cause SQLite does not use prepared statements during PRAGMA calls so there is no way to bind custom type. Actually allowed types are hardcoded and they are:

QString or any other custom type will not work. If you need custom type binding within PRAGMA calls please open an issue and describe your case in details so we will figure out how to make it work.

External links

Clone this wiki locally