VarBinary and Insert Statement

Ruslan Zasukhin sunshine at public.kherson.ua
Fri Nov 21 11:25:09 CST 2003


on 11/21/03 6:04 AM, Anoop Ahuja at ahuja_anoop at rediffmail.com wrote:

> Hi Ruslan
> 
> Thanx a lot for the last reply.
> 
> But the problem is that i didnt find any docs on using
> DataBase_SqlExecuteBinded(), though just found its declaration in
> ,<VCSDK_Database.h> along with BindParam's.
> 
> Could you please enlighten me a little bit on how to use it in C++ or C, if
> you have any sample code or docs to read about this, even this function is not
> mentioned in any of your docs mentioned below.

Yes, binding is not documented probably.

Okay, this is function from Valentina PHP module.
You can see how we create array of binds, how we fill that array, and how we
send it to Valentina_SqlExecute()

So what language you use?   C or C++ ?
 
//    int valDatabase_SqlExecute( dbRef, SqlQuery, [bind_list] )
//
ZEND_FUNCTION(valdatabase_sqlexecute)
{
    START_PHP_FUNCTION(3,2);

    VPHP_DATABASE_CHECK(args[0]);

    char*        qstr = NULL;
    HashTable*    array = NULL;
    
    BindParam* pCSDK_BindArray = NULL;
    ulong Count = 0;

    switch(arg_count)
    {
        case 3:
        {    
            convert_to_array_ex(args[2]);
            array = Z_ARRVAL_PP(args[2]);
            
            Count = zend_hash_num_elements( array );
            
            pCSDK_BindArray = (BindParam*) malloc( Count * sizeof(BindParam)
); 
            zend_hash_internal_pointer_reset(array);
            
            for( ulong i = 0; i < Count ; ++i )
            {
                zval **val;
                zend_hash_get_current_data(array, (void**) &val);
        
                switch( Z_TYPE_PP(val) )
                {
                    case IS_STRING:
                    {
                        pCSDK_BindArray[i].pData = (uchar*)
Z_STRVAL_PP(val);
                        pCSDK_BindArray[i].size  = Z_STRLEN_PP(val);
                    }break;
            
                    case IS_BOOL:
                    case IS_LONG:
                    case IS_DOUBLE:
                    {
                        convert_to_string_ex( val );
                        pCSDK_BindArray[i].pData = (uchar*)
Z_STRVAL_PP(val);
                        pCSDK_BindArray[i].size  = Z_STRLEN_PP(val);
                    }break;
            
                    default:
                    {
                        zend_error(E_WARNING, "Expected array of strings or
numbers." );
                        pCSDK_BindArray[i].pData = NULL;
                        pCSDK_BindArray[i].size  = 0;
                    }
                }

                zend_hash_move_forward(array);
            }
        }
            
        case 2:
            convert_to_string_ex(args[1]);
            qstr = Z_STRVAL_PP(args[1]);
    }

    ulong records = 0;
    
    if( arg_count >= 3 )
    {
        records = DataBase_SqlExecuteBinded(pDB, qstr, pCSDK_BindArray,
Count, 0 );

        if( records > 0 )
            DataBase_Flush(pDB);
        
        free( pCSDK_BindArray );
    }
    else
    {
        records = DataBase_SqlExecute(pDB, qstr);
    }

    STOP_PHP_FUNCTION;

    RETURN_LONG( (long) records );
}


----------------------------------------------------------------------------
------------
So the main points are.
I will try make code for YOUR task:


{
        BindParam* pCSDK_BindArray = NULL;

        // let you have just one binary parameter:
        uchar* pdata = ³aaaaaaaaaaa²;


            pCSDK_BindArray = (BindParam*) malloc( Count * sizeof(BindParam)
); 

                        pCSDK_BindArray[0].pData = pdata;
                        pCSDK_BindArray[0].size  = size of pdata; // define
it self in your task.

        sqlstr = ³INSERT INTO T (f1) VALUES (:1)²

        DataBase_SqlExecuteBinded(pDB, sqlstr, pCSDK_BindArray, 1, 0 );

         free( pCSDK_BindArray );
}




-- 
Best regards,
Ruslan Zasukhin      [ I feel the need...the need for speed ]
-------------------------------------------------------------
e-mail: ruslan at paradigmasoft.com
web: http://www.paradigmasoft.com

To subscribe to the Valentina mail list go to:
http://lists.macserve.net/mailman/listinfo/valentina
-------------------------------------------------------------



More information about the Valentina mailing list