Hi,
I am encountering an issue trying to use NOT NULL text database fields.
I realise I could work around this by setting "noNullUpdates=true" and "omitNullDefaultsOnAdd=true" on my datasource but I do have some fields that genuinely sometimes need to be set to null.
If "omitNullDefaultsOnAdd=true" could be set on the DataSourceField level it would be acceptable for my "not null DEFAULT ''" text database fields.
But it would be even better if either of the lines below actually stopped the text field from ever being set to null:
In order to create the problem you have to leave the "description" field blank but either tab through the field or click onto the field then click off the field without entering any text in it.
Also "form1.editNewRecord();" has to be run first, though this could be a user clicking a "New Record" button after the first record has saved successfully.
Then as an example set of data it will send through something like:
And get an error back from the server like:
data:"integrity constraint violation: NOT NULL check constraint; SYS_CT_10411 table: SUPPLYITEM column: DESCRIPTION",
To set up the database ready to fail.. the following SQL commands need to be run:
Below is a testcase based on "built-in-ds":
SmartClient Version: v10.1p_2016-02-26/PowerEdition Deployment (built 2016-02-26) / Google Chrome OS X Version 48.0.2564.116 (64-bit)
I am encountering an issue trying to use NOT NULL text database fields.
I realise I could work around this by setting "noNullUpdates=true" and "omitNullDefaultsOnAdd=true" on my datasource but I do have some fields that genuinely sometimes need to be set to null.
If "omitNullDefaultsOnAdd=true" could be set on the DataSourceField level it would be acceptable for my "not null DEFAULT ''" text database fields.
But it would be even better if either of the lines below actually stopped the text field from ever being set to null:
Code:
txtDescription.setDefaultValue(""); txtDescription.setAttribute("emptyStringValue", "");
In order to create the problem you have to leave the "description" field blank but either tab through the field or click onto the field then click off the field without entering any text in it.
Also "form1.editNewRecord();" has to be run first, though this could be a user clicking a "New Record" button after the first record has saved successfully.
Then as an example set of data it will send through something like:
Code:
data:{ description:null, itemID:"1", itemName:"A", SKU:"B", unitCost:"1", category:"C" },
data:"integrity constraint violation: NOT NULL check constraint; SYS_CT_10411 table: SUPPLYITEM column: DESCRIPTION",
To set up the database ready to fail.. the following SQL commands need to be run:
Code:
DELETE FROM supplyitem WHERE description IS NULL; ALTER TABLE supplyitem ALTER COLUMN description SET NOT NULL; ALTER TABLE supplyitem ALTER COLUMN description SET DEFAULT '';
Below is a testcase based on "built-in-ds":
SmartClient Version: v10.1p_2016-02-26/PowerEdition Deployment (built 2016-02-26) / Google Chrome OS X Version 48.0.2564.116 (64-bit)
Code:
package com.smartgwt.sample.client; import com.google.gwt.core.client.EntryPoint; import com.smartgwt.client.core.KeyIdentifier; import com.smartgwt.client.data.DataSource; import com.smartgwt.client.util.Page; import com.smartgwt.client.util.PageKeyHandler; import com.smartgwt.client.util.SC; import com.smartgwt.client.widgets.IButton; import com.smartgwt.client.widgets.events.ClickEvent; import com.smartgwt.client.widgets.events.ClickHandler; import com.smartgwt.client.widgets.form.DynamicForm; import com.smartgwt.client.widgets.form.fields.TextItem; import com.smartgwt.client.widgets.layout.HLayout; import com.smartgwt.client.widgets.layout.VStack; /** * Entry point classes define <code>onModuleLoad()</code>. */ public class BuiltInDS implements EntryPoint { /** * This is the entry point method. */ @Override public void onModuleLoad() { KeyIdentifier debugKey = new KeyIdentifier(); debugKey.setCtrlKey(true); debugKey.setKeyName("D"); Page.registerKey(debugKey, new PageKeyHandler() { @Override public void execute(String keyName) { SC.showConsole(); } }); DataSource ds = DataSource.get("supplyItem"); VStack vStack = new VStack(); vStack.setLeft(175); vStack.setTop(75); vStack.setWidth("70%"); vStack.setMembersMargin(20); final DynamicForm form1 = new DynamicForm(); form1.setNumCols(6); form1.setAutoFocus(false); form1.setDataSource(ds); vStack.addMember(form1); TextItem txtItem1 = new TextItem("itemID", "itemID"); TextItem txtItem2 = new TextItem("itemName", "itemName"); TextItem txtItem3 = new TextItem("SKU", "SKU"); TextItem txtItem4 = new TextItem("unitCost", "unitCost"); TextItem txtItem5 = new TextItem("category", "category"); final TextItem txtDescription = new TextItem("description", "Description"); txtDescription.setDefaultValue(""); txtDescription.setValue(""); txtDescription.setAttribute("emptyStringValue", ""); form1.setFields(txtItem1, txtItem2, txtItem3, txtItem4, txtItem5, txtDescription); HLayout hLayout = new HLayout(10); hLayout.setMembersMargin(10); hLayout.setHeight(22); final IButton saveBtn = new IButton("Save"); saveBtn.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { form1.saveData(); } }); hLayout.addMember(saveBtn); IButton newBtn = new IButton("New"); newBtn.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { form1.editNewRecord(); } }); hLayout.addMember(newBtn); IButton clearBtn = new IButton("Check Value"); clearBtn.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { SC.say("txtCategoryName value="+ txtDescription.getValue()+ " -- "+ (txtDescription.getValue() == null)); } }); hLayout.addMember(clearBtn); vStack.addMember(hLayout); vStack.draw(); form1.editNewRecord(); } }
Comment