empty VBLOB data with correct length

Tomas Dikk t.dikk at se-dd.com
Fri Apr 29 15:47:02 CDT 2005


hi everybody, i hope somebody could help me on this problem.
i tried really for a long time and wasn't able to solve the problem.
i'm programming in java and using valentina 1.1.

in short, i store some byte[] to a blob field, and then read
it out again, and i check the length of the read out data which
is what i stored, but when i read individual bytes, they are all
zero. i made an example which you could check out:

it consists of 3 classes, App for testing, Table and DB for the DB/data

here is the code (it is a simple example to reproduce the behavior)

################## APP.JAVA #######################

package blobtest;
import com.paradigmasoft.valentina.vjdk.*;

public class App {

	public static void main(String[] args) {
		try {
			// open
			VJDK.init(4 * 1024 * 1024, "", "");
			VJDK.setDebugLevel(2);
			db = new DB();
			
			// do some operations
			Table t = db.get_table();
			
			byte[] ba = new byte[2]; // make a byte buffer
			ba[0] = 1;
			ba[1] = 2;
			t.setBlank(); // clear temp record
			t.field_blob.setBLOBLength(2); // set length of blob data
			t.field_blob.deleteBLOBData(); // delete blob data of buffer record (not really necessary)
			t.field_blob.writeBLOBData(ba, ba.length, 0); // (buffer, buffer length, from where)
			t.addRecord(); // store record in db

// FIRST POSSIBILITY TO READ OUT THE DATA (which does not seem to work)

			t.firstRecord(); // go to first record of this table
			VBLOB blob = (VBLOB)t.getField("blob"); // get field, cast it to vblob
			byte[] blob_data = blob.readBLOBData(0, blob.getDataSize()); // read out data from this field
			System.out.println("App:: main:		1. record blob length: " + blob.getDataSize() + " bytes");
			System.out.println("App:: main:		1. record blob isnull: " + blob.isNull());
			System.out.println("App:: main:		blob data [0] = " + blob_data[0]);
			System.out.println("App:: main:		blob data [1] = " + blob_data[1]);

// 2. POSSIBILITY TO READ OUT BLOB DATA (which doesn't work either)
			new VCursor(db);
			VCursor c = db.sqlSelect("SELECT * FROM table"); // select all records..
			c.firstRecord(); // go to first record of this cursor
			VBLOB blob = c.getBLOBField("blob"); // read out blob field
			byte[] blob_data = blob.readBLOBData(0, blob.getDataSize()); // read data from this field
			System.out.println("App:: main:		1. record blob length: " + blob.getDataSize() + " bytes");
			System.out.println("App:: main:		1. record blob isnull: " + blob.isNull());
			System.out.println("App:: main:		blob data [0] = " + blob_data[0]);
			System.out.println("App:: main:		blob data [1] = " + blob_data[1]);

			// close
			db.close();
			db.shutdown();
			System.out.println("App::main:		execution without any exception");
		}
		catch (VException ve) {
			System.out.println("# VException");
			System.out.println("# ErrorCode: " + ve.getErrorCode() + ", ErrorMsg: " + ve.getErrorString());
		}
	}
	
	private static DB db;
}

and here the classes for the db and table which i used:

################## DB.JAVA #######################

package blobtest;
mport com.paradigmasoft.valentina.vjdk.*;

public class DB extends VDataBase {

	public DB() throws VException {
		table = new Table();
		this.open("db.vdb"); // (name)
		System.out.println("DB::db:			instantiation successful");
	}
	
	public Table get_table() {
		return table;
	}
	
	public void shutdown() throws VException {
		VJDK.shutdown();
	}
	
	private Table table;
	
}

################## TABLE.JAVA #######################

package blobtest;
import com.paradigmasoft.valentina.vjdk.*;

public class Table extends VBaseObject {

	public Table() throws VException {
		super("table"); // (name)
		
		// set fields
		field_blob = new VBLOB("blob", 512); // (name, segment size)
	}

	public VBLOB field_blob; // must be public such that i can add records from app.java code (to have simpler testing)
	
}



the output which is generated is

DB::db:			instantiation successful
App:: main:		1. record blob length: 2 bytes
App:: main:		1. record blob isnull: false
App:: main:		blob data [0] = 0
App:: main:		blob data [1] = 0
App::main:		execution without any exception

so storing seems ok (also checked the values with vstudio) but reading out gives
only a byte[] with the correct length (2) but with only 0 in it..

can anybody explain this behavior to me? it seems really strange.. what am i missing?

thanks alot for reading this, and thanks for your time

greetings,

t


More information about the Valentina mailing list