Hi, kudlay:
The problem is that once we detect the field type is BLOB, we can not directly assign the field value to a string object, or else some bytes might be trimmed or ignored.
A solution is to get the field value into a _VARIANT type variable and then put the value into an Origin vector object. The following is the sample code to get the field value.
Do remmeber to include <variant.h> and <VariantTypes.h> as the compile the code.
#include <Origin.h>
////////////////////////////////////////////////////////////////////////////////////
#include <variant.h>
#include <VariantTypes.h>
//#pragma labtalk(0) // to disable OC functions for LT calling.
////////////////////////////////////////////////////////////////////////////////////
// Include your own header files here.
////////////////////////////////////////////////////////////////////////////////////
// Start your functions here.
#define DB_SETUP_STR "Provider=MSDASQL.1;Password="";User ID=Admin;Data Source=PD0;Extended Properties="
#define DB_FILE_FULLPATH "<Your Full Path>\DataSet1.1.db"
#define TABLE_NAME "PINGVELOCITIES"
#define DB_EXTENDED_1 "DSN=PD0;Database="
#define DB_EXTENDED_2 ";StepAPI=0;SyncPragma=;NoTXN=0;Timeout=1000;ShortNames=0;LongNames=0;NoCreat=0;NoWCHAR=0;LoadExt="
BOOL LoadSQLite()
{
Worksheet wks;
wks.Create("new");
Object ocrs;
ocrs = CreateObject("ADODB.Recordset");
if( !ocrs )
return FALSE;
ocrs.CursorLocation = 3;
string strConn = DB_SETUP_STR + "\"" + DB_EXTENDED_1 + DB_FILE_FULLPATH + DB_EXTENDED_2 + "\"" + ";"; //user code
ocrs.open("select * from " + TABLE_NAME + ";", strConn, 1, 3);
ocrs.MoveFirst();
int nRowIndex = 0;
Object ocfield;
int ct = 0;
while( !ocrs.eof )
{
if( nRowIndex > ocrs.RecordCount )
break;
for(int ii = 0; ii < ocrs.fields.Count; ii++)
{
ocfield = ocrs.fields(ii);
int nFieldType = ocfield.Type;
string strValue, strCell;
strValue = "";
char t;
if(nFieldType == 128)
{ // bin type
ct++;
if(ct >= 65){ // data starts on row 65 in this example db
// should be
//"02007E003C00F8FF1E00470051000100060038004E00FDFFF8FF44005400FFFFD3FF6D005600D4FFB8FF98007400DAFFBEFF94007C00EBFFC9FFC90078000A00FAFF92006D00E2FF2B0017017200B3FFFFFF4B016400BEFF090059016F00A0FF3400A8014F0090FF21008D014C0079FF150072014E0055FF32009001390075FFE3FF94013E0064FFFDFF5C013F0098FFC4FF04014E009BFFC1FF0A013500F4FF
///OrigiinLab 11/19/2009 BETTER_HANDLE_FOR_BLOB_DATA
//if( ocfield.Value != NULL ){
// strValue = (string)ocfield.Value;
//}
//for(int i = 0; i < 160; i++)
//{
//t = strValue[i];
//}
_VARIANT var;
var = ocfield.Value;
ASSERT((VT_ARRAY | VT_UI1) == var.vt);
vector<BYTE> vby;
vby.Append(var); //now vby contains data like "02007E003C00F8FF1E00470051000100060038004E00FDFFF8FF44005400FFFFD3FF6D005600D4FFB8FF98007400DAFFBEFF94007C00EBFFC9FFC90078000A00FAFF92006D00E2FF2B0017017200B3FFFFFF4B016400BEFF090059016F00A0FF3400A8014F0090FF21008D014C0079FF150072014E0055FF32009001390075FFE3FF94013E0064FFFDFF5C013F0098FFC4FF04014E009BFFC1FF0A013500F4FF
//you can see in variable window in Code Builder, vby = {2, 0, 126, 0, 60, 0, ..., 244, 255}
//and then you can decide what to do with this buffer, like just output the content below:
int nBytes = vby.GetSize();
for ( int ii = 0; ii < nBytes; ii++ )
{
printf("The vby[%d] = 0x%02X\n", ii, vby[ii]);
}
///end BETTER_HANDLE_FOR_BLOB_DATA
}
}
}
ocrs.MoveNext();
nRowIndex++;
if( ocrs.eof )
break;
}
return TRUE;
}