Page 1 of 2

SetCheck() on MariaDB => SOLVED

Posted: Mon Sep 03, 2018 1:20 am
by fraxzi
Hi Folks,

I am having trouble displaying xBrowse :SetCheck() on MariaDB RS as shown:

RS:

Code: Select all

...
SELECT False AS lcheck, rdt_reqnum, rdt_reqdat, rdt_mrnumb, rdt_mrdesc
FROM rdt_forms
...

oRS::lTinyIntAsLogical := .T.

...
oBrw:aCols[ 1 ]:SetCheck({'checkon16', 'checkoff16'}, .T.)
...

 



I tried other combinations but the result is blank:

Image

:?:

Re: SetCheck() on MariaDB

Posted: Tue Sep 04, 2018 3:50 am
by nageswaragunupudi
Use only the

Code: Select all

function MYSQL_TinyIntAsLogical( .t. / .f. ) --> lPrevStatus
 
to set or reset the status.

Rowset remembers the status applicable for that table in its DATA lTinyIntAsLogical. We should not change it.

Global default is .F. and we recommend keeping it as .F.

Behavior when MYSQL_TinyIntAsLogical() is set to .F. :
(Default and Recommended)


1) When a table is created, logical fields are created as fields of BIT type.
2) When a table is read (i.e., when a rowset is read) BIT type fields are read as Boolean and TinyInteger fields are read as integers. Rowset object remembers the setting when it reads the table from the server and uses the same setting throughout the life of that recordset.

Behavior when MYSQL_TinyIntAsLogical() is set to .T. :

1) When a table is created, logical fields are created as fields of TINYINTEGER type.
2) When a table is read (i.e., when a rowset is read) BIT type fields and also TINYINTEGER fields are read as Boolean. Rowset object remembers the setting when it reads the table from the server and uses the same setting throughout the life of that recordset.

So, set MYSQL_TinyIntAsLogical( .t. / .f. ) once globally at the beginning of the program, depending on your personal choice and leave it.

Re: SetCheck() on MariaDB

Posted: Tue Sep 04, 2018 5:13 am
by fraxzi
Hi Rao,

I declared it as global on my init procedure and modify conditions ...

Image

Still the :SetCheck() and the oRS column showing numeric zero instead of boolean..

:?:

Re: SetCheck() on MariaDB

Posted: Tue Sep 04, 2018 8:33 am
by nageswaragunupudi
Please execute this:

Code: Select all

oCn:ListColumns( cTable, .t. )
You see the structure of the table in XBrowse

Please reproduce the screenshot here.

Re: SetCheck() on MariaDB

Posted: Tue Sep 04, 2018 9:14 am
by fraxzi
Hi Rao,

Here's the result with table containing TINYINT field is it the same structure when I query a table with TINYINT field?:

Image

Re: SetCheck() on MariaDB

Posted: Tue Sep 04, 2018 9:20 am
by nageswaragunupudi
Let me check

Re: SetCheck() on MariaDB

Posted: Tue Sep 04, 2018 10:42 am
by nageswaragunupudi
A simple test:

Code: Select all

function TestTinyInt()

   MYSQL_TinyIntAsLogical ( .t. )

   oCn:DropTable( "TINYTEST" )

   oCn:CreateTable( "tinytest", { { "fldlog", "L",  1, 0 }, ;
                                  { "fldchr", "C", 10, 0 }  } )

   oCn:Insert( "tinytest", "fldlog,fldchr", { { .f., "false" }, ;
                                              { .t., "true"  }  } )

   oCn:ListColumns( "tinytest", .t. )

   XBROWSER oCn:tinytest

return nil
 
Image

Image

Re: SetCheck() on MariaDB

Posted: Tue Sep 04, 2018 10:56 am
by nageswaragunupudi
Please try this small test program at your end and let us see the screen-shot of the result:

Code: Select all

#include "fivewin.ch"

function Main()

   local oCn
   
   oCn   := <your connection function>
   
   MYSQL_TinyIntAsLogical ( .t. )

   XBROWSER oCn:RowSet( "SELECT rdt_cnfirm,rdt_apprvd,rdt_appdby FROM rdt_forms" )

   oCn:Close()
   
