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
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 SQLite blob data type and ReadRecordset.
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

dkudlay

USA
22 Posts

Posted - 11/18/2009 :  2:07:41 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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?

dkudlay

USA
22 Posts

Posted - 11/18/2009 :  8:23:49 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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?
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 11/18/2009 :  11:20:13 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

ML

USA
63 Posts

Posted - 11/18/2009 :  11:26:16 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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

Edited by - ML on 11/18/2009 11:27:07 PM
Go to Top of Page

dkudlay

USA
22 Posts

Posted - 11/19/2009 :  12:58:42 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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.
Go to Top of Page

dkudlay

USA
22 Posts

Posted - 11/19/2009 :  1:27:49 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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;
}
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 11/19/2009 :  4:47:26 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

Sophy

China
Posts

Posted - 11/20/2009 :  02:33:07 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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;
} 
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000