dbTalk Databases Forums  

inserting record with amount field

comp.databases.btrieve comp.databases.btrieve


Discuss inserting record with amount field in the comp.databases.btrieve forum.



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

Default inserting record with amount field - 10-13-2005 , 08:13 PM






people, i have been developing on an existing POS system that uses
btrieve for the back-end, and have found it fairly easy to use. never
have i come across this problem before. when inserting a amount field,
(a dollar amount) the field seems to be formatting itself, or putting
in a default value nothing nearly what i have set it to.

firstly, btreive version = pervasive 2000, developing in VB6.

i have a table with a number of records, one is called 'amount'. the
amount is : string field * 8, i have made it double and still i get the
same problem. when i set the 'amonut' field to 150, then 20, then 5,
2.5, each time running a btrieve insert, when i look in the table, the
'amount' field equals 6.14868575759022, nothing to do with what i'm
inserting each time.

is there some default value it's inserting, if so, how do i check? or
is there something else. very hard for me to diagnose, any help would
be great.

thanks, peter.


Reply With Quote
  #2  
Old   
stromberg45
 
Posts: n/a

Default Re: inserting record with amount field - 10-17-2005 , 08:09 AM






hasn't anyone seen this? do you need any more information, please just
let me know you are reading this, i cannot seem to sort this out.
thanks.


Reply With Quote
  #3  
Old   
Brad Kunkel
 
Posts: n/a

Default Re: inserting record with amount field - 10-17-2005 , 01:02 PM



"stromberg45" <peter.thericgroup (AT) gmail (DOT) com> wrote

Quote:
hasn't anyone seen this? do you need any more information, please just
let me know you are reading this, i cannot seem to sort this out.
thanks.

Just a guess but maybe it's an alignment problem. Try making the amount
field a string and inserting "abcdefgh" then read it back as a string and
see if any of the letters are cut off.

HTH,
Brad Kunkel
Integrated Business, Inc.





Reply With Quote
  #4  
Old   
Bill Bach
 
Posts: n/a

Default Re: inserting record with amount field - 10-17-2005 , 09:27 PM



The Btrieve interface simply accepts a block of bytes from the
application. IN this case, you are probably getting a mis-aligned
block of bytes. Microsoft, in their attempts to make life "easier" for
developers, removed the ability to byte-align the data structures for
numeric fields. This forces numeric elements to align on an even
4-byte boundary. If you have bad alignment, you'll get all sorts of
bad data as the data gets shifted around.

To illustrate this, check out this pseudocode example:

Structure
TextField CHAR(10) Bytes 0-9
Amount DOUBLE Bytes 10-17
EndStructure

This is 18 bytes, right? WRONG! This is 20 Bytes! Microsoft decides
to "help" by changing the structure to this:

Structure
TextField CHAR(10) Bytes 0-9
HiddenFiller BYTE(2) Bytes 10-11
Amount DOUBLE Bytes 12-19
EndStructure

Therefore, when you write the data from VB, you are writing it to Bytes
12-19 in the structure. However, when you read the data from ODBC, you
are getting Bytes 10-17 instead, and the values are all messed up.


Since Btrieve takes the block of bytes you give it and simply stores
it, there is nothing that the database can do with the data you give
it. It is the purest form of "garbage in, garbage out".
Goldstar Software Inc.
Building on Btrieve(R) for the Future(SM)
Bill Bach
BillBach (AT) goldstarsoftware (DOT) com
http://www.goldstarsoftware.com
*** Chicago: Pervasive.SQL Service & Support - November, 2005 ***
*** Chicago: Pervasive DataExchange Class - November, 2005 ***

stromberg45 wrote:

Quote:
people, i have been developing on an existing POS system that uses
btrieve for the back-end, and have found it fairly easy to use. never
have i come across this problem before. when inserting a amount field,
(a dollar amount) the field seems to be formatting itself, or putting
in a default value nothing nearly what i have set it to.

firstly, btreive version = pervasive 2000, developing in VB6.

i have a table with a number of records, one is called 'amount'. the
amount is : string field * 8, i have made it double and still i get
the same problem. when i set the 'amonut' field to 150, then 20, then
5, 2.5, each time running a btrieve insert, when i look in the table,
the 'amount' field equals 6.14868575759022, nothing to do with what
i'm inserting each time.

is there some default value it's inserting, if so, how do i check? or
is there something else. very hard for me to diagnose, any help would
be great.

thanks, peter.


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.