DB2 record add problem


Author
Message
Keith Chisarik
Keith Chisarik
StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)
Group: StrataFrame Users
Posts: 939, Visits: 40K
OK I will look into that, any thoughts on my bigger problem, the use of auto-incrementing keys with a DB2 datasource?



Thanks.

Keith Chisarik
Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
also, why would BO.save commit my inserts/updates to the server, yet return FALSE?

You might expand on this one since the Save returns an enum value rather than a boolean (i.e. Successful, Failed, etc.)

Keith Chisarik
Keith Chisarik
StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)
Group: StrataFrame Users
Posts: 939, Visits: 40K
I went back to using non-incrementing keys so I could get some stuff done until you tell me what is wrong when using DB2 auto-incrementing keys.



Everything is working the way I want by manually updating a new primekey value in the SetDefaultValue method but I have some questions. we used to do this all the time in VFP but I don't see how it can work in a disconnected data model? If I am creating 5 records on Client A and 5 records on Client B since the data isn't committed to the server until the call to BO.save(), my primekey assignment will fall down since Client B will get the same "next primekey" value from the server until Client A commits their inserts. Hopefully this is a moot point since I really want to use good old server assigned keys but i thought it a vlaid question to ask.



Also, why would BO.save commit my inserts/updates to the server, yet return FALSE? That is happening to me now.






Keith Chisarik
Keith Chisarik
Keith Chisarik
StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)
Group: StrataFrame Users
Posts: 939, Visits: 40K
Also, I did remove the code from bo.SetDefaultValues.



I miss my SQL Server right now.



Thanks.

Keith Chisarik
Keith Chisarik
Keith Chisarik
StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)
Group: StrataFrame Users
Posts: 939, Visits: 40K
So.........



I have my DB2 table set to now use auto incrementing keys of type BIGINT.



I set the PrimaryKeyIsAutoIncremented property to TRUE on the BO.



I get the following error now:

ERROR [428C9] [IBM][AS] SQL0798N A value cannot be specified for column "PURCH_PK" which is defined as GENERATED ALWAYS. SQLSTATE=428C9



The field is defined as:

PURCH_PK BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 0, INCREMENT BY 1)



I tried adding the PURCH_PK field to the FieldsToExcludeFromInsert collection to no avail:

Cannot create INSERT command because the updating DataTable does not contain columns for all PrimaryKeyFields.



Any ideas why this isn't working? The primekey field does auto-increment if I add records manually using a query window.

Keith Chisarik
Keith Chisarik
Keith Chisarik
StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)
Group: StrataFrame Users
Posts: 939, Visits: 40K
Just for anyone that might read this later, DB2 does fully support auto-increment fields, our RPG programmer just doesn't use them so he didn't know they existed.

Keith Chisarik
Keith Chisarik
Keith Chisarik
StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)
Group: StrataFrame Users
Posts: 939, Visits: 40K
gotcha

Keith Chisarik
Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
So then would the process be to always set the primekey field to a default, and then make sure to update it with the "real" primekey before calling save?

Well, this is kindof a trick question.  You must have the initialization of the properties turned off for the BO, otherwise this would have at least had a "0" in it when created.  So in this case, you will have to assign a value or manage the NULL value.  In this particular case, I think that I would go ahead and use a NextID table, like you did in VFP, and assign the "real" PK value in the SetDefaultValues of the BO.

Keith Chisarik
Keith Chisarik
StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)
Group: StrataFrame Users
Posts: 939, Visits: 40K
That was it, I didn't set the default value for the primekey field. Your the man.



So then would the process be to always set the primekey field to a default, and then make sure to update it with the "real" primekey before calling save?



I was going to use my old VFP way of tracking primekeys that we used before VFP supported auto increment fields, have a table that has a record for each table in the database that contains a field for the next valid primekey.



I cant believe DB2 doesn't have auto increment fields in 2007.....



Thanks again for your help. So simple once you know......




Keith Chisarik
Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
Well, this is happening in the Get of the property so this indicates that something is trying to pull a value.  So two things, look at and/or post the call stack so that we can see where it is coming from.  Also, have you initialized the field in the SetDefaultValues event?  You mentioned that this is happening when you call the Add(), so at this point, the server has never been queried.  So more than likely you are not allowing the fields to be initialized and have not set a value in the SetDefaultValues before something is trying to query the property.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search