Exemplo n.º 1
0
int SQLiteStatement::prepare()
{
    ASSERT(!m_isPrepared);

    MutexLocker databaseLock(m_database.databaseMutex());
    if (m_database.isInterrupted())
        return SQLITE_INTERRUPT;

    CString query = m_query.stripWhiteSpace().utf8();

    LOG(SQLDatabase, "SQL - prepare - %s", query.data());

    // Pass the length of the string including the null character to sqlite3_prepare_v2;
    // this lets SQLite avoid an extra string copy.
    size_t lengthIncludingNullCharacter = query.length() + 1;

    const char* tail;
    int error = sqlite3_prepare_v2(m_database.sqlite3Handle(), query.data(), lengthIncludingNullCharacter, &m_statement, &tail);

    if (error != SQLITE_OK)
        LOG(SQLDatabase, "sqlite3_prepare16 failed (%i)\n%s\n%s", error, query.data(), sqlite3_errmsg(m_database.sqlite3Handle()));

    if (tail && *tail)
        error = SQLITE_ERROR;

#ifndef NDEBUG
    m_isPrepared = error == SQLITE_OK;
#endif
    return error;
}
Exemplo n.º 2
0
int SQLiteStatement::prepare()
{
    ASSERT(!m_isPrepared);

    MutexLocker databaseLock(m_database.databaseMutex());
    if (m_database.isInterrupted())
        return SQLITE_INTERRUPT;

    const void* tail = 0;
    LOG(SQLDatabase, "SQL - prepare - %s", m_query.ascii().data());
    String strippedQuery = m_query.stripWhiteSpace();
    const UChar* nullTermed = strippedQuery.deprecatedCharactersWithNullTermination();
    int error = sqlite3_prepare16_v2(m_database.sqlite3Handle(), nullTermed, -1, &m_statement, &tail);

    // Starting with version 3.6.16, sqlite has a patch (http://www.sqlite.org/src/ci/256ec3c6af)
    // that should make sure sqlite3_prepare16_v2 doesn't return a SQLITE_SCHEMA error.
    // If we're using an older sqlite version, try to emulate the patch.
    if (error == SQLITE_SCHEMA) {
      sqlite3_finalize(m_statement);
      error = sqlite3_prepare16_v2(m_database.sqlite3Handle(), m_query.deprecatedCharactersWithNullTermination(), -1, &m_statement, &tail);
    }

    if (error != SQLITE_OK)
        LOG(SQLDatabase, "sqlite3_prepare16 failed (%i)\n%s\n%s", error, m_query.ascii().data(), sqlite3_errmsg(m_database.sqlite3Handle()));
    const UChar* ch = static_cast<const UChar*>(tail);
    if (ch && *ch)
        error = SQLITE_ERROR;
#ifndef NDEBUG
    m_isPrepared = error == SQLITE_OK;
#endif
    return error;
}
Exemplo n.º 3
0
int SQLiteStatement::step()
{
    MutexLocker databaseLock(m_database.databaseMutex());
    if (m_database.isInterrupted())
        return SQLITE_INTERRUPT;
    ASSERT(m_isPrepared);

    if (!m_statement)
        return SQLITE_OK;
    LOG(SQLDatabase, "SQL - step - %s", m_query.ascii().data());
    int error = sqlite3_step(m_statement);
    if (error != SQLITE_DONE && error != SQLITE_ROW) {
        LOG(SQLDatabase, "sqlite3_step failed (%i)\nQuery - %s\nError - %s", 
            error, m_query.ascii().data(), sqlite3_errmsg(m_database.sqlite3Handle()));
    }

    return error;
}
Exemplo n.º 4
0
int SQLiteStatement::step()
{
    MutexLocker databaseLock(m_database.databaseMutex());

    if (!m_statement)
        return SQLITE_OK;

    // The database needs to update its last changes count before each statement
    // in order to compute properly the lastChanges() return value.
    m_database.updateLastChangesCount();

    LOG(SQLDatabase, "SQL - step - %s", m_query.ascii().data());
    int error = sqlite3_step(m_statement);
    if (error != SQLITE_DONE && error != SQLITE_ROW) {
        LOG(SQLDatabase, "sqlite3_step failed (%i)\nQuery - %s\nError - %s", 
            error, m_query.ascii().data(), sqlite3_errmsg(m_database.sqlite3Handle()));
    }

    return error;
}