dbTalk Databases Forums  

Variabel length database (BLOB)

comp.databases.btrieve comp.databases.btrieve


Discuss Variabel length database (BLOB) in the comp.databases.btrieve forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
GTi
 
Posts: n/a

Default Variabel length database (BLOB) - 08-08-2003 , 03:48 AM






I want to store files in a database, I have absolute no clue how I do this.

I have a structure like this:
typedef struct DB_DOCUMENTBASE
{
DWORD NDX;
char HEADING[100+1];
DWORD DATALEN;
char *DATA; // Actual file
} DOCUMENTBASE;
DOCUMENTBASE db;

I create the file with:
FileBuf.RecLen = 255;
FileBuf.PageSize = 1024;
FileBuf.FILEFLAGS = VAR_RECS;
........

So when I want to insert a new record I alloc memory (calloc)
db.DATALEN = filelength;
db.DATA = calloc(db.DATALEN,sizeof(char));
copy the file into the db.DATA

But then I have no clue how I insert the data into btrieve.
How do I tell the length of the data to btrieve?

And how do I receive the data again.
Can I use G_GET_EQUAL, B_GET_FIRST as usual
And if the buffer is to low I receive status 22. But is the
data copied into my buffer?
Example:
I want to step thru the hole database without receiving the file.
Can I allocate a buffer large enough to hold the first part and
handle status 22 like status 0?

Regards,
GTi



Reply With Quote
  #2  
Old   
Mike Hovis
 
Posts: n/a

Default Re: Variabel length database (BLOB) - 08-08-2003 , 11:07 AM






You must use the Get Direct / Get Chunk operation, each time the portion is
greater than 64k you will receive stat 22, which is not a failure. Once you
reach the end of the record, you will get a stat 0. Your app must keep
track of the offset and length of each 'chunk' of data.

In answer to your last question, status 22 is not a failure, it just means
that the entire record could not fit in your buffer, so yes - treat it as a
stat 0.

Best Regards,
Michael Hovis
Pervasive Software

"GTi" <nospam (AT) online (DOT) com> wrote

Quote:
I want to store files in a database, I have absolute no clue how I do
this.

I have a structure like this:
typedef struct DB_DOCUMENTBASE
{
DWORD NDX;
char HEADING[100+1];
DWORD DATALEN;
char *DATA; // Actual file
} DOCUMENTBASE;
DOCUMENTBASE db;

I create the file with:
FileBuf.RecLen = 255;
FileBuf.PageSize = 1024;
FileBuf.FILEFLAGS = VAR_RECS;
.......

So when I want to insert a new record I alloc memory (calloc)
db.DATALEN = filelength;
db.DATA = calloc(db.DATALEN,sizeof(char));
copy the file into the db.DATA

But then I have no clue how I insert the data into btrieve.
How do I tell the length of the data to btrieve?

And how do I receive the data again.
Can I use G_GET_EQUAL, B_GET_FIRST as usual
And if the buffer is to low I receive status 22. But is the
data copied into my buffer?
Example:
I want to step thru the hole database without receiving the file.
Can I allocate a buffer large enough to hold the first part and
handle status 22 like status 0?

Regards,
GTi





Reply With Quote
  #3  
Old   
GTi
 
Posts: n/a

Default Re: Variabel length database (BLOB) - 08-08-2003 , 02:54 PM



Mike,
Thank you for the answer, but I still don't get it.

Is there any c/c++ example available?

Now I'm really confused.
Must I read the database just like a ordinary file.
Always remember the offset byte for byte from the
beginning of the file.
Is searching based on a KEY not possible?

Must I read the database from the beginning and read
through all records (with "files") until I reach the key?
I must be misapprehension you answer.

Please explain me how this is done.
In my example:
NDX and HEADING is a key:

GTi

"Mike Hovis" <mhovisNOSPAM (AT) pervasive (DOT) com> wrote

Quote:
You must use the Get Direct / Get Chunk operation, each time the portion
is
greater than 64k you will receive stat 22, which is not a failure. Once
you
reach the end of the record, you will get a stat 0. Your app must keep
track of the offset and length of each 'chunk' of data.

In answer to your last question, status 22 is not a failure, it just means
that the entire record could not fit in your buffer, so yes - treat it as
a
stat 0.

Best Regards,
Michael Hovis
Pervasive Software

