15
using std::ostringstream;
17
// Fuzzy compare function using levenshtein string distance
18
static void fuzzy_like(sqlite3_context *context, int argc, sqlite3_value** val)
21
throw SQLException("fuzzy_like", "argc != 2");
22
sqlite3_result_int(context, string_like(
23
(char*)sqlite3_value_text(val[0]),
24
(char*)sqlite3_value_text(val[1]), 4));
31
if (!access(get_imms_root("imms.db").c_str(), R_OK)
32
&& access(get_imms_root("imms2.db").c_str(), F_OK))
34
cerr << string(60, '*') << endl;
35
cerr << "Old database format detected, "
36
"will attempt an upgrade..." << endl;
37
ostringstream command;
38
command << "sqlite " << get_imms_root("imms.db")
39
<< " .dump | sqlite3 " << get_imms_root("imms2.db") << endl;
40
cerr << "Running: " << command.str() << endl;
41
system(command.str().c_str());
42
cerr << "If you see errors above verify that you have *both*"
43
" sqlite 2.8.x" << endl;
44
cerr << "and 3.0.x installed and rerun the command by hand." << endl;
45
cerr << string(60, '*') << endl;
48
dbcon.open(get_imms_root("imms2.db"));
49
sqlite3_create_function(db(), "similar", 2, 1, 0, fuzzy_like, 0, 0);
57
void SqlDb::close_database()
64
return db() ? sqlite3_changes(db()) : 0;