#1 2022-02-22 02:20:28

charlesqin
Member
Registered: 2020-10-14
Posts: 7

sql server field type is bit, when value is true, return -1. why?

fProps := TOleDBMSSQL2012ConnectionProperties.Create(VServer,VDatabase,VUserName,VPassword);

fProps.ExecuteInlined(VStr_Sql,True);

Offline

#2 2022-02-22 07:28:14

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,240
Website

Re: sql server field type is bit, when value is true, return -1. why?

Do you mean that a column type bit is returned as -1 when the value is true?

It seems as documented, and expected: there is no native boolean type in our DB classes.
So the boolean is converted into an integer.
Just transtype with boolean() to get back your "true" value. If you use our ORM, it will be done directly.

See OleDBColumnToFieldType() in mormot.db.raw.oledb.pas which detects DBTYPE_BOOL as a ftInt64.

Offline

#3 2022-02-23 03:41:50

charlesqin
Member
Registered: 2020-10-14
Posts: 7

Re: sql server field type is bit, when value is true, return -1. why?

thanks ab,

but how can i set the true value to 1 instead of -1 ?

Offline

#4 2022-02-23 08:55:13

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,240
Website

Re: sql server field type is bit, when value is true, return -1. why?

The integer conversion is done by the OleDB layer itself, which sets all bits to the integer value, therefore returns -1.

What do you want to achieve?

Offline

Board footer

Powered by FluxBB