Ejemplo n.º 1
0
///////////////////////////////////////////////////////////////
//
// CDatabaseManagerImpl::QueryWithResultf
//
// Start a query and wait for the result
//
///////////////////////////////////////////////////////////////
bool CDatabaseManagerImpl::QueryWithResultf ( SConnectionHandle hConnection, CRegistryResult* pResult, const char* szQuery, ... )
{
    va_list vl;
    va_start ( vl, szQuery );

    ClearLastErrorMessage ();

    // Check connection
    if ( !MapContains ( m_ConnectionTypeMap, hConnection ) )
    {
        SetLastErrorMessage ( "Invalid connection" );
        return false;
    }

    // Insert arguments with correct escapement
    SString strEscapedQuery = InsertQueryArguments ( hConnection, szQuery, vl );

    // Start query
    CDbJobData* pJobData = m_JobQueue->AddCommand ( EJobCommand::QUERY, hConnection, strEscapedQuery );

    // Wait for result
    QueryPoll ( pJobData, -1 );

    // Process result
    if ( pJobData->result.status == EJobResult::FAIL )
    {
        if ( pResult )
            *pResult = CRegistryResult ();
        return false;
    }
    else
    {
        if ( pResult )
            *pResult = pJobData->result.registryResult;
        return true;
    }
}
Ejemplo n.º 2
0
bool CRegistry::Query ( CRegistryResult* pResult, const char* szQuery, va_list vl )
{
    // Clear result
    if ( pResult )
        *pResult = CRegistryResult ();

    if ( m_bOpened == false )
	{
        SetLastErrorMessage ( "SQLite3 was not opened, cannot perform query!", szQuery );
        return false;
    }

    SString strParsedQuery;
    for ( unsigned int i = 0; szQuery[i] != '\0'; i++ )
    {
        if ( szQuery[i] != SQL_VARIABLE_PLACEHOLDER )
        {
            strParsedQuery += szQuery[i];
        }
        else
        {
            switch ( va_arg( vl, int ) )
            {
                case SQLITE_INTEGER:
                {
                    int iValue = va_arg( vl, int );
                    strParsedQuery += SString ( "%d", iValue );
                }
                break;

                case SQLITE_FLOAT:
                {
                    double fValue = va_arg( vl, double );
                    strParsedQuery += SString ( "%f", fValue );
                }
                break;

                case SQLITE_TEXT:
                {
                    const char* szValue = va_arg( vl, const char* );
                    assert ( szValue );
                    strParsedQuery += SString ( "'%s'", SQLEscape ( szValue, true, false ).c_str () );
                }
                break;

                case SQLITE_BLOB:
                {
                    strParsedQuery += "CANT_DO_BLOBS_M8";
                }
                break;

                case SQLITE_NULL:
                {
                    strParsedQuery += "NULL";
                }
                break;

                default:
                    // someone passed a value without specifying its type
                    assert ( 0 );
                    break;
            }
        }
    }
    va_end ( vl );
    // VACUUM query does not work with transactions
    if ( strParsedQuery.BeginsWithI( "VACUUM" ) )
        EndAutomaticTransaction ();
    else
        BeginAutomaticTransaction ();
    return QueryInternal ( strParsedQuery.c_str (), pResult );
}