Create a C++ program that simulates a basic inventory management system for a store. The system should support adding items, removing items, updating item quantities, and displaying the current inventory. Use SQLite as the database to store the inventory data.
PLAINFORMAT
#include <iostream>
#include <string>
#include <sqlite3.h>

static int callback(void *data, int argc, char **argv, char **azColName) {
    for (int i = 0; i < argc; i++) {
        std::cout << azColName[i] << ": " << (argv[i] ? argv[i] : "NULL") << std::endl;
    }
    std::cout << std::endl;
    return 0;
}

void createTable(sqlite3 *db) {
    const char *sql = "CREATE TABLE IF NOT EXISTS INVENTORY("
                      "ID INTEGER PRIMARY KEY AUTOINCREMENT,"
                      "NAME TEXT NOT NULL,"
                      "QUANTITY INT NOT NULL);";

    char *errMsg = nullptr;
    if (sqlite3_exec(db, sql, nullptr, nullptr, &errMsg)) {
        std::cerr << "Error creating table: " << errMsg << std::endl;
        sqlite3_free(errMsg);
    } else {
        std::cout << "Table created successfully" << std::endl;
    }
}

void addItem(sqlite3 *db, const std::string &name, int quantity) {
    std::string sql = "INSERT INTO INVENTORY(NAME, QUANTITY) VALUES('" + name + "', " + std::to_string(quantity) + ");";
    char *errMsg = nullptr;
    if (sqlite3_exec(db, sql.c_str(), nullptr, nullptr, &errMsg)) {
        std::cerr << "Error adding item: " << errMsg << std::endl;
        sqlite3_free(errMsg);
    } else {
        std::cout << "Item added successfully" << std::endl;
    }
}

void removeItem(sqlite3 *db, int id) {
    std::string sql = "DELETE FROM INVENTORY WHERE ID=" + std::to_string(id) + ";";
    char *errMsg = nullptr;
    if (sqlite3_exec(db, sql.c_str(), nullptr, nullptr, &errMsg)) {
        std::cerr << "Error removing item: " << errMsg << std::endl;
        sqlite3_free(errMsg);
    } else {
        std::cout << "Item removed successfully" << std::endl;
    }
}

void updateQuantity(sqlite3 *db, int id, int quantity) {
    std::string sql = "UPDATE INVENTORY SET QUANTITY=" + std::to_string(quantity) + " WHERE ID=" + std::to_string(id) + ";";
    char *errMsg = nullptr;
    if (sqlite3_exec(db, sql.c_str(), nullptr, nullptr, &errMsg)) {
        std::cerr << "Error updating quantity: " << errMsg << std::endl;
        sqlite3_free(errMsg);
    } else {
        std::cout << "Quantity updated successfully" << std::endl;
    }
}

void displayInventory(sqlite3 *db) {
    const char *sql = "SELECT * FROM INVENTORY;";
    char *errMsg = nullptr;
    if (sqlite3_exec(db, sql, callback, nullptr, &errMsg)) {
        std::cerr << "Error displaying inventory: " << errMsg << std::endl;
        sqlite3_free(errMsg);
    }
}

int main() {
    sqlite3 *db;
    if (sqlite3_open("inventory.db", &db)) {
        std::cerr << "Can't open database: " << sqlite3_errmsg(db) << std::endl;
        return 1;
    }

    createTable(db);

    // Example usage
    addItem(db, "Apples", 10);
    addItem(db, "Oranges", 5);
    displayInventory(db);
    updateQuantity(db, 1, 8);
    removeItem(db, 2);
    displayInventory(db);

    sqlite3_close(db);
    return 0;
}