List:General Discussion« Previous MessageNext Message »
From:alexander.skwar Date:February 7 2001 9:14am
Subject:Antwort: Boolean Datatype
View as plain text  
On 06.02.2001 18:09:36 russ wrote:

> Im new to the list, apologies if this has been asked before.
>
> Im developing a backend for a personal site (www.russd.com) using mySQL.
> The site is hosted on NT4 and has myODBC installed, I have some database
access
> working, but I'm looking for a way to implement boolean types.
>
> Using Access/SQL server I can simple do an insert using SQL like the following

> (from within ASP):
>
> INSERT INTO tblMyTable (booleanField) VALUES (" & myBooleanVariant & ");"

Okay, define booleanField to be TinyINT, or maybe ENUM('TRUE', 'FALSE'), but
TinyINT would be a lot easier IMO.
Then for FALSE you'd insert a 0 and for TRUE you'd insert something else.

> values within my ASP code to 1/0. This isn't perfect howevere as its more
code,

Why?  Dunno about ASP but since it's from M$ it must be superior to PHP *G* and
in PHP you'd simply do this:

$q = "INSERT INTO tblMyTable (booleanField) VALUES ('" . ( "yes" == "no" ) .
"')";
$rs = mysql_query( $q );

Now booleanField would be set to a FALSE value, or:

$q = "INSERT INTO tblMyTable (booleanField) VALUES ('" . ( "answer to life,
universe and everything" == "42" ) . "')";
$rs = mysql_query( $q );

This time, we'd have set your booleanField to TRUE *G*  (well, sorta :]).

$q = "SELECT booleanField FROM tblMyTable WHERE Something=42";
$rs = mysql_query( $q );
$row = mysql_fetch_object( $rs );

if( $row->booleanField ){(
     // booleanField is anything but 0, ie. it's TRUE
} else {
     // booleanField is 0, ie. it is FALSE
}

In how far is this more code??

> Could anyone suggest a better way of implementing this, or am I missing
> something?

Yeah, you're missing something.  In many languages there's no bool data type,
basically, because something like a tinyINT handles this very well.


Thread
Boolean DatatypeRuss Davies6 Feb
RE: Boolean DatatypeChris M. Oson6 Feb
  • Re: Boolean DatatypeRuss Davies6 Feb
    • Re: Boolean DatatypeVivek Khera6 Feb
    • RE: Boolean DatatypeRoger Ramirez6 Feb
  • Re: Boolean DatatypeRuss Davies6 Feb
RE: Boolean DatatypeChris M. Oson6 Feb
  • Re: Boolean DatatypeRuss Davies6 Feb
  • Re: Boolean DatatypeMatt Friedman6 Feb
  • Re: Boolean DatatypeRuss Davies6 Feb
  • Re: Boolean DatatypeGregg Housh6 Feb
  • Re: Boolean DatatypeRolf Hopkins7 Feb
Re: Boolean Datatypebtjones6 Feb
Re: Boolean DatatypeGregg Housh6 Feb
Antwort: Boolean Datatypealexander.skwar7 Feb