views:

111

answers:

2

OleDB always add one more digit to DBF numeric fields when we create them. A command like this: CREATE TABLE [file1.DBF] ( [MY_FIELD] NUMERIC(1,0) NULL) will create a field that can contains 2 digits (or one digit and a minus sign). What's funny is that I can ask for a length of zero like this NUMERIC(0,0) and it's going to create a field with a length of 1.

I couldn't find any documentation regarding this behavior.

Is it specific to the use of oleDB to create DBF or the same can happen with other DB?

Is the extra digit added by oleDB only to handle the minus sign?

Is this behavior consistent? I mean, can I just subtract one to the width when I create the table?

Edit: This question has pretty much been answered here: http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/af245580-8897-4608-8fa0-f00286d37324?prof=required

A: 

It might be as simple as zero-based interpretation vs one-based, but interesting find.

DRapp
+1  A: 

Looks like DRapp might be on to something.

CREATE TABLE [file1.DBF] ( [MY_FIELD] NUMERIC(1,0) NULL)

from FoxPro creates:

Structure for table:    FILE1.DBF
Number of data records: 0       
Date of last update:    08/24/10
Code Page:              1252    
Field  Field Name      Type                Width    Dec   Index   Collate Nulls
    1  MY_FIELD        Numeric                 1                            Yes
** Total **                                    3

Same SQL through OleDb creates:

Structure for table:    FILE1.DBF
Number of data records: 0       
Date of last update:    08/24/10
Code Page:              1252    
Field  Field Name      Type                Width    Dec   Index   Collate Nulls
    1  MY_FIELD        Numeric                 2                            Yes
** Total **                                    4

But, CREATE TABLE [file1.DBF] ( [MY_FIELD] NUMERIC(0,0) NULL) through OleDb creates:

Structure for table:    FILE1.DBF
Number of data records: 0       
Date of last update:    08/24/10
Code Page:              1252    
Field  Field Name      Type                Width    Dec   Index   Collate Nulls
    1  MY_FIELD        Numeric                 1                            Yes
** Total **                                    3

The same structure as from FoxPro. For whatever reason this occurs, it does point out that there is a difference in behavior between the FoxPro engine and the VFPOLEDB driver.

DaveB
I don't see how this can be zero-based vs one-based issue, beside some kind of bug in the implementation that would make use of an array for some manipulation. The number that we specify is a size, not an index. It would mean that it's interpreted as an index at some point.
Simon T.