Exemple #1
0
void Statement::reset()
{
    if (::sqlite3_clear_bindings(mStmtPtr) != SQLITE_OK) {
        throw CargoException("Error unbinding statement: " +
                              mConnRef.getErrorMessage());
    }

    if (::sqlite3_reset(mStmtPtr) != SQLITE_OK) {
        throw CargoException("Error reseting statement: " +
                              mConnRef.getErrorMessage());
    }
}
Exemple #2
0
void loadFromKVStoreWithJsonFile(const std::string& kvfile,
                                 const std::string& jsonfile,
                                 Cargo& visitable,
                                 const std::string& kvVisitableName)
{
    std::string content;
    if (!internals::fsutils::readFileContent(jsonfile, content)) {
        throw CargoException("Could not load " + jsonfile);
    }
    try {
        loadFromKVStoreWithJson(kvfile, content, visitable, kvVisitableName);
    } catch (CargoException& e) {
        throw CargoException("Error in " + jsonfile + ": " + e.what());
    }
}
Exemple #3
0
Statement::Statement::~Statement()
{
    if (::sqlite3_finalize(mStmtPtr) != SQLITE_OK) {
        throw CargoException("Error during finalizing statement " +
                              mConnRef.getErrorMessage());
    }
}
Exemple #4
0
void Connection::exec(const std::string& query)
{
    char* mess;
    if (::sqlite3_exec(mDbPtr, query.c_str(), 0, 0, &mess) != SQLITE_OK) {
        throw CargoException("Error during executing statement " + std::string(mess));
    }
}
Exemple #5
0
static void extract(const char *pakfile, const char *root) {
    ZipReader zr(pakfile);
    const Zip::Files& files = zr.get_files();
    for (Zip::Files::const_iterator it = files.begin(); it != files.end(); it++) {
        create_directory(root, it->filename.c_str());
        FILE *f = 0;
        const char *data = 0;
        try {
            std::string new_file(root);
            new_file += "/" + it->filename;
            modify_directory_separator(new_file);
            f = fopen(new_file.c_str(), "wb");
            if (!f) {
                throw CargoException(std::string("Cannot open file for writing: ") + it->filename + " (" + strerror(errno) + ")");
            }
            size_t sz;
            data = zr.extract(it->filename, &sz);
            fwrite(data, 1, sz, f);
            zr.destroy(data);
            fclose(f);
        } catch (const Exception& e) {
            if (f) {
                fclose(f);
            }
            if (data) {
                zr.destroy(data);
            }
            throw;
        }
    }

    std::cout << zr.get_files().size() << " files extracted." << std::endl;
}
Exemple #6
0
Statement::Statement(sqlite3::Connection& connRef, const std::string& query)
    : mConnRef(connRef)
{
    if (::sqlite3_prepare_v2(connRef.get(),
                             query.c_str(),
                             query.size(),
                             &mStmtPtr,
                             NULL)
            != SQLITE_OK) {
        throw CargoException("Error during preparing statement " +
                              mConnRef.getErrorMessage());
    }

    if (mStmtPtr == NULL) {
        throw CargoException("Wrong query: " + query);
    }
}
Exemple #7
0
Connection::Connection(const std::string& path)
{
    if (path.empty()) {
        // Sqlite creates temporary database in case of empty path
        // but we want to forbid this.
        throw CargoException("Error opening the database: empty path");
    }
    if (::sqlite3_open_v2(path.c_str(),
                          &mDbPtr,
                          SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
                          NULL) != SQLITE_OK) {
        throw CargoException("Error opening the database: " + getErrorMessage());
    }

    if (mDbPtr == NULL) {
        throw CargoException("Error opening the database: Unable to allocate memory.");
    }
}