"GTi" <nospam (AT) online (DOT) com> wrote in message
news:RtJYa.21753$KF1.309204 (AT) amstwist00 (DOT) ..
I want to store files in a database, I have absolute no clue how I do
this.

I have a structure like this:
typedef struct DB_DOCUMENTBASE
{
DWORD NDX;
char HEADING[100+1];
DWORD DATALEN;
char *DATA; // Actual file
} DOCUMENTBASE;
DOCUMENTBASE db;

I create the file with:
FileBuf.RecLen = 255;
FileBuf.PageSize = 1024;
FileBuf.FILEFLAGS = VAR_RECS;
.......

So when I want to insert a new record I alloc memory (calloc)
db.DATALEN = filelength;
db.DATA = calloc(db.DATALEN,sizeof(char));
copy the file into the db.DATA

But then I have no clue how I insert the data into btrieve.
How do I tell the length of the data to btrieve?

And how do I receive the data again.
Can I use G_GET_EQUAL, B_GET_FIRST as usual
And if the buffer is to low I receive status 22. But is the
data copied into my buffer?
Example:
I want to step thru the hole database without receiving the file.
Can I allocate a buffer large enough to hold the first part and
handle status 22 like status 0?

Regards,
GTi







Reply With Quote
  #4  
Old   
Gordon
 
Posts: n/a

Default Re: Variabel length database (BLOB) - 08-11-2003 , 03:34 AM



Just walk your records as usual with GET or STEP operations. When
you've found the record you're looking for, based on your key, then
the fun starts:

Start with a GET POSITION (22) to retrieve the 4 byte record address
that you'll need to feed to GET DIRECT (23). GET DIRECT does not
change positioning. Just keep calling it in chunkmode with subsequent
offsets inside your blob until you've retrieved every part. You'll
have to "glue" the parts together yourself in order to retrieve the
blob, which was what Mike was referring to when he said you'd need to
remember the offsets.

Sorry, got no example ready


On Fri, 8 Aug 2003 21:54:30 +0200, "GTi" <nospam (AT) online (DOT) com> wrote:

Quote:
Mike,
Thank you for the answer, but I still don't get it.

Is there any c/c++ example available?

Now I'm really confused.
Must I read the database just like a ordinary file.
Always remember the offset byte for byte from the
beginning of the file.
Is searching based on a KEY not possible?

Must I read the database from the beginning and read
through all records (with "files") until I reach the key?
I must be misapprehension you answer.

Please explain me how this is done.
In my example:
NDX and HEADING is a key:

GTi

"Mike Hovis" <mhovisNOSPAM (AT) pervasive (DOT) com> wrote in message
news:HUPYa.935$4B7.661 (AT) newssvr23 (DOT) news.prodigy.com...
You must use the Get Direct / Get Chunk operation, each time the portion
is
greater than 64k you will receive stat 22, which is not a failure. Once
you
reach the end of the record, you will get a stat 0. Your app must keep
track of the offset and length of each 'chunk' of data.

In answer to your last question, status 22 is not a failure, it just means
that the entire record could not fit in your buffer, so yes - treat it as
a
stat 0.

Best Regards,
Michael Hovis
Pervasive Software

"GTi" <nospam (AT) online (DOT) com> wrote in message
news:RtJYa.21753$KF1.309204 (AT) amstwist00 (DOT) ..
I want to store files in a database, I have absolute no clue how I do
this.

I have a structure like this:
typedef struct DB_DOCUMENTBASE
{
DWORD NDX;
char HEADING[100+1];
DWORD DATALEN;
char *DATA; // Actual file
} DOCUMENTBASE;
DOCUMENTBASE db;

I create the file with:
FileBuf.RecLen = 255;
FileBuf.PageSize = 1024;
FileBuf.FILEFLAGS = VAR_RECS;
.......

So when I want to insert a new record I alloc memory (calloc)
db.DATALEN = filelength;
db.DATA = calloc(db.DATALEN,sizeof(char));
copy the file into the db.DATA

But then I have no clue how I insert the data into btrieve.
How do I tell the length of the data to btrieve?

And how do I receive the data again.
Can I use G_GET_EQUAL, B_GET_FIRST as usual
And if the buffer is to low I receive status 22. But is the
data copied into my buffer?
Example:
I want to step thru the hole database without receiving the file.
Can I allocate a buffer large enough to hold the first part and
handle status 22 like status 0?

Regards,
GTi






Gordon Bos
Q-RY Solutions
+31-(0)15-2564035

http://www.q-ry.nl/


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.