Page 1 of 1

PostPosted: Sun Feb 20, 2005 12:30 pm
by Mikael
I'm trying to get the DBinfo function to return the number of fields in a particular record. The problem is that it returns the number of fields in the longest record instead. I'm using the first record in the db for testing with:

DBgetfield(recNum,0);//record # zero in this case
numFields=DBinfo(1,0);//numFields should equal 25
alert(numFields);//alerts 265 fields instead

Where am I going wrong with this? I can't see it for the life of me.
I've checked the db's properties and configuration and they seem fine-it being a string db with 214 records, the longest record containing 265 fields.

Thanks in advance,


PostPosted: Sun Feb 20, 2005 2:38 pm
by Mikael
I'm starting to get the idea that this function is supposed to return the largest number of fields in the db after all. What got me thinking it wasn't is a old test app I found with a test db containing only one record and three fields, which always returned the correct number of fields. Also this info in the docs made me think this function is record specific:

Field Count. <b>Returns the number of fields per record</b>. Field parameter unused. For HanDBase databases returns a count based on the last non-none field position.


PostPosted: Sun Feb 20, 2005 3:07 pm
by jstadolnik
All records for a given pilot-DB and HandBase have the same number of fields. So in your case each record does have 265 fields, even if they are null strings.

The reason why DBinfo(1,0) returns the the total number of fields (whether they be null strings or not), is so that you know how much memory to malloc. Should you happen to provide DBgetrec with an array that's too short, you'll likely get a crash.


The PToolboxLib guy.

PostPosted: Sun Feb 20, 2005 3:57 pm
by Mikael
Thanks Joe, for clearing that up.