Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 7 of 7 total
Thread HowTo AlterTable in v4.29?
Wed, Oct 13 2010 11:28 AMPermanent Link

Gene Abel

Hi,

I'm trying to have my application check the FieldDefs and IndexDefs each time it loads to determine if an update to the structure is needed and do an AlterTable only if the table structure is outdated.

Comparing the FieldDefs and IndexDefs is no problem.  However, if I insert a field in the definition, I get an exception during the AlterTable call.

I'm doing a table.FieldDefs.Update and comparing each field to a TFieldDefs that I'm creating with the current structure.  If the structure has changed, I want AlterTable to update the table.

If I have an existing table like this:
'Field1', ftString
'Field2', ftInteger
'Field3', ftDateTime
'Field4', ftString

and my application is looking for:
'Field1', ftString
'NewField', ftString   // inserted FieldDef
'Field2', ftInteger
'Field3', ftDateTime
'Field4', ftString

The application throws an exception trying to alter the data.  Can anyone offer an example of how this can be done?  The documentation uses TFieldDefs.Insert to insert a field, but this won't do what I need because this check is made every time the application runs (therefore, it would try to insert the field every time).  I just need it to examine the structure and alter only if needed.

TIA
Wed, Oct 13 2010 7:27 PMPermanent Link

Gregory Sebastian

Hi Gene,
<<I just need it to examine the structure and alter only if needed.>>
You can also use the :

DBISAMTable1.UserMajorVersion;
DBISAMTable1.UserMinorVersion;

properties to safely check the version number without opening any unexpected
table stuctures. If the version number is lower than what the app is
expecting, I run my sql code to alter/ upgrade the tables then stamp the
UserMajorVersion with the current DB version number. After this is done, the
tables can then be opened safely.


--
Gregory Sebastian
EzySoft Developments
www.ezysoft-dev.com
Thu, Oct 14 2010 1:50 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Gene,

<< I'm doing a table.FieldDefs.Update and comparing each field to a
TFieldDefs that I'm creating with the current structure.  If the structure
has changed, I want AlterTable to update the table. >>

Could you post all of the code that you're using ?  It would help to know
exactly how you're creating the field defs for comparison, and how they are
applied before the AlterTable call.

Thanks,

--
Tim Young
Elevate Software
www.elevatesoft.com
Thu, Nov 4 2010 6:01 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Gene,

Are you working with Steve Harp on this ?  I replied to him a couple of
weeks ago via email with the information on how to avoid this issue with the
AlterTable calls.

--
Tim Young
Elevate Software
www.elevatesoft.com
Mon, Nov 22 2010 9:01 AMPermanent Link

Gene Abel

"Tim Young [Elevate Software]" wrote:

Gene,

Are you working with Steve Harp on this ?  I replied to him a couple of
weeks ago via email with the information on how to avoid this issue with the
AlterTable calls.

Yes.  Gene's name is on the account because he owns the company.  I'm Steve and the one actually using DBISAM.  Thanks to your help, I've been able to resolve everything except the TDateTime default thing.  If I add a TDateTime field to an existing table and specify a default value, the program barfs during the AlterTable when trying to apply the default to existing fields.  I understand that the default value has to be specified as a string but it fails regardless of what date format I try.

The error I'm getting is EConvertError with message "25 00:00:00" is not a valid integer value.  The code is doing a TFieldDefs.Insert(5, 6, 'dateField', ftDateTime, 0, true, '2010-10-25 00:00:00').  I've also tried converting the TDateTime value (a double) to a string.  I get the same error.

Thanks again,
Steve
Mon, Nov 22 2010 10:28 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Gene


Can you enter a default in DBSys? If so what do you get if you reverse engineer the code?

Roy Lambert
Mon, Nov 22 2010 3:17 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Steve,

<< The error I'm getting is EConvertError with message "25 00:00:00" is not
a valid integer value.  The code is doing a TFieldDefs.Insert(5, 6,
'dateField', ftDateTime, 0, true, '2010-10-25 00:00:00').  I've also tried
converting the TDateTime value (a double) to a string.  I get the same
error. >>

The issue is because of the order that the FieldDefs are specified, and
doesn't have anything to do with the actual default value definition.
What's happening is that DBISAM is ending up trying to convert a
non-date/time field into a date/time field, and of course, it is getting
conversion errors.

Did you get my last email to you regarding how to set up the field defs
properly for the alter ?

--
Tim Young
Elevate Software
www.elevatesoft.com
Image