Solved

Delphi, Mysql and boolean

Posted on 2008-10-06
6
729 Views
Last Modified: 2013-11-05
Hi,

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?

Thanks
Luc
0
Comment
Question by:Mysterion
  • 3
  • 2
6 Comments
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 22652933
Some databases use -1 as true, some use 1.
Only other way I can think would be to not use boolean and use smallInt
0
 
LVL 37

Accepted Solution

by:
Geert Gruwez earned 300 total points
ID: 22657383
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 ?
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 22657404
looking at the MySQL docs the value is stored as 0 or 1 into a TinyInt(1) field

http://dev.mysql.com/doc/refman/6.0/en/numeric-type-overview.html

how do you store the value into the mysql database ?
and what components do you use for this ?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 45

Assisted Solution

by:aikimark
aikimark earned 200 total points
ID: 22658167
@Luc

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.
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 22666761
Please read the help before you ask your next question
especially about accepting answers

http://beta.experts-exchange.com/help.jsp
0
 
LVL 45

Expert Comment

by:aikimark
ID: 22668376
@Geert_Gruwez

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now