MariaDB RS AppendBlank (SOLVED)

Post Reply
User avatar
fraxzi
Posts: 811
Joined: Tue May 06, 2008 4:28 am
Location: Philippines
Contact:

MariaDB RS AppendBlank (SOLVED)

Post 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: :?:
Last edited by fraxzi on Wed Sep 12, 2018 7:56 am, edited 1 time in total.
Kind Regards,
Frances

Fivewin for xHarbour v18.07
xHarbour v1.2.3.x
BCC 7.3 + PellesC8 ( Resource Compiler only)
ADS 10.1 / MariaDB
Crystal Reports 8.5/9.23 DE
xMate v1.15
User avatar
fraxzi
Posts: 811
Joined: Tue May 06, 2008 4:28 am
Location: Philippines
Contact:

Re: MariaDB RS AppendBlank

Post by fraxzi »

anybody experienced this ?

:?:
Kind Regards,
Frances

Fivewin for xHarbour v18.07
xHarbour v1.2.3.x
BCC 7.3 + PellesC8 ( Resource Compiler only)
ADS 10.1 / MariaDB
Crystal Reports 8.5/9.23 DE
xMate v1.15
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: MariaDB RS AppendBlank

Post by nageswaragunupudi »

Are you using appendblank() for inline appends in XBrowse ?
Regards

G. N. Rao.
Hyderabad, India
User avatar
fraxzi
Posts: 811
Joined: Tue May 06, 2008 4:28 am
Location: Philippines
Contact:

Re: MariaDB RS AppendBlank

Post 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.

:?:
Kind Regards,
Frances

Fivewin for xHarbour v18.07
xHarbour v1.2.3.x
BCC 7.3 + PellesC8 ( Resource Compiler only)
ADS 10.1 / MariaDB
Crystal Reports 8.5/9.23 DE
xMate v1.15
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: MariaDB RS AppendBlank

Post 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.
Regards

G. N. Rao.
Hyderabad, India
User avatar
fraxzi
Posts: 811
Joined: Tue May 06, 2008 4:28 am
Location: Philippines
Contact:

Re: MariaDB RS AppendBlank

Post 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
Kind Regards,
Frances

Fivewin for xHarbour v18.07
xHarbour v1.2.3.x
BCC 7.3 + PellesC8 ( Resource Compiler only)
ADS 10.1 / MariaDB
Crystal Reports 8.5/9.23 DE
xMate v1.15
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: MariaDB RS AppendBlank

Post 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.
Regards

G. N. Rao.
Hyderabad, India
User avatar
fraxzi
Posts: 811
Joined: Tue May 06, 2008 4:28 am
Location: Philippines
Contact:

Re: MariaDB RS AppendBlank

Post 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:
Kind Regards,
Frances

Fivewin for xHarbour v18.07
xHarbour v1.2.3.x
BCC 7.3 + PellesC8 ( Resource Compiler only)
ADS 10.1 / MariaDB
Crystal Reports 8.5/9.23 DE
xMate v1.15
User avatar
fraxzi
Posts: 811
Joined: Tue May 06, 2008 4:28 am
Location: Philippines
Contact:

Re: MariaDB RS AppendBlank

Post 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...)
...
 
:?:
Kind Regards,
Frances

Fivewin for xHarbour v18.07
xHarbour v1.2.3.x
BCC 7.3 + PellesC8 ( Resource Compiler only)
ADS 10.1 / MariaDB
Crystal Reports 8.5/9.23 DE
xMate v1.15
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: MariaDB RS AppendBlank

Post 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.
Regards

G. N. Rao.
Hyderabad, India
User avatar
fraxzi
Posts: 811
Joined: Tue May 06, 2008 4:28 am
Location: Philippines
Contact:

Re: MariaDB RS AppendBlank

Post 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:
Last edited by fraxzi on Wed Sep 12, 2018 9:01 am, edited 1 time in total.
Kind Regards,
Frances

Fivewin for xHarbour v18.07
xHarbour v1.2.3.x
BCC 7.3 + PellesC8 ( Resource Compiler only)
ADS 10.1 / MariaDB
Crystal Reports 8.5/9.23 DE
xMate v1.15
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: MariaDB RS AppendBlank (SOLVED)

Post 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.
Regards

G. N. Rao.
Hyderabad, India
User avatar
fraxzi
Posts: 811
Joined: Tue May 06, 2008 4:28 am
Location: Philippines
Contact:

Re: MariaDB RS AppendBlank (SOLVED)

Post 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:
Kind Regards,
Frances

Fivewin for xHarbour v18.07
xHarbour v1.2.3.x
BCC 7.3 + PellesC8 ( Resource Compiler only)
ADS 10.1 / MariaDB
Crystal Reports 8.5/9.23 DE
xMate v1.15
Post Reply