FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour MySql/MariaDB Edit a unique Key column
Posts: 130
Joined: Sat Oct 08, 2005 09:38 PM
MySql/MariaDB Edit a unique Key column
Posted: Fri Jun 30, 2017 11:04 PM
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 (fw): Select all Collapse
#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
Posts: 130
Joined: Sat Oct 08, 2005 09:38 PM
Re: MySql/MariaDB Edit a unique Key column
Posted: Sun Jul 09, 2017 10:27 PM

Up

Birol Betoncu
birol.betoncu@gmail.com
Using Harbour, FWH 19.05, BCC7
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: MySql/MariaDB Edit a unique Key column
Posted: Mon Jul 10, 2017 09:25 AM

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

Continue the discussion