return nil
 

Re: SetCheck() on MariaDB

Posted: Tue Sep 04, 2018 11:53 pm
by fraxzi
Hi Rao,

The samples you provided works.. But the other query condition (expression) still not recognized as boolean (after MYSQL_TinyIntAsLogical ( .T. ) global declaration) as shown:

with TinyInt column:
Image

with expression:
Image

query with HeidiSQL:
Image

:?:

Re: SetCheck() on MariaDB

Posted: Wed Sep 05, 2018 2:43 am
by nageswaragunupudi
MySQL returns "false AS lCheck" AS LONG INTEGER but not as TINYINT. There is no way you can return a TinyInt or Bit value from a Query, unless the field itself is TinyInt or Bit field.

We need to instruct XBrowse to treat the numeric value as logical.
This is how:

Code: Select all

#include "fivewin.ch"

function Main()

   local oCn, oRs, oDlg, oBrw
   
   oCn   := <your connection>
   oRs   := oCn:RowSet( "SELECT false AS lCheck, rdt_aprvd, rdt_appdby FROM rdt_forms" )
   
   DEFINE DIALOG oDlg SIZE 400,300 PIXEL TRUEPIXEL
   @ 20,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE oRs AUTOCOLS CELL LINES NOBORDER
      
   WITH OBJECT oBrw:lCheck
      :SetLogical()
      :SetCheck()
   END
   oBrw:CreateFromCode()
   
   ACTIVATE DIALOG oDlg CENTERED

return nil
 

Re: SetCheck() on MariaDB => SOLVED

Posted: Wed Sep 05, 2018 3:25 am
by fraxzi
Hi Rao,

You Nailed it :!:

:wink: :wink: :wink:

Re: SetCheck() on MariaDB => SOLVED

Posted: Wed Sep 05, 2018 3:56 am
by nageswaragunupudi
You must be using lCheck column to allow the user to select/deselect different rows.
Here is another way to do it without creating a logical column in the query itself. Please test it:

Code: Select all

#include "fivewin.ch"

function Main()

   local oCn, oRs, oDlg, oBrw, oFont

   oCn   := FW_DemoDB()
   oRs   := oCn:states

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
   DEFINE DIALOG oDlg SIZE 500,400 PIXEL TRUEPIXEL FONT oFont

   @ 20,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE oRs ;
      COLUMNS { || oBrw:IsSelectedRow() }, "CODE", "NAME" ;
      HEADERS "" ;
      CELL LINES NOBORDER FASTEDIT

   WITH OBJECT oBrw
      WITH OBJECT :aCols[ 1 ]
         :SetCheck()
         :nHeadBmpNo := 2
         :bLClickHeader := { || oBrw:SelectRow( If( Len( oBrw:aSelected ) == oBrw:nLen, 0, 4 ) ), oBrw:Refresh() }
         :bKeyChar   := { |k| If( k == VK_SPACE, ( oBrw:SelectRow(), 0 ), nil ) }
      END
      //
      oBrw:bLDblClick   := { || oBrw:SelectRow() }
      //
      :CreateFromCode()
   END

   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont

return nil
 

Re: SetCheck() on MariaDB => SOLVED

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

Yes you are correct! :D

The example you provided truly demonstrate xBrowse flexibility ... I so much appreciate your help.

Thanks!

:idea: :idea: :idea: :idea: :idea:

Re: SetCheck() on MariaDB => SOLVED

Posted: Wed Apr 08, 2020 8:31 pm
by vilian
Mr Rao,

I understand the code bellow select all rows:

Code: Select all

:bLClickHeader := { || oBrw:SelectRow( If( Len( oBrw:aSelected ) == oBrw:nLen, 0, 4 ) ), oBrw:Refresh() }
How could I avoid select some rows?

Re: SetCheck() on MariaDB => SOLVED

Posted: Thu Apr 09, 2020 4:03 am
by nageswaragunupudi
Clicking on any row toggles the selection.
Selected becomes unselected and vice versa.