Mr. Rao - Error using BIT type with TRecSet Class - Ado

Post Reply
User avatar
Compuin
Posts: 1256
Joined: Tue Dec 28, 2010 1:29 pm
Location: Quebec, Canada
Has thanked: 15 times
Been thanked: 4 times
Contact:

Mr. Rao - Error using BIT type with TRecSet Class - Ado

Post by Compuin »

Hello Mr Rao

I'm trying to get acces to a table using ADO.

I do my Ado connection with this

Code: Select all | Expand

oAp:oMySql:= FW_OpenAdoConnection( { "MYSQL", cServer, cDataBase, cUser, cPassWord }, .t. )
 


Now I need to open a Table using this code

Code: Select all | Expand

 
    cSql:= "SELECT * FROM CUSTOMER"
 
    oTable:=TRecSet():New():Open( cSql, oAp:oMySql )


For this line, I need to retrieve a Logical field, I set this field as BIT

Code: Select all | Expand

@ 5.7, 22 CHECKBOX oTable:Married PROMPT "Married"  UPDATE OF oDlg     //Line 51


But not matter if I switch BIT or TINYINT, I always get this error message
Time from start: 0 hours 0 mins 16 secs
Error occurred at: 21/08/2022, 13:06:04
Error description: Error BASE/1070 Argument error: ==
Args:
[ 1] = L .F.
[ 2] = N 1

Stack Calls
===========
Called from: .\source\classes\TRECSET.PRG => TRECSET:FIELDPUT( 596 )
Called from: .\source\classes\TRECSET.PRG => TRECSET:_MARRIED( 1286 )
Called from: source\Core\Ventas\test.prg => (b)TEST( 51 )


Please advise and thanks in advance
FWH 25.01 | Hbmk2 32/64 Bits (Build 19.29.30133) | Microsoft Visual C 32 Bits | MySql 8.0.24 32/64 Bits | VS Code
User avatar
nageswaragunupudi
Posts: 10729
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 10 times
Contact:

Re: Mr. Rao - Error using BIT type with TRecSet Class - Ado

Post by nageswaragunupudi »

I am looking into this.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
Posts: 10729
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 10 times
Contact:

Re: Mr. Rao - Error using BIT type with TRecSet Class - Ado

Post by nageswaragunupudi »

I am looking into this.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
Posts: 10729
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 10 times
Contact:

Re: Mr. Rao - Error using BIT type with TRecSet Class - Ado

Post by nageswaragunupudi »

We tested and TReSet class deals with BIT fields properly.
BIT field needs to be defined like this:

Code: Select all | Expand

`MARRIED` bit(1) DEFAULT b'0',


ADO always treats BIT fields as Boolean values ( Type 11 adBoolean ).

ADO does not natively support treating TINYINT as LOGICAL. If we want, we need to handle this by ourselves in our application program.

Please test with this sample program. Please use the same server we used in this sample.

Code: Select all | Expand

function AdoTestLogical()

   local oCn, oRs

   oCn   := FW_OpenAdoConnection( { "MYSQL","209.250.245.152","fwh","fwhuser","FiveTech@2022" }, .t. )

   if oCn == nil
      ? "connect fail"
      return nil
   endif

   oRs   := TRecSet():New( nil, "select * from customer", oCn )
   oRs:Open()
   if oRs:IsOpen

      ? oRs:Married, ValType( oRs:Married )
      oRs:Married := !oRs:Married
      ? oRs:Married

      oRs:Close()

   else
      ? "recset not open"
   endif

   oCn:Close()

return nil
 


You can comfortably use the value "oRs:bitfield" in CheckBoxes.
Please test

Code: Select all | Expand


? oRs:FieldType( "married" ) // --> result should be "L"
 

to make sure.

TINYINT
ADO treats "adTinyInt" (16) as Numeric Integer but not as Logical.

We know some MySql programmers use TinyInt for logical values.
In the next version we will provide the option to the programmer for using TinyInt as logical.
Regards

G. N. Rao.
Hyderabad, India
Post Reply