SetCheck() on MariaDB => SOLVED

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

SetCheck() on MariaDB => SOLVED

Post 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

:?:
Last edited by fraxzi on Wed Sep 05, 2018 3:23 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: SetCheck() on MariaDB

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

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

Re: SetCheck() on MariaDB

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

:?:
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: SetCheck() on MariaDB

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

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

Re: SetCheck() on MariaDB

Post 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
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: SetCheck() on MariaDB

Post by nageswaragunupudi »

Let me check
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: SetCheck() on MariaDB

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

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: SetCheck() on MariaDB

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

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

Re: SetCheck() on MariaDB

Post 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

:?:
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: SetCheck() on MariaDB

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

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

Re: SetCheck() on MariaDB => SOLVED

Post by fraxzi »

Hi Rao,

You Nailed it :!:

: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
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: SetCheck() on MariaDB => SOLVED

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

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

Re: SetCheck() on MariaDB => SOLVED

Post 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:
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
vilian
Posts: 795
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil
Contact:

Re: SetCheck() on MariaDB => SOLVED

Post 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?
Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: SetCheck() on MariaDB => SOLVED

Post by nageswaragunupudi »

Clicking on any row toggles the selection.
Selected becomes unselected and vice versa.
Regards

G. N. Rao.
Hyderabad, India
Post Reply