SourceCode/Bond/Servo/RecipeManager.cpp
@@ -43,7 +43,8 @@
    const std::string createRecipeTable = R"(
        CREATE TABLE IF NOT EXISTS recipes (
            ppid TEXT PRIMARY KEY NOT NULL,
            id INTEGER PRIMARY KEY AUTOINCREMENT,
            ppid TEXT NOT NULL UNIQUE,
            description TEXT,
            create_time TEXT DEFAULT (datetime('now', 'localtime'))
        );
@@ -283,6 +284,44 @@
    return vecPPID;
}
std::string RecipeManager::getPPIDById(int nId) {
    if (!m_pDB) {
        return {};
    }
    std::ostringstream query;
    query << "SELECT ppid FROM recipes WHERE id = " << nId << ";";
    auto rows = m_pDB->fetchResults(query.str());
    if (rows.empty() || rows[0].empty()) {
        return {};
    }
    return rows[0][0];
}
int RecipeManager::getIdByPPID(const std::string& ppid) {
    if (!m_pDB) {
        return -1;
    }
    std::ostringstream query;
    query << "SELECT id FROM recipes WHERE ppid = '" << ppid << "';";
    auto rows = m_pDB->fetchResults(query.str());
    if (rows.empty() || rows[0].empty()) {
        return -1;
    }
    try {
        return std::stoi(rows[0][0]);
    }
    catch (...) {
        std::cerr << "Invalid id value for PPID: " << ppid << std::endl;
        return -1;
    }
}
RecipeInfo RecipeManager::getRecipeByPPID(const std::string& ppid) {
    RecipeInfo info;
    auto rows = m_pDB->fetchResults("SELECT ppid, description, create_time FROM recipes WHERE ppid = '" + ppid + "';");