Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Issue trying to use NOT NULL text database fields

    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:

    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"
        },
    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:

    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();
        }
    }






    #2
    Also for some further info, we did not used to have the same problem back in build:

    Version v10.0p_2014-11-23/PowerEdition Deployment (2014-11-23).

    Thank-you very much for any help you can offer.

    Comment


      #3
      Sorry for the slow response here - we're already working on this one, and we've solved it locally, we are just making sure the fix does not have any unintended consequences. Unfortunately in the midst of doing that, a developer's laptop got destroyed (soda incident) so there's been a small delay. Should be wrapped up this week.

      Comment


        #4
        Hi Isomorphic,

        Thank-you very much for the update .. really so glad to hear a fix is on the way... It took me far too long to get the test case together .. I tried several times .. I think the key was now that I must have left out the "new record" step before .. and so could never get a test case to show what was happening in my application... So only having to wait a few more days will be no trouble at all.

        I was also on the same boat a few years ago .... trying to mix soda and a laptop, so I know how bad that feels for the poor guy. :-/

        Thanks again for the update.

        Mark

        Comment


          #5
          Ok, this is fixed for builds dated March 11 and later - now, if you specify an emptyStringValue, it will not be reset to null as a result of clearValue() being called.

          Comment


            #6
            Hi,

            Did the fix make it into "SmartClient Version: v10.1p_2016-03-11/PowerEdition Deployment (built 2016-03-11)" ?

            I have have just rebuild the test case above with the new version and it does not seem to behave any differently.. it is still setting the description to "null" if you click on and and then back off the field.

            Thanks,

            Mark

            Comment


              #7
              Apologies - we fixed this bug in TextAreaItem, which is the default field-type used for the "description" field, since it has length="2000".

              The same issue was present in TextItem, and we've now fixed that logic also - you can test that out in builds dated March 13 and later.

              If you wish, you can test that the fix will work for you by testing the one we already made - just change the "description" field in your sample ta a TextAreaItem, rather than a TextItem, and you should see things work as you expect.

              Comment


                #8
                Thanks for fixing it, I am looking forward to trying it out .... though is there some kind of issue with the nightly build process ? .. it does not seem to have built a release for the 12th, 13th or 14th ? Thanks

                Comment


                  #9
                  Please ignore the above post .. I see a build for the 14th has been generated.. and also from my initial testing it seems to have fixed my issue. :-) Thank-you very much guys.

                  Comment

                  Working...
                  X