Marcelo /Patricio;
Grato ver la pregunta.
Saving an image, or anything else for that matter, is best done via pure SQL. To save images, I prefer to use a binary field instead of a memo field. Here is some actual code (a bit reduced):
- Code: Select all Expand view
cSql := "INSERT INTO images ( jpg ) VALUES ( :bindata ) \n"
ADSCreateSQLStatement( "cAlias" )
AdsPrepareSql( cSql )
binImage := MemoRead( cFile )
AdsSetBinary( "bindata", binImage )
AdsExecuteSql()
As you see, you must first prepare the query. Prepared SQLs execute faster, especially if your are executing the same sql inside a loop, as only the parameters change. You set parameters using ACE functions: AdsSetBinary(), AdsSetString(), AdsSetLong(), AdsSetDouble(), AdsSetDate(), AdsSetLogical(). These functions are not in included (as of now) with AdsFunc.c on harbour. They should soon be included as I recently sent them to be included as a contribution to harbour.
In the meanwhile, here is the wrappers to those functions. You only need to add this code to your adsfunc.c and rebuild rddads.lib. Then you may start using AdsSet...() funcs.
- Code: Select all Expand view
//----------------------------------
//RCB 4/25/2011 10:16:24 AM
HB_FUNC( ADSSETBINARY )
{
UNSIGNED32 ulRetVal;
ADSAREAP pArea = hb_adsGetWorkAreaPointer();
ulRetVal = AdsSetBinary( pArea->hStatement,
(char*) hb_parc( 1 ),
(hb_pcount() > 2 && hb_parni( 3 ) == 1) ? ADS_BINARY : ADS_IMAGE,
hb_parclen( 2 ), //ulTotalLength
0,//ulOffset
(char*) hb_parc( 2 ),
hb_parclen( 2 ) );
hb_retl( ulRetVal == AE_SUCCESS );
}
//----------------------------------
//RCB 4/25/2011 10:16:24 AM
HB_FUNC( ADSSETSTRING )
{
UNSIGNED32 ulRetVal;
ADSAREAP pArea = hb_adsGetWorkAreaPointer();
ulRetVal = AdsSetString( pArea->hStatement,
(char*) hb_parc(1),
(char*) hb_parc(2),
hb_parclen(2) );
hb_retl( ulRetVal == AE_SUCCESS );
}
//----------------------------------
//RCB 4/25/2011 10:16:24 AM
HB_FUNC( ADSSETDATE )
{
UNSIGNED32 ulRetVal;
ADSAREAP pArea = hb_adsGetWorkAreaPointer();
ulRetVal = AdsSetDate( pArea->hStatement,
(char*) hb_parc(1),
(char*) hb_parc(2),
hb_parclen(2) );
hb_retl( ulRetVal == AE_SUCCESS );
}
//----------------------------------
//RCB 4/25/2011 10:16:24 AM
HB_FUNC( ADSSETLONG )
{
UNSIGNED32 ulRetVal;
ADSAREAP pArea = hb_adsGetWorkAreaPointer();
ulRetVal = AdsSetLong( pArea->hStatement,
(char*) hb_parc(1),
hb_parnl(2));
hb_retl( ulRetVal == AE_SUCCESS );
}
//----------------------------------
//RCB 4/25/2011 10:16:24 AM
HB_FUNC( ADSSETDOUBLE )
{
UNSIGNED32 ulRetVal;
ADSAREAP pArea = hb_adsGetWorkAreaPointer();
ulRetVal = AdsSetDouble( pArea->hStatement,
(char*) hb_parc(1),
hb_parnd(2));
hb_retl( ulRetVal == AE_SUCCESS );
}
//----------------------------------
//RCB 4/25/2011 10:16:24 AM
HB_FUNC( ADSSETLOGICAL )
{
UNSIGNED32 ulRetVal;
ADSAREAP pArea = hb_adsGetWorkAreaPointer();
ulRetVal = AdsSetLogical( pArea->hStatement,(char*) hb_parc(1), hb_parl(2));
hb_retl( ulRetVal == AE_SUCCESS );
}
//RCB
HB_FUNC( ADSSETNULL )
{
UNSIGNED32 ulRetVal;
ADSAREAP pArea = hb_adsGetWorkAreaPointer();
ulRetVal = AdsSetNull( (hb_parnl(1)==0) ? pArea->hOrdCurrent : hb_parnl(1),(char*) hb_parc(2));
hb_retl( ulRetVal == AE_SUCCESS );
}
And just as a reminder to FWH community and to keep this thread focused; xBrowse is grossly eating up resources like a pig anytime you show images on it. It is easy to reproduce the problem using Marcelos's posted sample on this same thread. Is there an outlook on this problem? Anyone working on it?
Please help;
Reinaldo.