Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Delphi, Mysql and boolean

Posted on 2008-10-06
6
735 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Machine not responding during CopyFile() 3 103
CheckListBox usage 3 71
How to load 2 images in same column in Delphi 2 57
firemonkey Android Listview Sort items 7 49
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

839 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