Web Connection
Error wwBusinessObject.New()
Gravatar is a globally recognized avatar based on your email address. Error wwBusinessObject.New()
  Alejandro A Sosa
  All
  Mar 19, 2021 @ 01:44pm

I am excited. For the first time ever I am working on a webConnection website that has its data in SQL Server, and I am using wwBusinessObject class. Heck, this is the first time I am doing anything serious using SQL Server.

In any case, got this error when testing wwBusinessObject.New()

Connectivity error: [Microsoft][ODBC SQL Server Driver][SQL Server]There are more columns in the INSERT statement than values specified in the VALUES clause. The number of values in the VALUES clause must match the number of columns specified in the INSER

Presume sp_ww_NewId was doing the insert.

Any suggestions as to what may be the problem?

TIA,

Alex

Gravatar is a globally recognized avatar based on your email address. re: Error wwBusinessObject.New()
  Alejandro A Sosa
  Alejandro A Sosa
  Mar 20, 2021 @ 04:54am

The error seems to have occurred because Id is set as the primary key and also as identity key, so when wwBusinessObject.New() tried to create the primary key it caused a clash.

Instead, the call should be to wwBusinessObject.New(.T.) since there is no need to assign a newly generated key to a relationship that has not been saved to disk yet.

I naively thought that createnewid() might have some magic up its sleeve for these cases.

Alex

Gravatar is a globally recognized avatar based on your email address. re: Error wwBusinessObject.New()
  Rick Strahl
  Alejandro A Sosa
  Mar 20, 2021 @ 12:46pm

If keys are auto-generated you can't assign a value to them. So yes, you need to not have wwBusiness set a key. You can override the CreateNewId() method, but you basically need to set the insert exclusion field list (cSkipFieldsForUpdates).

wwBusinessObject::cSkipFieldsForUpdates

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Error wwBusinessObject.New()
  Rick Strahl
  Rick Strahl
  Mar 21, 2021 @ 02:19pm

FWIW, the proper way to do this is to override the CreateNewId() method so it doesn't do anything at all in your business object and set the cSkipFieldsForUpdates property:

DEFINE CLASS MyBus as wwBusinessObject

...

cSkipFieldsForUpdates = "Id"

FUNCTION CreateNewId()
RETURN 0

ENDDEFINE

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Error wwBusinessObject.New()
  Alejandro A Sosa
  Rick Strahl
  Mar 21, 2021 @ 04:42pm

Thank you.

I hadn't seen this part of WebConnection code. As usual, top notch. Wanted to mention that.

Alex

© 1996-2024