The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 SQLite blob data type and ReadRecordset.

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
dkudlay Posted - 11/18/2009 : 2:07:41 PM
I have an SQLite db. One of the fields is a blob type containing many values. If I load the db using the same ODBC driver using a .NET library lets say, I get a string with all values for my blob cell. If I use ReadRecordset and load the db into a worksheet, only the very first value of the blob is preserved in a cell. Why isn't the whole blob is read? Is there no support for that data type?
7   L A T E S T    R E P L I E S    (Newest First)
Sophy Posted - 11/20/2009 : 02:33:07 AM
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;
} 
cpyang Posted - 11/19/2009 : 4:47:26 PM
What I meant was that you can use Convert(VarChar(255), mydb.field) in your query string, but I now see you do not have a detailed query, but just "Select * From". So best will be for us to look at your db and see what we can do.

Please send the 1Mb db to me at

cp@originlab.com

Thanks.

CP
dkudlay Posted - 11/19/2009 : 1:27:49 PM
I can post the code meanwhile, let's see if it'll format right:

#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 + "\"" + ";";

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
if( ocfield.Value != NULL ){
strValue = (string)ocfield.Value;
}
for(int i = 0; i < 160; i++)
{
t = strValue[i];
}
}
}

}
ocrs.MoveNext();
nRowIndex++;
if( ocrs.eof ) break;
}
return TRUE;
}
dkudlay Posted - 11/19/2009 : 12:58:42 PM
Convert() was not found by the Origin Code Builder.

If you would like a a sample DB (1mb size). Please e-mail me dkudlay@teledyne.com.
ML Posted - 11/18/2009 : 11:26:16 PM
Hi dkudlay,

We'll try to reproduce your problem. Meanwhile, would you be able to create a small sample database - a couple of records and fields (plus the query used) - which shows the problem?

Thanks.

ML
cpyang Posted - 11/18/2009 : 11:20:13 PM
If you know the content of the field is actually text, then you can use

Convert(VarChar(255), mydb.field)

assuming mydb.field is the field you want to import.

CP
dkudlay Posted - 11/18/2009 : 8:23:49 PM
Did some more investigation.

the database field in question is ocfield.Type == DBTYPE_BYTES == 128

I can get the string of data now via ocfield.Value.

However, all the binary values > 128 are cropped to a '?' == 63. So my data is lost.

Anyone know of a setting to flip to read the full 255 values?

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000