MySql/MariaDB Edit a unique Key column

Post Reply
User avatar
betoncu
Posts: 126
Joined: Sat Oct 08, 2005 9:38 pm
Location: Cyprus (North)

MySql/MariaDB Edit a unique Key column

Post by betoncu »

Mr. Rao, I have faced another problem when I edit a column which is defined as unique key.
The browse does not refresh the edited row and does not position the cursor correctly.
Below I have attached a sample. Try to edit the name column of a row to see it please.

Code: Select all | Expand

#include "fivewin.ch"

static oCn

function Main()

   local oRs, oDlg, oBrw, oFont

   FWCONNECT oCn HOST "localhost" USER "root" PASSWORD "mypass" DATABASE "deneme" PORT 3306

   oCn:lShowErrors := .T.

   CreateTables()

   oRs   := oCn:RowSet( "SELECT ID, NAME FROM test_unq")
   oRs:Sort := "NAME"

   DEFINE FONT oFont NAME "Ms Sans Serif" SIZE 0, -12

   DEFINE DIALOG oDlg SIZE 500,600 FONT oFont PIXEL TRUEPIXEL TITLE "Test Unique Key"

   @ 70,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
           DATASOURCE oRs AUTOCOLS AUTOSORT ;
           COLSIZES -10, -30 ;
           CELL LINES NOBORDER

   oBrw:CreateFromCode()

   @ 20, 20 BTNBMP PROMPT "ADD"  SIZE 100,30 PIXEL FLAT OF oDlg ;
      ACTION oRs:EditBaseRecord( nil, .t., { |oRec| MyEditDlg( oRec ) }, oBrw )

   @ 20,130 BTNBMP PROMPT "EDIT" SIZE 100,30 PIXEL FLAT OF oDlg ;
      ACTION oRs:EditBaseRecord( nil, .f., { |oRec| MyEditDlg( oRec ) }, oBrw )

   @ 20,240 BTNBMP PROMPT "REFRESH" SIZE 100,30 PIXEL FLAT OF oDlg ;
      ACTION ( oRs:Requery(), oBrw:Refresh(), oBrw:SetFocus() )

   ACTIVATE DIALOG oDlg CENTERED
   oFont:End()

return nil


function CreateTables()

   oCn:DropTable( "test_unq" )

   if !oCn:TableExists( "test_unq" )
      oCn:CreateTable( "test_unq", { ;
         { "NAME",  'C', 30, 0, "UNI, NOT NULL" }, ;
         { "UNIT",  'C',  2, 0 }, ;
         { "PRICE", 'N',  6, 2 } } )

      oCn:Insert( "test_unq", "NAME, UNIT, PRICE", ;
         { {'BANANA', 'KG',  5.25}, {'SARDINES', 'AD', 2.15}, {'APPLE', 'KG', 3.50}, {'STRAWBERRY', 'KG', 1.30}, ;
           {'MELON',  'KG',  3.45}, {'ZERDECAL', 'GR', 8.65}, {'LEMON', 'KG', 1.00}, {'CRANBERRY',  'KG', 3.50} } )
   endif

return nil


static function MyEditDlg( oRec )

   local lNew     := ( oRec:RecNo == 0 )
   local oDlg, oFont

   DEFINE FONT oFont NAME "Ms Sans Serif" SIZE 0, -12

   DEFINE DIALOG oDlg SIZE 400,300 PIXEL TRUEPIXEL FONT oFont

   @ 030,020 SAY "ID:"    SIZE 80,20 PIXEL OF oDlg RIGHT
   @ 060,020 SAY "Name:"  SIZE 80,20 PIXEL OF oDlg RIGHT
   @ 090,020 SAY "Unit"   SIZE 80,20 PIXEL OF oDlg RIGHT
   @ 120,120 SAY "Price"  SIZE 80,20 PIXEL OF oDlg RIGHT

   @ 030,120 GET oRec:ID       SIZE 100,22 PIXEL OF oDlg WHEN .F.
   @ 060,120 GET oRec:NAME     SIZE 240,22 PIXEL OF oDlg
   @ 090,120 GET oRec:UNIT     SIZE  50,22 PIXEL OF oDlg
   @ 120,120 GET oRec:PRICE    SIZE  50,22 PIXEL OF oDlg PICTURE '999.99'

   @ 170,020 BTNBMP PROMPT "Save"   SIZE 150,30 PIXEL FLAT OF oDlg ;
             ACTION ( If( oRec:Modified(), oRec:Save(), nil ), oDlg:End() )

   @ 170,240 BTNBMP PROMPT "Cancel" SIZE 150,30 PIXEL FLAT OF oDlg ACTION oDlg:End()

   ACTIVATE DIALOG oDlg CENTERED ON PAINT oDlg:Box( 15, 10, 155, 390 )

return nil
 
Birol Betoncu
birol.betoncu@gmail.com
Using Harbour, FWH 19.05, BCC7
User avatar
betoncu
Posts: 126
Joined: Sat Oct 08, 2005 9:38 pm
Location: Cyprus (North)

Re: MySql/MariaDB Edit a unique Key column

Post by betoncu »

Up
Birol Betoncu
birol.betoncu@gmail.com
Using Harbour, FWH 19.05, BCC7
User avatar
nageswaragunupudi
Posts: 10733
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 11 times
Contact:

Re: MySql/MariaDB Edit a unique Key column

Post by nageswaragunupudi »

The method is working correctly if the field is not unique and fails when the field is unique. Thank you for pointing out the problem. This problem is fixed in the next version, i.e., FWH 17.07.

Please send me email to nageswaragunupudi at gmail dot com and we will send you revised libraries. Please also mention the latest FWH version you are using.
Regards

G. N. Rao.
Hyderabad, India
Post Reply