-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcddbupdater.hpp
139 lines (123 loc) · 4.63 KB
/
cddbupdater.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
//
// cddbupdater.hpp
//
// Copyright © 2016 Joachim Schurig. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
#ifndef cddbupdater_hpp_ALIHKDYHJVDGSOICULKHAISOULKGZUCVTKADZBK
#define cddbupdater_hpp_ALIHKDYHJVDGSOICULKHAISOULKGZUCVTKADZBK
#include "sqlitecpp/SQLiteCpp.h"
#include "helper.hpp"
#include "cddbstringintmap.hpp"
#include "cddbdefines.hpp"
#include "diskrecord.hpp"
#include "untar.hpp"
namespace CDDB {
class SchemaInit {
public:
SchemaInit(const std::string& dbname);
~SchemaInit() {}
};
class CDDBSQLUpdater {
public:
CDDBSQLUpdater(const std::string& dbname);
~CDDBSQLUpdater() {}
void import(const std::string& importfile, bool initial_import);
void add_fuzzy_table();
private:
struct report_t {
// read count
uint64_t rct = 0;
// link count
uint64_t lct = 0;
// duplicate crc count
uint64_t dcrcct = 0;
// failed record count
uint64_t frct = 0;
// total unpacked bytes
uint64_t bct = 0;
// real discid collisions of the same CD, but with different frames
uint64_t realcddidcollct = 0;
// real discid collisions of the same CD
uint64_t samecdframesct = 0;
// real discid collisions
uint64_t realdidcollct = 0;
// real discid collisions
uint64_t sameframesct = 0;
// does the new record have higher entropy
uint64_t entropy_gt = 0;
// or same
uint64_t entropy_eq = 0;
// or lower
uint64_t entropy_lt = 0;
// records with exactly the same strings
uint64_t duplicate = 0;
uint64_t duplicate_lower = 0;
// uppercase charcount
uint64_t upper_count_gt = 0;
uint64_t upper_count_eqlt = 0;
// overall charcount
uint64_t overall_count_gt = 0;
uint64_t overall_count_eqlt = 0;
// absolute counts
uint64_t added = 0;
uint64_t updated = 0;
// clear counters
void clear() { std::memset(this, 0, sizeof(report_t)); }
std::string to_string();
};
SchemaInit m_schema;
SQLite::Database m_sql;
StringIntMapCache m_genres;
report_t m_rep;
SQLite::Statement qcd;
SQLite::Statement qupdatecd;
SQLite::Statement qcd2;
SQLite::Statement qtracks;
SQLite::Statement qdiscid;
SQLite::Statement qfdiscid;
SQLite::Statement qscrc;
SQLite::Statement qdhash;
SQLite::Statement qicrc;
SQLite::Statement qcoll1;
SQLite::Statement qcoll2;
SQLite::Statement qcoll3;
SQLite::Statement qupdatetracks;
SQLite::Statement qdelcd;
SQLite::Statement qdeltracks;
SQLite::Statement qdelhash;
SQLite::Statement qerror;
bool m_debug = false;
CDDBSQLUpdater(const CDDBSQLUpdater&) = delete;
CDDBSQLUpdater& operator=(const CDDBSQLUpdater&) = delete;
uint32_t check_title_hash(uint32_t hash);
uint32_t write_record(const DiskRecord& rec, bool check_hash);
uint32_t check_discid(uint32_t discid);
void write_fuzzy_discid(uint32_t fuzzyid, uint32_t cdid);
void write_discid(uint32_t discid, uint32_t cdid);
DiskRecord read_record(uint32_t cdid, uint32_t discid);
void update_record(uint32_t cdid, const DiskRecord& rec);
void delete_record(uint32_t cdid, uint32_t hashvalue);
void error(const std::string& error, const std::string& exterror, UnTar::buf_t& data);
};
}
#endif /* cddbupdater_hpp */