Defining/Binding Blob Values

Ruslan Zasukhin sunshine at public.kherson.ua
Fri Aug 15 14:23:00 CDT 2008


On 8/14/08 3:15 PM, "Thomas.DellAnno at swisstopo.ch"
<Thomas.DellAnno at swisstopo.ch> wrote:

> I'm using the C++-API and I'm unable to create Blob values and insert/update
> them via parameter binding (:1, :2, etc.). I have found solutions that are
> working with "DateTime" values (see source code below) and primitive data
> types (int, double, etc.) but found none for Blobs. I'm shure I'm missing
> something but I didn't find the right answer in the available valentina
> documentation.
> 
> Here the code fragment: the problem is calling the function "put_Data" of an
> "I_ValueBinaryPtr" pointer returns always an null pointer. Is the use of
> I_ValueBinary correct in the context of blob handling?
> 
> Many thanks in advance and kind regards  -- Tom

Another example from our Valentina for VCOM

ArrayOfValues_Ptr BuildArrayOfBinds(VARIANT inBinds, FBL::I_Database*
inDatabase)
{
#ifdef _DEBUG
    log_start("BuildArrayOfBinds");
#endif

    ArrayOfValues_Ptr pBinds;
    
    if( inBinds.vt & VT_ARRAY ) // It is an array of variants
    {
        LONG lBound;
        LONG uBound;

        SafeArrayGetLBound( inBinds.parray, 1, &lBound );
        SafeArrayGetUBound( inBinds.parray, 1, &uBound );

        VARIANT dat;
        String str;

        VariantInit( &dat );
        
        long bindCount = uBound - lBound;
        //#ifdef _DEBUG
        //    LOG_PARAM(count);
        //#endif

        if( bindCount )
            pBinds = new ArrayOfValues();

        for (long i = 0; i < bindCount; i++)
        {
            SafeArrayGetElement(inBinds.parray,&i,&dat);

            //#ifdef _DEBUG
            //    LOG_PARAM(dat.bstrVal);
            //#endif

            // It is an array of bytes (vartype - 8209) which is saved into
the variant array
            if( dat.vt == 8209 )
            {
                // Array of bytes (binary value) comes as single value.
                //
                FBL_CHECK( dat.vt & VT_UI1 );

                LONG lBound_byteArray;
                LONG uBound_byteArray;

                SafeArrayGetLBound( dat.parray, 1, &lBound_byteArray );
                SafeArrayGetUBound( dat.parray, 1, &uBound_byteArray );

                UINT bufferSize = uBound_byteArray - lBound_byteArray;
                BYTE HUGEP *pBytes;
                SafeArrayAccessData( dat.parray, (void HUGEP* FAR*)&pBytes
);

                I_Value_Ptr a = inDatabase->CreateValue( ::kTypeFixedBinary,
0, &bufferSize );
                a->put_String( (char*)pBytes, (char*)pBytes + bufferSize );
                pBinds->AddItem( a );

                SafeArrayUnaccessData( dat.parray );
            }

            switch( dat.vt )
            {

                case VT_EMPTY:
                case VT_NULL:
                {
                    I_Value_Ptr a = inDatabase->CreateValue( ::kTypeBoolean,
::fNullable );
                    a->put_IsNull(true);
                    pBinds->AddItem( a );

                }break;

                case VT_BOOL:
                {
                    I_Value_Ptr a = inDatabase->CreateValue(
::kTypeBoolean,0 );
                    a->put_Boolean(dat.boolVal);
                    pBinds->AddItem( a );

                }break;

                case VT_UI1:
                {
                    I_Value_Ptr a = inDatabase->CreateValue(::kTypeByte, 0
);
                    a->put_Byte(dat.bVal);
                    pBinds->AddItem( a );

                }break;

                case VT_I2:
                {
                    I_Value_Ptr a = inDatabase->CreateValue(::kTypeShort, 0
);
                    a->put_Short(dat.iVal);
                    pBinds->AddItem( a );
                   
                }break;

                case VT_UI2:
                {
                    I_Value_Ptr a = inDatabase->CreateValue(::kTypeUShort, 0
);
                    a->put_UShort(dat.uiVal);
                    pBinds->AddItem( a );
                   
                }break;

                case VT_I4:
                {
                    I_Value_Ptr a = inDatabase->CreateValue(::kTypeLong, 0
);
                    a->put_Long(dat.lVal);
                    pBinds->AddItem( a );
                   
                }break;

                case VT_UI4:
                {
                    I_Value_Ptr a = inDatabase->CreateValue(::kTypeULong, 0
);
                    a->put_ULong(dat.ulVal);
                    pBinds->AddItem( a );
                   
                }break;

                case VT_I8:
                {
                    I_Value_Ptr a = inDatabase->CreateValue(::kTypeLLong, 0
);
                    a->put_LLong(dat.llVal);
                    pBinds->AddItem( a );
                   
                }break;

                case VT_UI8:
                {
                    I_Value_Ptr a = inDatabase->CreateValue(::kTypeULLong, 0
);
                    a->put_ULLong(dat.ullVal);
                    pBinds->AddItem( a );
                   
                }break;

                case VT_R4:
                {
                    I_Value_Ptr a = inDatabase->CreateValue(::kTypeFloat, 0
);
                    a->put_Float(dat.fltVal);
                    pBinds->AddItem( a );
                   
                }break;

                case VT_R8:
                {
                    I_Value_Ptr a = inDatabase->CreateValue(::kTypeDouble,
0);
                    a->put_Double(dat.dblVal);
                    pBinds->AddItem( a );
                   
                }break;

                case VT_BSTR:
                    {
                   
                    String str = dat.bstrVal;
                    long length = str.length();

                    I_Value_Ptr a = inDatabase->CreateValue(::kTypeString,
0, &length );
                    a->put_String(str.c_str(), str.end());
                    pBinds->AddItem( a );

                    #ifdef _DEBUG
                        LOG_PARAM(str);
                    #endif


                }break;

                case VT_DATE:
                {
                    I_Value_Ptr val =
inDatabase->CreateValue(::kTypeDateTime, 0);
                    I_ValueDateTime_Ptr a =
fbl_dynamic_cast<I_ValueDateTime>( val );

                    COleDateTime dtVal( dat.date );
                   
                    int year = dtVal.GetYear();
                    int month = dtVal.GetMonth();
                    int day = dtVal.GetDay();


                    // Trick: 30/12/1899 will be zero date:
                    if(year == 1899 && month == 12 && day == 30)
                    {
                        a->put_Year( 0 );
                        a->put_Month( (ushort)0 );
                        a->put_Day( (ushort)0 );
                    }
                    else
                    {
                        a->put_Year( year );
                        a->put_Month( (ushort)month );
                        a->put_Day( (ushort)day );
                    }

                    a->put_Hours( (ushort)dtVal.GetHour() );
                    a->put_Minutes( (ushort)dtVal.GetMinute() );
                    a->put_Seconds( (ushort)dtVal.GetSecond() );

                    pBinds->AddItem( val );
                   
                
                }break;

                default:
                {
                        // do nothing.
                }
            }
        }

        // Clear
        VariantClear( &dat );

    }
    return pBinds;
}





-- 
Best regards,

Ruslan Zasukhin
VP Engineering and New Technology
Paradigma Software, Inc

Valentina - Joining Worlds of Information
http://www.paradigmasoft.com

[I feel the need: the need for speed]



More information about the Valentina mailing list