|
@@ -25,14 +25,14 @@ namespace db {
|
|
|
std::array<std::string, 3> queries = {
|
|
|
"CREATE TABLE IF NOT EXISTS \"author\" (\
|
|
|
\"id\" INTEGER,\
|
|
|
- \"yt_id\" TEXT,\
|
|
|
+ \"ytid\" TEXT,\
|
|
|
\"name\" TEXT,\
|
|
|
PRIMARY KEY(\"id\" AUTOINCREMENT)\
|
|
|
)",
|
|
|
|
|
|
"CREATE TABLE IF NOT EXISTS \"video\" (\
|
|
|
\"id\" INTEGER,\
|
|
|
- \"yt_id\" TEXT,\
|
|
|
+ \"ytid\" TEXT,\
|
|
|
\"title\" TEXT NOT NULL,\
|
|
|
\"description\" TEXT NOT NULL,\
|
|
|
\"author_id\" INTEGER NOT NULL,\
|
|
@@ -55,7 +55,7 @@ namespace db {
|
|
|
status = sqlite3_exec(DB, queries[i].c_str(), NULL, 0, &message_error);
|
|
|
|
|
|
if (status != SQLITE_OK) {
|
|
|
- std::cerr << "Error creating tables" << std::endl;
|
|
|
+ std::cerr << "Error creating tables: " << status << std::endl;
|
|
|
sqlite3_free(message_error);
|
|
|
databaseClose();
|
|
|
return;
|
|
@@ -64,13 +64,13 @@ namespace db {
|
|
|
databaseClose();
|
|
|
}
|
|
|
|
|
|
- bool getVideoByYTID(std::string yt_id, video* output) {
|
|
|
+ bool getVideoByYTID(std::string ytid, video* output) {
|
|
|
sqlite3_stmt* stmt;
|
|
|
std::string query =
|
|
|
- "SELECT v.id, v.yt_id, v.title, v.description, a.id, a.yt_id, a.name,"
|
|
|
+ "SELECT v.id, v.ytid, v.title, v.description, a.id, a.ytid, a.name,"
|
|
|
" v.published_at, v.views_count, v.rate_status, v.big_thumbnail"
|
|
|
" FROM video v LEFT JOIN author a ON v.author_id=a.id"
|
|
|
- " WHERE v.yt_id=?";
|
|
|
+ " WHERE v.ytid=?";
|
|
|
databaseOpen();
|
|
|
author video_author;
|
|
|
|
|
@@ -78,7 +78,7 @@ namespace db {
|
|
|
sqlite3_prepare_v2(DB, query.c_str(), query.length(), &stmt, nullptr);
|
|
|
|
|
|
// Привязка данных
|
|
|
- sqlite3_bind_text(stmt, 1, yt_id.c_str(), yt_id.length(), SQLITE_STATIC);
|
|
|
+ sqlite3_bind_text(stmt, 1, ytid.c_str(), ytid.length(), SQLITE_STATIC);
|
|
|
|
|
|
// Выполнение
|
|
|
int result = sqlite3_step(stmt);
|
|
@@ -92,7 +92,7 @@ namespace db {
|
|
|
// unsigned const char* конвертируется в std::string
|
|
|
// https://stackoverflow.com/a/804131
|
|
|
video_author.id = sqlite3_column_int(stmt, 4);
|
|
|
- video_author.yt_id = std::string(reinterpret_cast<const char*>(
|
|
|
+ video_author.ytid = std::string(reinterpret_cast<const char*>(
|
|
|
sqlite3_column_text(stmt, 5)
|
|
|
));
|
|
|
video_author.name = Glib::ustring(reinterpret_cast<const char*>(
|
|
@@ -100,7 +100,7 @@ namespace db {
|
|
|
));
|
|
|
|
|
|
output->id = sqlite3_column_int(stmt, 0);
|
|
|
- output->yt_id = std::string(reinterpret_cast<const char*>(
|
|
|
+ output->ytid = std::string(reinterpret_cast<const char*>(
|
|
|
sqlite3_column_text(stmt, 1)
|
|
|
));
|
|
|
output->title = Glib::ustring(reinterpret_cast<const char*>(
|
|
@@ -125,19 +125,19 @@ namespace db {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- bool getAuthorByYTID(std::string yt_id, author* output) {
|
|
|
+ bool getAuthorByYTID(std::string ytid, author* output) {
|
|
|
sqlite3_stmt* stmt;
|
|
|
std::string query =
|
|
|
"SELECT a.id, a.name"
|
|
|
" FROM author a"
|
|
|
- " WHERE a.yt_id=?";
|
|
|
+ " WHERE a.ytid=?";
|
|
|
databaseOpen();
|
|
|
|
|
|
// Подготовка
|
|
|
sqlite3_prepare_v2(DB, query.c_str(), query.length(), &stmt, nullptr);
|
|
|
|
|
|
// Привязка данных
|
|
|
- sqlite3_bind_text(stmt, 1, yt_id.c_str(), yt_id.length(), SQLITE_STATIC);
|
|
|
+ sqlite3_bind_text(stmt, 1, ytid.c_str(), ytid.length(), SQLITE_STATIC);
|
|
|
|
|
|
// Выполнение
|
|
|
int result = sqlite3_step(stmt);
|
|
@@ -162,11 +162,11 @@ namespace db {
|
|
|
void addAuthor(author* a) {
|
|
|
sqlite3_stmt* stmt;
|
|
|
std::string query =
|
|
|
- "INSERT INTO author (yt_id, name) VALUES(?, ?)";
|
|
|
+ "INSERT INTO author (ytid, name) VALUES(?, ?)";
|
|
|
databaseOpen();
|
|
|
|
|
|
sqlite3_prepare_v2(DB, query.c_str(), query.length(), &stmt, nullptr);
|
|
|
- sqlite3_bind_text(stmt, 1, a->yt_id.c_str(), a->yt_id.length(), SQLITE_STATIC);
|
|
|
+ sqlite3_bind_text(stmt, 1, a->ytid.c_str(), a->ytid.length(), SQLITE_STATIC);
|
|
|
sqlite3_bind_text(stmt, 2, a->name.c_str(), a->name.bytes(), SQLITE_STATIC);
|
|
|
sqlite3_step(stmt);
|
|
|
|
|
@@ -180,13 +180,13 @@ namespace db {
|
|
|
{
|
|
|
sqlite3_stmt* stmt;
|
|
|
std::string query =
|
|
|
- "INSERT INTO video (yt_id, title, description, author_id, published_at,"
|
|
|
+ "INSERT INTO video (ytid, title, description, author_id, published_at,"
|
|
|
" views_count, rate_status, big_thumbnail)"
|
|
|
" VALUES(?, ?, ?, ?, ?, ?, ?, ?)";
|
|
|
databaseOpen();
|
|
|
|
|
|
sqlite3_prepare_v2(DB, query.c_str(), query.length(), &stmt, nullptr);
|
|
|
- sqlite3_bind_text(stmt, 1, v->yt_id.c_str(), v->yt_id.length(), SQLITE_STATIC);
|
|
|
+ sqlite3_bind_text(stmt, 1, v->ytid.c_str(), v->ytid.length(), SQLITE_STATIC);
|
|
|
sqlite3_bind_text(stmt, 2, v->title.c_str(), v->title.bytes(), SQLITE_STATIC);
|
|
|
sqlite3_bind_text(stmt, 3, v->description.c_str(), v->description.bytes(), SQLITE_STATIC);
|
|
|
sqlite3_bind_int(stmt, 4, v->author_obj.id);
|
|
@@ -202,33 +202,32 @@ namespace db {
|
|
|
databaseClose();
|
|
|
}
|
|
|
|
|
|
- void setVideoRating(std::string yt_id, int rating)
|
|
|
+ void setVideoRating(std::string ytid, int rating)
|
|
|
{
|
|
|
sqlite3_stmt* stmt;
|
|
|
std::string query =
|
|
|
- "UPDATE video SET rate_status=? WHERE yt_id=?";
|
|
|
+ "UPDATE video SET rate_status=? WHERE ytid=?";
|
|
|
databaseOpen();
|
|
|
|
|
|
sqlite3_prepare_v2(DB, query.c_str(), query.length(), &stmt, nullptr);
|
|
|
sqlite3_bind_int(stmt, 1, rating);
|
|
|
- sqlite3_bind_text(stmt, 2, yt_id.c_str(), yt_id.length(), SQLITE_STATIC);
|
|
|
+ sqlite3_bind_text(stmt, 2, ytid.c_str(), ytid.length(), SQLITE_STATIC);
|
|
|
|
|
|
- std::cout << sqlite3_step(stmt);
|
|
|
sqlite3_finalize(stmt);
|
|
|
databaseClose();
|
|
|
}
|
|
|
|
|
|
- int getVideoRating(std::string yt_id)
|
|
|
+ int getVideoRating(std::string ytid)
|
|
|
{
|
|
|
sqlite3_stmt* stmt;
|
|
|
std::string query =
|
|
|
"SELECT v.rate_status"
|
|
|
" FROM video v"
|
|
|
- " WHERE v.yt_id=?";
|
|
|
+ " WHERE v.ytid=?";
|
|
|
|
|
|
databaseOpen();
|
|
|
sqlite3_prepare_v2(DB, query.c_str(), query.length(), &stmt, nullptr);
|
|
|
- sqlite3_bind_text(stmt, 1, yt_id.c_str(), yt_id.length(), SQLITE_STATIC);
|
|
|
+ sqlite3_bind_text(stmt, 1, ytid.c_str(), ytid.length(), SQLITE_STATIC);
|
|
|
|
|
|
// Выполнение
|
|
|
int output;
|