• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 755
  • Last Modified:

Delphi, Mysql and boolean


I have a problem with delphi and mysql.. when i save a boolean in the database, the false is 0 and the true is -1.

Is there any way to force mysql to save it as 1 instead of -1?

  • 3
  • 2
2 Solutions
Some databases use -1 as true, some use 1.
Only other way I can think would be to not use boolean and use smallInt
Geert GOracle dbaCommented:
in what context are you using the loaded value ?

you could use
FieldByName('FIELDNAME').AsString = '0'
for False and

FieldByName('FIELDNAME').AsString <> '0'
for True

or is it the .AsBoolean which allways returns false ?
Geert GOracle dbaCommented:
looking at the MySQL docs the value is stored as 0 or 1 into a TinyInt(1) field


how do you store the value into the mysql database ?
and what components do you use for this ?
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.


Why would it matter how any database engine stores its boolean data values as long as your program accurately reflects their TRUE and FALSE values when records are retrieved?

If you need to sum a boolean column to determine the number of TRUE values, then take the absolute value of the SUM() function.
Geert GOracle dbaCommented:
Please read the help before you ask your next question
especially about accepting answers


Please be a bit more specific in what you are urging Mysterion to consider or change in evaluation of future answers.

Your answer was very language specific, where my answer was database/SQL specific.  Somewhere between the two of our answers, Luc seems to have gotten an acceptable work-around.  Looking at the new grading recommendations, I don't see anything amiss in the B grade and the split points.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now