OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "sql/connection.h" | 5 #include "sql/connection.h" |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include <string.h> | 10 #include <string.h> |
(...skipping 1904 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1915 return IntegrityCheckHelper("PRAGMA integrity_check", messages); | 1915 return IntegrityCheckHelper("PRAGMA integrity_check", messages); |
1916 } | 1916 } |
1917 | 1917 |
1918 bool Connection::QuickIntegrityCheck() { | 1918 bool Connection::QuickIntegrityCheck() { |
1919 std::vector<std::string> messages; | 1919 std::vector<std::string> messages; |
1920 if (!IntegrityCheckHelper("PRAGMA quick_check", &messages)) | 1920 if (!IntegrityCheckHelper("PRAGMA quick_check", &messages)) |
1921 return false; | 1921 return false; |
1922 return messages.size() == 1 && messages[0] == "ok"; | 1922 return messages.size() == 1 && messages[0] == "ok"; |
1923 } | 1923 } |
1924 | 1924 |
1925 sql::DatabaseDiagnosticMap Connection::GetDiagnosticMap() { | |
1926 sql::DatabaseDiagnosticMap result; | |
1927 const bool has_valid_header = | |
1928 (ExecuteAndReturnErrorCode("PRAGMA auto_vacuum") == SQLITE_OK); | |
1929 result["Has valid header"] = has_valid_header ? "Yes" : "No"; | |
1930 const bool select_sqlite_master_result = | |
1931 (ExecuteAndReturnErrorCode("SELECT COUNT(*) FROM sqlite_master") == | |
1932 SQLITE_OK); | |
1933 result["\"SELECT COUNT(*) FROM sqlite_master\" succeeds"] = | |
1934 select_sqlite_master_result ? "Yes" : "No"; | |
Scott Hess - ex-Googler
2016/07/10 05:16:52
Gross. You're running the SELECT to determine som
afakhry
2016/07/11 16:47:46
That's because I didn't know what that statement d
Scott Hess - ex-Googler
2016/07/13 01:18:46
Do you expect the master table to not exist?
Earl
afakhry
2016/07/13 19:57:58
Well, I'm not the sql expert here, so I don't know
| |
1935 | |
1936 // If any of the above failed, that's an indication that the file is really | |
1937 // corrupted. Doing the integrity check or getting the schema will crash on | |
1938 // DCHECKs on debug builds. | |
1939 std::string integrity_check_result("Failed"); | |
1940 std::string schema("Failed"); | |
1941 if (has_valid_header && select_sqlite_master_result) { | |
michaeln
2016/07/12 20:05:32
instead of dropping errors on the floor with a Nul
afakhry
2016/07/13 19:57:58
Done. I'm actually using the same code in Connecti
| |
1942 std::vector<std::string> integrity_check_output; | |
1943 if (FullIntegrityCheck(&integrity_check_output)) { | |
1944 integrity_check_result = ""; | |
1945 for (const auto& line : integrity_check_output) | |
michaeln
2016/07/09 03:00:38
The output is uninteresting in the success case, i
afakhry
2016/07/11 16:47:45
Done.
| |
1946 integrity_check_result += line + "\n"; | |
1947 | |
1948 // we can only get the schema if the integrity check passes. | |
1949 schema = GetSchema(); | |
1950 } | |
1951 } | |
1952 | |
1953 result["Integrity check"] = integrity_check_result; | |
1954 result["Schema"] = schema; | |
michaeln
2016/07/09 03:00:38
nit: for readability, might be nice to set all fou
Scott Hess - ex-Googler
2016/07/10 05:16:52
Note that |schema| and the integrity check results
afakhry
2016/07/11 16:47:45
Done.
afakhry
2016/07/11 16:47:46
For the integrity check, multilines are handled ab
michaeln
2016/07/12 20:05:32
i think i'd vote for a basic string too, i don't t
Scott Hess - ex-Googler
2016/07/13 01:18:46
IMHO having callers depend on keys would be really
Scott Hess - ex-Googler
2016/07/13 01:18:46
Multilines are handled above by injecting newlines
afakhry
2016/07/13 19:57:58
Done. Using a string now.
afakhry
2016/07/13 19:57:58
Now I'm using whatever CollectCorruptionInfo() or
afakhry
2016/07/13 19:57:58
Done.
afakhry
2016/07/13 19:57:58
Agreed, formatting is not really the primary conce
| |
1955 | |
1956 return result; | |
1957 } | |
1958 | |
1925 // TODO(shess): Allow specifying maximum results (default 100 lines). | 1959 // TODO(shess): Allow specifying maximum results (default 100 lines). |
1926 bool Connection::IntegrityCheckHelper( | 1960 bool Connection::IntegrityCheckHelper( |
1927 const char* pragma_sql, | 1961 const char* pragma_sql, |
1928 std::vector<std::string>* messages) { | 1962 std::vector<std::string>* messages) { |
1929 messages->clear(); | 1963 messages->clear(); |
1930 | 1964 |
1931 // This has the side effect of setting SQLITE_RecoveryMode, which | 1965 // This has the side effect of setting SQLITE_RecoveryMode, which |
1932 // allows SQLite to process through certain cases of corruption. | 1966 // allows SQLite to process through certain cases of corruption. |
1933 // Failing to set this pragma probably means that the database is | 1967 // Failing to set this pragma probably means that the database is |
1934 // beyond recovery. | 1968 // beyond recovery. |
(...skipping 21 matching lines...) Expand all Loading... | |
1956 ignore_result(Execute(kNoWritableSchema)); | 1990 ignore_result(Execute(kNoWritableSchema)); |
1957 | 1991 |
1958 return ret; | 1992 return ret; |
1959 } | 1993 } |
1960 | 1994 |
1961 base::TimeTicks TimeSource::Now() { | 1995 base::TimeTicks TimeSource::Now() { |
1962 return base::TimeTicks::Now(); | 1996 return base::TimeTicks::Now(); |
1963 } | 1997 } |
1964 | 1998 |
1965 } // namespace sql | 1999 } // namespace sql |
OLD | NEW |