parsing.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Copyright 2019 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. #ifndef SQL_RECOVER_MODULE_PARSING_H_
  5. #define SQL_RECOVER_MODULE_PARSING_H_
  6. #include <string>
  7. namespace sql {
  8. namespace recover {
  9. enum class ValueType;
  10. // The declared data type of a virtual table column.
  11. enum class ModuleColumnType {
  12. kInteger,
  13. kFloat,
  14. kText,
  15. kBlob,
  16. kNumeric,
  17. kRowId,
  18. kAny,
  19. };
  20. // User-supplied specification for recovering a column in a corrupted table.
  21. struct RecoveredColumnSpec {
  22. // False if this represents a parsing error.
  23. bool IsValid() const { return !name.empty(); }
  24. // Column description suitable for use in a CREATE TABLE statement.
  25. std::string ToCreateTableSql() const;
  26. // True if the given value type is admitted by this column specification.
  27. bool IsAcceptableValue(ValueType value_type) const;
  28. // Column name reported to the SQLite engine.
  29. //
  30. // The empty string is (ab)used for representing invalid column information,
  31. // which can be used to communicate parsing errors.
  32. std::string name;
  33. // The column's canonical type.
  34. ModuleColumnType type;
  35. // If true, recovery will skip over null values in this column.
  36. bool is_non_null = false;
  37. // If true, recovery will accept values in this column with compatible types.
  38. bool is_strict = false;
  39. };
  40. // Parses a SQLite module argument that holds a table column specification.
  41. //
  42. // Returns an invalid specification (IsValid() returns false) on parsing errors.
  43. RecoveredColumnSpec ParseColumnSpec(const char* sqlite_arg);
  44. // User-supplied SQL table identifier.
  45. //
  46. // This points to the table whose data is being recovered.
  47. struct TargetTableSpec {
  48. // False if this represents a parsing error.
  49. bool IsValid() const { return !table_name.empty(); }
  50. // The name of the attachment point of the database containing the table.
  51. std::string db_name;
  52. // The name of the table. Uniquely identifies a table in a database.
  53. std::string table_name;
  54. };
  55. // Parses a SQLite module argument that points to a table.
  56. TargetTableSpec ParseTableSpec(const char* sqlite_arg);
  57. } // namespace recover
  58. } // namespace sql
  59. #endif // SQL_RECOVER_MODULE_PARSING_H_