Page 1 of 1

MariaDB RS AppendBlank (SOLVED)

Posted: Fri Sep 07, 2018 3:01 am
by fraxzi
Hi All,

1. I have a trigger and procedure to check data lenght/data validity of user input, this is working fine.
2. When user encodes data to oRs:field (under appendblank) and fires oRs:Save()... then trigger captures and send message about the insufficient field length..
3. then the oRs:fields are cleared or the oRs:Appendblank() was cancelled, then the user has to re-do the encoding..

How can I avoid not clearing oRs:fields during appendblank editing :?: :?:

any :idea: :?:

Re: MariaDB RS AppendBlank

Posted: Tue Sep 11, 2018 12:02 am
by fraxzi
anybody experienced this ?

:?:

Re: MariaDB RS AppendBlank

Posted: Tue Sep 11, 2018 3:08 pm
by nageswaragunupudi
Are you using appendblank() for inline appends in XBrowse ?

Re: MariaDB RS AppendBlank

Posted: Wed Sep 12, 2018 12:16 am
by fraxzi
Hi Rao,

I used the oRs:AppendBlank() so user can edit blank oRs:field.. then oRs:Save() when done.
xbrowse is not use here.

:?:

Re: MariaDB RS AppendBlank

Posted: Wed Sep 12, 2018 12:32 am
by nageswaragunupudi
We recommend not to edit directly oRs:Fields.
This is our recommendation when editing /appending records when not in XBrowse.

For editing current record: oRs:Edit()
For appending Record : oRs:Edit( .t. )

By default, this will display FWH default dialog. Obviously, you want to use a dialog of your own design.

Code: Select all

oRs:bEdit := { |oRec| MyEditDialog( oRec ) }
oRs:Edit()  // for editing current record
oRs:Edit( .t. ) // for appending new record
//
//
function MyEditDialog( oRec )
   local lNew := ( oRec:RecNo == 0 )

   DEFINE DIALOG ............
   @ r,c GET oRec:fieldname1 ... UPDATE
   @ r,c, GET oRec:fieldname2 .. UPDATE

   @ r,c BUTTON "Undo" ... WHEN oRec:Modified() ACTION ( oRec:Undo(), oDlg:Update() )
   @ r,c, BUTTON "Save" ............ WHEN oRec:Modified() ;
     ACTION ( oRec:Save(), oDlg:Update() )
   @ r,c BUTTON "Close" .... ACTION oDlg:End()
    ACTIVATE DIALOG oDlg CENTERED
return nil
 
Once you assign your dialog to oRs:bEdit, when you browse the recordset, you can call oBrw:EditSource( .t./ .f. ) with the same effect.

In a short while, I will give you a working example.

Re: MariaDB RS AppendBlank

Posted: Wed Sep 12, 2018 1:37 am
by fraxzi
Hi Rao,

I did a good dialog editing modeled after your good samples specially from 'MariaInv.Prg' ...
Let me share my working dialog designed and required by end-user:

Image
Image


This dialog derived from oBrw:bEdit := {|oRec| uPrjDetails(oRec)} and oBrw:bLDblClick := {|| oBrw:EditSource() } which is related to the 2nd screenshot above:

Image

Re: MariaDB RS AppendBlank

Posted: Wed Sep 12, 2018 3:10 am
by nageswaragunupudi
Excellently designed dialogs.

Now, instead of assigning your dialogs to oBrw:bEdit, you may assign to oRs:bEdit. oBrw:bEdit is inherited from oRs:bEdit by default. In this case you can use the same dialogs by calling oBrw:EditSource(.t./.f.) during browse and oRs:Edit(.t./.f.) when not browsing. We suggest not to edit oRs:Fields directly. This way you need never call oRs:appendblank(), which is primarily created for autoappend for inline editing in xbrowse.

Rowset object automatically takes care of data length and you need not do this check again at server-level.

You may also consider using stored procedures to handle data updates and inserts with data validation.

Primarily, you better use table design itself to implement as many integrity checks as possible. You are using MariaDB, which supports CHECK constraint which is not supported by MySql. (note: MySql does not raise error when CHECK constraint is specified but does not use it.)

Code: Select all

  ,age INT UNSIGNED CHECK ( age < 100 )
  ,_ ENUM ( 'Male', 'Female', 'Other', 'NotSpecified' )
 
Enum values are automatically shown with EditListBox in XBrowse and default edit dialogs.
User foreign key constraints and computed columns wherever appropriate.

Forcing upper/lower case:

Use COMMENT 'CASE:UPPER'
or COMMENT 'CASE:lower'
or COMMENT 'CASE:Proper'
while creating the table.
Rowset object forces the case specified while writing data.

Re: MariaDB RS AppendBlank

Posted: Wed Sep 12, 2018 3:35 am
by fraxzi
Hi Rao,

Well explained. I will keep this open for some time.. for a while, I will test based on your directions how to avoid the issue (fields getting cleared) when trigger/procedure fires up.
I will also check oRS:field => oRec:field while editing on screen.

Thanks much as always you are very helpful to MariaDB newbies like me.

:wink: :wink: :wink:

Re: MariaDB RS AppendBlank

Posted: Wed Sep 12, 2018 5:41 am
by fraxzi
Hi Rao,

I have one observation.. while testing.

Code: Select all

...
oRs:Append()
oRec := oRs:Record()
...

oRec:field := "wrong value"

oRec:Save()  //returns .T., no trigger error!? (there should be...)
oRS:Save()   //returns .F.
...
 
but with this (presumably correct)

Code: Select all

...
oRs:Append()
oRs:field := "wrong value"
oRS:Save()  //returns .F., triggers error. (of which user needs to correct.... But it clears all edited field back to blanks...)
...
 
:?:

Re: MariaDB RS AppendBlank

Posted: Wed Sep 12, 2018 6:35 am
by nageswaragunupudi
Yes, that is the expected behaviour.

I advised you to use
oRs:bEdit := <yourfunc>
and
then
oRs:Edit( .t. )

Please stick to this approach only for edits/appends.

Re: MariaDB RS AppendBlank

Posted: Wed Sep 12, 2018 7:56 am
by fraxzi
Hi Rao,

I did this:

Code: Select all

... oRs:Append()
... oRec := oRs:Record(.T.)
... oRec:field := "if wrong data entered, trigger fires up, else normal)"
... oRec:Save()
 
When there's error, trigger shows up AND IT DOES NOT clear the input fields so user can still continue.
i verified and validated the saved entries from database and all looks great!

SOLVED!

:wink: :wink: :wink:

Re: MariaDB RS AppendBlank (SOLVED)

Posted: Wed Sep 12, 2018 8:48 am
by nageswaragunupudi
That is ok.
Still please follow my advice.
Do not use oRs:Append(), etc. even if they work.

This should be your standard practice for editing always for all rowsets.

oRs:bEdit := { |oRec| yourdialog( oRec ) }

for edit oRs:Edit()
for append, oRs:Edit( .t. )

Please do not deviate from my advice.

Re: MariaDB RS AppendBlank (SOLVED)

Posted: Wed Sep 12, 2018 9:00 am
by fraxzi
Hi Rao,

Copy ... I will find a way to modify those entry/dialogs ... I will keep you posted.
Rest assured this is only temporary.

:wink: :wink: :wink: