pervasivepervasive-sqlbtrieve

How is the record length affected in PSQL v9 when creating tables?


I'm using Btrieve and the Pervasive SQL Control Center to create a table. The table has 3 columns: char 20, char 20, & char 50. The first column is the primary key. When I inserted a record through code the first character of the second column was always missing. I assumed because the first column was overwriting it. While investigating why I loaded up the File Information Editor. The File Specification lists the Record Length as 92. This doesn't make sense to me because I clearly defined the table as having record lengths of 90.

I was also getting error 22 which is indicative of differing record length of my buffer in code and the actual table record length.

To fix the missing first character in the second column, I changed my buffer in code so the first column was 21 chars in length. I also changed the 3rd column to be 51 to fix the error 22.

How does the record length get set to 92 in my example when I clearly defined the record lengths as 90 when creating the table?


Solution

  • What you are most likely seeing is an artifact of the "null" handling in Btrieve / Pervasive.
    When you create a file using Btrieve, you layout the record exactly byte-by-byte. When "True Null" support was added to the Pervasive engine, any column created as nullable (the default) has an extra byte prefixing the field in the Btrieve file. This allows the engine to know if the field is null or an empty string.
    Because your table had three columns, there should have been three extra bytes but because one of the columns was Primary Key, it does not all null so you only got two extra bytes.
    In your case, if you had an existing Btrieve file and created the SQL definition, those extra fields wouldn't be there in some cases.
    You have two options: