|
it
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
(true = 1) returns false?
tests (below), and it doesn't make sense to me. False is equal to 0, and that's fine. True should be equal to 1, but it's not. Actually, True should be equal to anything but False, null, and 0. Is there a workaround for this? Or do I need to change all my comparisons to = 1 instead of = true? response.write True = 1 'prints False response.write True = 0 'prints False response.write False = 1 'prints False response.write False = 0 'prints True Just fyi, I am trying to convert our database from Access to MySQL. Access stores boolean as true/false, and MySQL stores booleans as 1 and 0, which is why I have this problem. Thanks in advance for your responses. --Jason Webmaster Substitute Teaching Institute, Utah State University Jason wrote:
> I am fairly new to ASP--I have been using it about 2 months. I did Why do you think that?> these tests (below), and it doesn't make sense to me. False is equal > to 0, and that's fine. True should be equal to 1, See http://msdn.microsoft.com/library/en-us/script56/html/38045e3b-d4fb-4958-b6c3-1e500872d64f.asp > but it's not. Actually, True should be equal to anything but False, null, No, that's not the way it works. In vbscript, if an expression evluates > and 0. to -1 then the statement is true. Otherwise, it is false > Is there a workaround for this? Or do I need to change all my Huh? Why would you need to do that? Give me an example of something that is > comparisons to = 1 instead of = true? failing you because you are saying "= true" instead of "= -1" > Try:> response.write True = 1 'prints False > response.write True = 0 'prints False > response.write False = 1 'prints False > response.write False = 0 'prints True > Response.Write CBool(-1) Response.Write CBool(0) Response.Write CBool(1) Response.Write CBool(null) > Just fyi, I am trying to convert our database from Access to MySQL. You're familiar with Access? True is not even equal to 1 in Access!Where did you get the idea that it was equal to 1 in Access? > Access stores boolean as true/false, In actuality, Access (Jet) stores 0 for false/off/no and -1 for true/on/yes.This is easy to find out on your own. Create a table with a single Yes/No field, put some data inot it, then run this sql statement: select boolean_column, cint(boolean_column) as int_equivalent from yourtable > and MySQL stores booleans as 1 I don't work with MySQL but I don't think MySQL has a boolean datatype; at > and 0, which is why I have this problem. > least it doesn't if it's similar to SQL Server, which has a bit datatype, not boolean. What's the difference, you ask? A boolean can have two values: true or false. A bit can have 3 possible values: true, false or null. The OLE DB provider commonly handles conversions between vbscript and sql. So if you run a query against Access, you treat the data returned as if it was a native vbscript boolean subtype. The same thing will occur if you go against mysql or sql server: the bit datatype will be correctly translated to the vbscript boolean value. -- Microsoft MVP - ASP/ASP.NET Please reply to the newsgroup. This email account is my spam trap so I don't check it very often. If you must reply off-line, then remove the "NO SPAM" "Bob Barrows [MVP]" <reb01501@NOyahoo.SPAMcom> wrote in message I should have worded my question differently. That's what I was asking news:uqeyX5DhGHA.3924@TK2MSFTNGP03.phx.gbl... > Jason wrote: >> I am fairly new to ASP--I have been using it about 2 months. I did >> these tests (below), and it doesn't make sense to me. False is equal >> to 0, and that's fine. True should be equal to 1, >> but it's not. Actually, True should be equal to anything but False, null, >> and 0. > > No, that's not the way it works. In vbscript, if an expression evluates > to -1 then the statement is true. Otherwise, it is false > though, if VBscript followed the traditional definitions for true and false. >> Is there a workaround for this? Or do I need to change all my MySQL stores true as 1, not -1.>> comparisons to = 1 instead of = true? > > Huh? Why would you need to do that? Give me an example of something that > is failing you because you are saying "= true" instead of "= -1" > Not really that familiar with Access, no.>> Just fyi, I am trying to convert our database from Access to MySQL. > > You're familiar with Access? True is not even equal to 1 in Access! > I didn't say that, but it's irrelevant now.> Where did you get the idea that it was equal to 1 in Access? > I don't work with MySQL but I don't think MySQL has a boolean datatype; at MySQL stores booleans as an integers (unsigned I think), one byte big. 0 is > least it doesn't if it's similar to SQL Server, which has a bit datatype, > not boolean. What's the difference, you ask? A boolean can have two > values: true or false. A bit can have 3 possible values: true, false or > null. false, 1 is true. I haven't tested this, but I think MySQL treats any value other than 0 as true. However, when you store a value as true, it's stored as 1. > That's the problem then, it's not being translated correctly from MySQL.> The OLE DB provider commonly handles conversions between vbscript and sql. > So if you run a query against Access, you treat the data returned as if it > was a native vbscript boolean subtype. The same thing will occur if you go > against mysql or sql server: the bit datatype will be correctly translated > to the vbscript boolean value. > I'm not sure if I am using OLE DB or not. This is the code I use to connect: Dim sConnection, mysqlConn sConnection = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost; DATABASE=myDB; UID=user;PASSWORD=pass; OPTION=3" Set mysqlConn = Server.CreateObject("ADODB.Connection") mysqlConn.Open(sConnection) Is that using the OLE DB provider? The relevant part would be rather how you pass those data to MySQL rather
than the connection string... You way want to use parametized queries instead of stuffing text into an SQL statement (if this is the problem). It will take care of this as well as from possible problem with date formats and decimal values whose text is country dependant... A MySQL forum might be a better place (for example if this something specific to the dat type you used for your column, is this defined as a boolean or as an integer ?)... -- Patrice "Jason" <bigwheels16 hotmail> a écrit dans le message de news: KOSdnTCu6MYaQOHZnZ2dnUVZ_uWdn***@comcast.com...Show quote > > "Bob Barrows [MVP]" <reb01501@NOyahoo.SPAMcom> wrote in message > news:uqeyX5DhGHA.3924@TK2MSFTNGP03.phx.gbl... >> Jason wrote: >>> I am fairly new to ASP--I have been using it about 2 months. I did >>> these tests (below), and it doesn't make sense to me. False is equal >>> to 0, and that's fine. True should be equal to 1, >>> but it's not. Actually, True should be equal to anything but False, >>> null, and 0. >> >> No, that's not the way it works. In vbscript, if an expression evluates >> to -1 then the statement is true. Otherwise, it is false >> > > I should have worded my question differently. That's what I was asking > though, if VBscript followed the traditional definitions for true and > false. > >>> Is there a workaround for this? Or do I need to change all my >>> comparisons to = 1 instead of = true? >> >> Huh? Why would you need to do that? Give me an example of something that >> is failing you because you are saying "= true" instead of "= -1" > > MySQL stores true as 1, not -1. > >> >>> Just fyi, I am trying to convert our database from Access to MySQL. >> >> You're familiar with Access? True is not even equal to 1 in Access! > > Not really that familiar with Access, no. > >> >> Where did you get the idea that it was equal to 1 in Access? > > I didn't say that, but it's irrelevant now. > >> I don't work with MySQL but I don't think MySQL has a boolean datatype; >> at least it doesn't if it's similar to SQL Server, which has a bit >> datatype, not boolean. What's the difference, you ask? A boolean can have >> two values: true or false. A bit can have 3 possible values: true, false >> or null. > > MySQL stores booleans as an integers (unsigned I think), one byte big. 0 > is false, 1 is true. I haven't tested this, but I think MySQL treats any > value other than 0 as true. However, when you store a value as true, it's > stored as 1. > >> >> The OLE DB provider commonly handles conversions between vbscript and >> sql. So if you run a query against Access, you treat the data returned as >> if it was a native vbscript boolean subtype. The same thing will occur if >> you go against mysql or sql server: the bit datatype will be correctly >> translated to the vbscript boolean value. >> > > That's the problem then, it's not being translated correctly from MySQL. > I'm not sure if I am using OLE DB or not. > This is the code I use to connect: > > Dim sConnection, mysqlConn > sConnection = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost; > DATABASE=myDB; UID=user;PASSWORD=pass; OPTION=3" > Set mysqlConn = Server.CreateObject("ADODB.Connection") > mysqlConn.Open(sConnection) > > Is that using the OLE DB provider? >
Show quote
"Patrice" <scr***@chez.com> wrote in message To be honest, I am not real familiar with parametized queries. Would using news:%23PtVd8IhGHA.3996@TK2MSFTNGP03.phx.gbl... > The relevant part would be rather how you pass those data to MySQL rather > than the connection string... > > You way want to use parametized queries instead of stuffing text into an > SQL statement (if this is the problem). It will take care of this as well > as from possible problem with date formats and decimal values whose text > is country dependant... > > A MySQL forum might be a better place (for example if this something > specific to the dat type you used for your column, is this defined as a > boolean or as an integer ?)... > > -- > Patrice > parametized queries require a code change in every place that I query the db and get bool results back? Thanks for your reply. --Jason Yes, it would require changes...
Let's take things the other way round. My first thought would be that MySQL doesn't really have boolean columns (I thought of this because you said that MySQL consider as true any non 0 value. If the column was really a boolean you could only have 3 possible values). If MySQL doesn't provide an explicit boolean datatype the db layer won't have any kind of translation... You could easily then transmit a wrong value. Don't assume anything about the value of boleans and use something like IIf(Condition,1,0)so that you explicity code the value used by MySQL in your SQL statements (of course you could use your own small function so that you can eventually change this one day). It will also require changes... Finally you could just transform -1 to 1 server side if possible (would require just a small server side change ?) -- Patrice "Jason" <bigwheels16 hotmail> a écrit dans le message de news: _bGdnQo6IYPqe-DZnZ2dnUVZ_s-dn***@comcast.com...Show quote > "Patrice" <scr***@chez.com> wrote in message > news:%23PtVd8IhGHA.3996@TK2MSFTNGP03.phx.gbl... >> The relevant part would be rather how you pass those data to MySQL rather >> than the connection string... >> >> You way want to use parametized queries instead of stuffing text into an >> SQL statement (if this is the problem). It will take care of this as well >> as from possible problem with date formats and decimal values whose text >> is country dependant... >> >> A MySQL forum might be a better place (for example if this something >> specific to the dat type you used for your column, is this defined as a >> boolean or as an integer ?)... >> >> -- >> Patrice >> > > To be honest, I am not real familiar with parametized queries. Would > using parametized queries require a code change in every place that I > query the db and get bool results back? > > Thanks for your reply. > > --Jason > You're right, MySQL doesn't really have boolean data types. They are just
ints. I could change all the 1's to -1's in the database, but then queries like "SELECT * FROM table WHERE isOpen = true" would fail. MySQL only sees 1 as true, 0 as false, and anything else is neither. I am not sure what you mean by server side--the problem happens before the client ever sees any html. The root of the problem is the mysql definition of true vs the vbscript definition of true, where mysql defines trues as 1, and vbscript defines true as -1. So I can either change the values in the database, or I can change my code, and I don't want to change the database for the reason stated above. So basically, I am left with changing code, and that wouldn't be a quick change--there are lots of places I would have to change, but I don't see another option. I think the best option would be to use the CBool() function, so that is what I am going to do. thanks for your replies --Jason Show quote "Patrice" <scr***@chez.com> wrote in message news:%239EzBIVhGHA.2456@TK2MSFTNGP04.phx.gbl... > Yes, it would require changes... > > Let's take things the other way round. My first thought would be that > MySQL doesn't really have boolean columns (I thought of this because you > said that MySQL consider as true any non 0 value. If the column was really > a boolean you could only have 3 possible values). > > If MySQL doesn't provide an explicit boolean datatype the db layer won't > have any kind of translation... You could easily then transmit a wrong > value. > > Don't assume anything about the value of boleans and use something like > IIf(Condition,1,0)so that you explicity code the value used by MySQL in > your SQL statements (of course you could use your own small function so > that you can eventually change this one day). It will also require > changes... Finally you could just transform -1 to 1 server side if > possible (would require just a small server side change ?) > > -- > Patrice > > "Jason" <bigwheels16 hotmail> a écrit dans le message de news: > _bGdnQo6IYPqe-DZnZ2dnUVZ_s-dn***@comcast.com... >> "Patrice" <scr***@chez.com> wrote in message >> news:%23PtVd8IhGHA.3996@TK2MSFTNGP03.phx.gbl... >>> The relevant part would be rather how you pass those data to MySQL >>> rather than the connection string... >>> >>> You way want to use parametized queries instead of stuffing text into an >>> SQL statement (if this is the problem). It will take care of this as >>> well as from possible problem with date formats and decimal values whose >>> text is country dependant... >>> >>> A MySQL forum might be a better place (for example if this something >>> specific to the dat type you used for your column, is this defined as a >>> boolean or as an integer ?)... >>> >>> -- >>> Patrice >>> >> >> To be honest, I am not real familiar with parametized queries. Would >> using parametized queries require a code change in every place that I >> query the db and get bool results back? >> >> Thanks for your reply. >> >> --Jason >> > > Jason wrote:
Show quote > "Bob Barrows [MVP]" <reb01501@NOyahoo.SPAMcom> wrote in message I guess I'm having trouble with the word "traditional". But I think the > news:uqeyX5DhGHA.3924@TK2MSFTNGP03.phx.gbl... >> Jason wrote: >>> I am fairly new to ASP--I have been using it about 2 months. I did >>> these tests (below), and it doesn't make sense to me. False is >>> equal to 0, and that's fine. True should be equal to 1, >>> but it's not. Actually, True should be equal to anything but False, >>> null, and 0. >> >> No, that's not the way it works. In vbscript, if an expression >> evluates to -1 then the statement is true. Otherwise, it is false >> > > I should have worded my question differently. That's what I was > asking though, if VBscript followed the traditional definitions for > true and false. question is answered. > I'm not sure this is relevant, but given that I've never used MySQL, it may >>> Is there a workaround for this? Or do I need to change all my >>> comparisons to = 1 instead of = true? >> >> Huh? Why would you need to do that? Give me an example of something >> that is failing you because you are saying "= true" instead of "= -1" > > MySQL stores true as 1, not -1. be. Could you show me an example where this causes a problem for you? Maybe we can suggest something if the MySQL ODBC driver is not doing what it's supposed to do. > That's the problem then, it's not being translated correctly from With ADO, you are always using an OLE DB provider. In this case you are > MySQL. I'm not sure if I am using OLE DB or not. > This is the code I use to connect: > > Dim sConnection, mysqlConn > sConnection = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost; > DATABASE=myDB; UID=user;PASSWORD=pass; OPTION=3" > Set mysqlConn = Server.CreateObject("ADODB.Connection") > mysqlConn.Open(sConnection) > > Is that using the OLE DB provider? using the MSDASQL provider, which is the Provider for ODBC, i.e., it provides the interface between ODBC drivers and ADO. -- Microsoft MVP - ASP/ASP.NET Please reply to the newsgroup. This email account is my spam trap so I don't check it very often. If you must reply off-line, then remove the "NO SPAM" "Bob Barrows [MVP]" <reb01501@NOyahoo.SPAMcom> wrote in message Just an fyi, I did a test, and MySQL does not treat any value besides 0 as news:eXyc$TKhGHA.5088@TK2MSFTNGP02.phx.gbl... > Jason wrote: > >> MySQL stores true as 1, not -1. true, so sorry about that bad info. > Sure. Here's a test table I created.> I'm not sure this is relevant, but given that I've never used MySQL, it > may be. > > Could you show me an example where this causes a problem for you? Maybe we > can suggest something if the MySQL ODBC driver is not doing what it's > supposed to do. create table test ( id int not null primary key, name char(30), isMale bool ); Which generates this table: +--------+------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | so you can see the bool is stored as a 1 byte int.+--------+------------+------+-----+---------+-------+ | id int(11) PRI 0 | name char(30) YES NULL | isMale tinyint(1) YES NULL +--------+------------+------+-----+---------+-------+ Then I insert two rows: insert into test VALUES(1, 'Jack', true); insert into test VALUES(2, 'Jill', false); The resulting table rows are: +----+------+--------+ | id | name | isMale | 1 for true, 0 for false.+----+------+--------+ | 1 Jack 1 | 2 Jill 0 +----+------+--------+ This is some sample code to demonstrate the problem: '-------- strquery = "SELECT * FROM test" set rsobj = objconn.execute(strquery) while NOT rsobj.eof if rsobj("isMale") = true then response.write rsobj("name") & "<br />" end ifrsobj.MoveNext wend '--------- Nothing prints. If I change the IF statement to ' if rsobj("isMale") = false then ' then it will print ' Jill '. Or if I change the value of isMale for Jack to -1, then it will also work as intended, but MySQL doesn't recognize -1 as true. I realize I may have to change my code, but I would like to avoid that if possible becuase it would take a lot of changes. It must store bools as signed ints, instead of unsigned ints, since it let me change it to -1, so sorry about that bad info before also. Thank you for your replies. --Jason Show quote > > With ADO, you are always using an OLE DB provider. In this case you are > using the MSDASQL provider, which is the Provider for ODBC, i.e., it > provides the interface between ODBC drivers and ADO. > > -- > Microsoft MVP - ASP/ASP.NET > Please reply to the newsgroup. This email account is my spam trap so I > don't check it very often. If you must reply off-line, then remove the > "NO SPAM" > "Jason" <bigwheels16 hotmail> wrote in message How about...news:t9Sdndt2OvdPfuDZnZ2dnUVZ_vudnZ2d@comcast.com... > while NOT rsobj.eof > > if rsobj("isMale") = true then > response.write rsobj("name") & "<br />" > end if > > rsobj.MoveNext > wend if rsobj("isMale") then response.write rsobj("name") & "<br />" Does that do what you want?end if -- roger
Show quote
"roger" <mothl***@btopenworld.com> wrote in message Well, if that worked, then yes :) but that doesn't work, which is the news:%23VN32rhhGHA.3424@TK2MSFTNGP05.phx.gbl... > "Jason" <bigwheels16 hotmail> wrote in message > news:t9Sdndt2OvdPfuDZnZ2dnUVZ_vudnZ2d@comcast.com... > > > How about... > > if rsobj("isMale") then > response.write rsobj("name") & "<br />" > end if > > Does that do what you want? > > problem.
Show quote
"Jason" <bigwheels16 hotmail> wrote in message Perhaps I am not understanding the problemnews:yrOdnVm9ZY0VER3ZnZ2dnUVZ_sKdnZ2d@comcast.com... > > How about... > > > > if rsobj("isMale") then > > response.write rsobj("name") & "<br />" > > end if > > > > Does that do what you want? > > > > > > Well, if that worked, then yes :) but that doesn't work, which is the > problem. dim b b = 1 if b then Response.Write "true = 1" if b = true then Response.Write "but this doesn't work" gives me the result... true = 1 Isn't that what you want? -- roger
Show quote
"roger" <mothl***@btopenworld.com> wrote in message Yes. That's exactly what I want, but your example doesn't work that way for news:OPstqHohGHA.1272@TK2MSFTNGP03.phx.gbl... > > > Perhaps I am not understanding the problem > > dim b > > b = 1 > if b then Response.Write "true = 1" > if b = true then Response.Write "but this doesn't work" > > gives me the result... > > true = 1 > > Isn't that what you want? > > -- > roger me when I do it. For me, b = 0 evaluates to false, b = -1 evaluates to true, and if b equals any other number, then b is neither true nor false. Are you sure that code works for you? I mean, did you test it? Because if it does, I would be interested to know why it works for you and not for me. --Jason Jason wrote on 06 jun 2006 in microsoft.public.inetserver.asp.general:
Show quote > "roger" <mothl***@btopenworld.com> wrote in message Then why use the internal evaluation?>> >> >> Perhaps I am not understanding the problem >> >> dim b >> >> b = 1 >> if b then Response.Write "true = 1" >> if b = true then Response.Write "but this doesn't work" >> >> gives me the result... >> >> true = 1 >> >> Isn't that what you want? >> > > Yes. That's exactly what I want, but your example doesn't work that > way for me when I do it. For me, b = 0 evaluates to false, b = -1 > evaluates to true, and if b equals any other number, then b is neither > true nor false. Are you sure that code works for you? I mean, did you > test it? Because if it does, I would be interested to know why it > works for you and not for me. Using your definition: if b = 0 then b = "is false" elseif b=-1 then b = "is true" else b = "is neither" end if -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
Show quote
"Evertjan." <exjxw.hannivo***@interxnl.net> wrote in message Yeah, I could do that....but I was looking for a solution that didn't news:Xns97DA611DAA9C9eejj99@194.109.133.242... >> works for you and not for me. > > Then why use the internal evaluation? > > Using your definition: > > if b = 0 then > b = "is false" > elseif b=-1 then > b = "is true" > else > b = "is neither" > end if > involve changing my code every place I used 'if b = true then...' There is no solution that I am aware of so I did change my code from 'if b=true then...' to 'if CBool(b) = true then...' in every spot. Jason wrote on 06 jun 2006 in microsoft.public.inetserver.asp.general:
Show quote > "Evertjan." <exjxw.hannivo***@interxnl.net> wrote in message Since if then tests for true/false itself,>>> works for you and not for me. >> >> Then why use the internal evaluation? >> >> Using your definition: >> >> if b = 0 then >> b = "is false" >> elseif b=-1 then >> b = "is true" >> else >> b = "is neither" >> end if >> > Yeah, I could do that....but I was looking for a solution that didn't > involve changing my code every place I used 'if b = true then...' > > There is no solution that I am aware of so I did change my code from > 'if b=true then...' to 'if CBool(b) = true then...' in every spot. I would not expect any difference in behavur between: if b = true then and if b then however, if you want to test for "true", "false" and "neither", my above code remains necassary, IMHO. -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress) > I don't think you understand the problem. ASP defines 0 as false and -1 as > Since if then tests for true/false itself, > I would not expect any difference in behavur between: > > if b = true then > > and > > if b then > > however, > if you want to test for "true", "false" and "neither", > my above code remains necassary, IMHO. > true, and everything else is neither. I wanted a way to make ASP define 1 also as true, but we couldn't come up with one except to change code everywhere I needed that extra functionality. Jason wrote on 06 jun 2006 in microsoft.public.inetserver.asp.general:
>> if you want to test for "true", "false" and "neither", True.>> my above code remains necassary, IMHO. >> > I don't think you understand the problem. > ASP defines 0 as false and Not true. > -1 as true, and everything else is neither. ============== ASP is just the platform, and does not define. ============== ASP-VBscript does boolean TEST 0 as false and all other as true. [You could call that "define"] if 7 then response.write "TRUE" if NOT 0 then response.write "FALSE" VBscript does translate in a FORMULA true as -1, and false as 0 response.write true ' shows True response.write 7 + true ' shows 6 response.write 7 + false ' shows 7 =============== ASP-JScript TESTS [boolean] 0 as false and other numbers as true, if (7) response.write( 'TRUE' ); if (! 0) response.write( 'FALSE' ); and does translate in a FORMULA true as 1, and false as 0 response.write( 7 + true ); // 8 > I wanted a way to make > ASP define 1 also as true, but we couldn't come up with one except to > change code everywhere I needed that extra functionality. > -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress) Jason wrote:
>> No, not quite. If an expression evaluates to 0, it is False. All other> I don't think you understand the problem. ASP defines 0 as false and > -1 as true, and everything else is neither. results are True*. Again, try: <% Response.Write CBool(-1) Response.Write CBool(0) Response.Write CBool(1) Response.Write CBool(2) %> Here is the result I get from this: TrueFalseTrueTrue So you see that CBool(2) resulted in True. In fact, the only one that resulted in False was 0. In fact, try this: <% if (1+3) then Response.Write "<br>true" else Response.Write "<br>false" end if s="abcd" Response.Write "<BR>" & instr(s,"c") if instr(s,"c") then Response.Write "<BR>c is in abcd" else Response.Write "<BR>c is not in abcd" end if %> This is the real reason both Yes/No values from Access and bit values from SQL Server work well in vbscript/vb. I'm still not clear about why your boolean values from MySQL aren't working the same way. Bob Barrows *I realize I mistakenly said the reverse of this in my earlier message - my apologies. -- Microsoft MVP -- ASP/ASP.NET Please reply to the newsgroup. The email account listed in my From header is my spam trap, so I don't check it very often. You will get a quicker response by posting to the newsgroup. Bob Barrows [MVP] wrote:
> Jason wrote: Interestingly, this is exactly the same in MySQL:> >> > > I don't think you understand the problem. ASP defines 0 as false and > > -1 as true, and everything else is neither. > > No, not quite. If an expression evaluates to 0, it is False. All other > results are True*. (See BOOL,BOOLEAN subhead) http://dev.mysql.com/doc/refman/5.0/en/numeric-type-overview.html -- Mike Brind
Show quote
"Bob Barrows [MVP]" <reb01501@NOyahoo.SPAMcom> wrote in message Actually the reason it works is that if you check the field type property itnews:u9Jaz4aiGHA.1508@TK2MSFTNGP04.phx.gbl... > Jason wrote: > >> > > I don't think you understand the problem. ASP defines 0 as false and > > -1 as true, and everything else is neither. > > No, not quite. If an expression evaluates to 0, it is False. All other > results are True*. Again, try: > > <% > Response.Write CBool(-1) > Response.Write CBool(0) > Response.Write CBool(1) > Response.Write CBool(2) > > %> > Here is the result I get from this: > TrueFalseTrueTrue > So you see that CBool(2) resulted in True. In fact, the only one that > resulted in False was 0. > > In fact, try this: > <% > if (1+3) then > Response.Write "<br>true" > else > Response.Write "<br>false" > end if > > s="abcd" > Response.Write "<BR>" & instr(s,"c") > if instr(s,"c") then > Response.Write "<BR>c is in abcd" > else > Response.Write "<BR>c is not in abcd" > end if > %> > > > This is the real reason both Yes/No values from Access and bit values > from SQL Server work well in vbscript/vb. > I'm still not clear about why your boolean values from MySQL aren't > working the same way. is set to adBoolean (11) that is boolean. Since the value property is a variant it will contain either -1 for True or 0 for False. I suspect the MySQL isn't using this adBoolean (probably adUnsignedTinyInt or some such) and therefore the value comes through as 1 Show quote > > Bob Barrows > > *I realize I mistakenly said the reverse of this in my earlier message - > my apologies. > -- > Microsoft MVP -- ASP/ASP.NET > Please reply to the newsgroup. The email account listed in my From > header is my spam trap, so I don't check it very often. You will get a > quicker response by posting to the newsgroup. > > Anthony Jones wrote:
>> This is the real reason both Yes/No values from Access and bit values Yes, you're probably correct.>> from SQL Server work well in vbscript/vb. >> I'm still not clear about why your boolean values from MySQL aren't >> working the same way. > > Actually the reason it works is that if you check the field type > property it is set to adBoolean (11) that is boolean. > Since the value property is a variant it will contain either -1 for > True or 0 for False. > > I suspect the MySQL isn't using this adBoolean (probably > adUnsignedTinyInt or some such) and therefore the value comes through > as 1 > -- Microsoft MVP -- ASP/ASP.NET Please reply to the newsgroup. The email account listed in my From header is my spam trap, so I don't check it very often. You will get a quicker response by posting to the newsgroup.
Show quote
"Bob Barrows [MVP]" <reb01501@NOyahoo.SPAMcom> wrote in message Ok, I figured out why we're having this problem. And it's kind of my bad, news:ebBpHBjiGHA.3496@TK2MSFTNGP02.phx.gbl... > Anthony Jones wrote: >>> This is the real reason both Yes/No values from Access and bit values >>> from SQL Server work well in vbscript/vb. >>> I'm still not clear about why your boolean values from MySQL aren't >>> working the same way. >> >> Actually the reason it works is that if you check the field type >> property it is set to adBoolean (11) that is boolean. >> Since the value property is a variant it will contain either -1 for >> True or 0 for False. >> >> I suspect the MySQL isn't using this adBoolean (probably >> adUnsignedTinyInt or some such) and therefore the value comes through >> as 1 >> > Yes, you're probably correct. > -- > Microsoft MVP -- ASP/ASP.NET > Please reply to the newsgroup. The email account listed in my From > header is my spam trap, so I don't check it very often. You will get a > quicker response by posting to the newsgroup. > kind of. :P I assumed it would work the same way it does in C++, but it doesn't. My if statements look like this: <% if rsobj("column") = true then %> and that fails, but if I change them to this: <% if rsobj("colum") then %> then it works. It appears that true is just an alias for -1. So ASP (using vbscript) as a language defines true as anything except false, and defines false as zero, but the keyword true is only defined as -1. I can't say I am pleased with this, but I am pleased with knowing why. --jason
Show quote
"Jason" <bigwheels16 hotmail> wrote in message Take this C++ :-news:z4mdnQX7S9gugBrZnZ2dnUVZ_t2dnZ2d@comcast.com... > "Bob Barrows [MVP]" <reb01501@NOyahoo.SPAMcom> wrote in message > news:ebBpHBjiGHA.3496@TK2MSFTNGP02.phx.gbl... > > Anthony Jones wrote: > >>> This is the real reason both Yes/No values from Access and bit values > >>> from SQL Server work well in vbscript/vb. > >>> I'm still not clear about why your boolean values from MySQL aren't > >>> working the same way. > >> > >> Actually the reason it works is that if you check the field type > >> property it is set to adBoolean (11) that is boolean. > >> Since the value property is a variant it will contain either -1 for > >> True or 0 for False. > >> > >> I suspect the MySQL isn't using this adBoolean (probably > >> adUnsignedTinyInt or some such) and therefore the value comes through > >> as 1 > >> > > Yes, you're probably correct. > > -- > > Microsoft MVP -- ASP/ASP.NET > > Please reply to the newsgroup. The email account listed in my From > > header is my spam trap, so I don't check it very often. You will get a > > quicker response by posting to the newsgroup. > > > Ok, I figured out why we're having this problem. And it's kind of my bad, > kind of. :P I assumed it would work the same way it does in C++, but it > doesn't. > > My if statements look like this: > > <% > if rsobj("column") = true then > %> > > and that fails, but if I change them to this: > > <% > if rsobj("colum") then > %> > > then it works. > > It appears that true is just an alias for -1. So ASP (using vbscript) as a > language defines true as anything except false, and defines false as zero, > but the keyword true is only defined as -1. > > I can't say I am pleased with this, but I am pleased with knowing why. > if (5 == true) // 5 is equal to true this doesn't happen else // 5 is not equal to true this happens However things are different if you do this:- if (1 == true) // 1 is equal to true this does happen else // 1 is not equal to true this doesn't happen or this:- if (5) // This always happens else // This never happens In C/C++ (as is the same with VB/Script) when a boolean type and a numeric type are either side of an operand it is the boolean which is coerced to a numeric. However the C/C++ true is an 'alias' for 1 whereas in VB/Script/COM a true is -1. The reason -1 was chosen is that VB does not differentiate between bitwise and logical operators (e.g. & or && in C) it only has bitwise operators (and, or, not). It seems you have two problems. 1) using 'if x = true then' forces the true to be coerced to a numeric and then a comparison is made and then a branch is made accordingly. Whereas 'if x Then' simply branches to 'then' on non-zero and 'else' on zero. 2) rsobj("column") isn't a boolean type but some kind of numeric type (although I have found some interface declare a COM interface having a boolean parameter or member but actually use 1 instead of -1 but that is poor implementation). Frankly stop doing this x = true and be aware that all apparently logical operators in VB are in fact bitwise Show quote > --jason > > Anthony Jones wrote:
> 2) rsobj("column") isn't a boolean type but some kind of numeric type An alternative would be to coerce the MySQL boolean trues to -1, perhaps > (although I have found some interface declare a COM interface having a > boolean parameter or member but actually use 1 instead of -1 but that > is poor implementation). > > Frankly stop doing this x = true and be aware that all apparently > logical operators in VB are in fact bitwise > > using a view with a calculated column. -- Microsoft MVP - ASP/ASP.NET Please reply to the newsgroup. This email account is my spam trap so I don't check it very often. If you must reply off-line, then remove the "NO SPAM"
Show quote
"Anthony Jones" <A**@yadayadayada.com> wrote in message Yeah, you are right. I assumed 'if b == true then...' and 'if b then...' news:u3fH6TtiGHA.1508@TK2MSFTNGP04.phx.gbl... > > Take this C++ :- > > if (5 == true) > // 5 is equal to true this doesn't happen > else > // 5 is not equal to true this happens > > > However things are different if you do this:- > > if (1 == true) > // 1 is equal to true this does happen > else > // 1 is not equal to true this doesn't happen > > or this:- > > if (5) > // This always happens > else > // This never happens > > > In C/C++ (as is the same with VB/Script) when a boolean type and a numeric > type are either side of an operand it is the boolean which is coerced to a > numeric. However the C/C++ true is an 'alias' for 1 whereas in > VB/Script/COM a true is -1. The reason -1 was chosen is that VB does not > differentiate between bitwise and logical operators (e.g. & or && in C) > it only has bitwise operators (and, or, not). > > It seems you have two problems. > > 1) using 'if x = true then' forces the true to be coerced to a numeric and > then a comparison is made and then a branch is made accordingly. Whereas > 'if x Then' simply branches to 'then' on non-zero and 'else' on zero. > > 2) rsobj("column") isn't a boolean type but some kind of numeric type > (although I have found some interface declare a COM interface having a > boolean parameter or member but actually use 1 instead of -1 but that is > poor implementation). > > Frankly stop doing this x = true and be aware that all apparently > logical > operators in VB are in fact bitwise > were identical statements, but they aren't. Your explanantion of how the bool is casted as an int helps to make it clear as to why it happens because I did not really know why. --jason "Bob Barrows [MVP]" <reb01501@NOyahoo.SPAMcom> wrote in message I'm not clear why either. :)news:u9Jaz4aiGHA.1508@TK2MSFTNGP04.phx.gbl... > > This is the real reason both Yes/No values from Access and bit values > from SQL Server work well in vbscript/vb. > I'm still not clear about why your boolean values from MySQL aren't > working the same way. > > Bob Barrows > --jason
Show quote
"Jason" <bigwheels16 hotmail> wrote in message I posted this just before I discovered why.news:DtudnU-1nsykihrZnZ2dnUVZ_s6dnZ2d@comcast.com... > "Bob Barrows [MVP]" <reb01501@NOyahoo.SPAMcom> wrote in message > news:u9Jaz4aiGHA.1508@TK2MSFTNGP04.phx.gbl... >> >> This is the real reason both Yes/No values from Access and bit values >> from SQL Server work well in vbscript/vb. >> I'm still not clear about why your boolean values from MySQL aren't >> working the same way. >> >> Bob Barrows >> > I'm not clear why either. :) > > --jason --jason "Jason" <bigwheels16 hotmail> wrote in message Very strange. And yes I did test it.news:3sidnRgXm88gkxjZnZ2dnUVZ_smdnZ2d@comcast.com... > Yes. That's exactly what I want, but your example doesn't work that way for > me when I do it. For me, b = 0 evaluates to false, b = -1 evaluates to > true, and if b equals any other number, then b is neither true nor false. > Are you sure that code works for you? I mean, did you test it? Because if > it does, I would be interested to know why it works for you and not for me. "if b then" should test whether b is non-zero. and "if b = true then" should test whether b is identical to the definition of the keyword "true", which in VBScript is -1. I remain mystified why this doesn't work for you. -- roger Good example of this is the .checked value of a checkbox. it will
return a -1 if checked (vbscript). Easy to work around with a CBool(obj.checked) or cint(obj.checked) * -1 depending on the desired output. ~ John Fullmer Bob Barrows [MVP] wrote: Show quote > Jason wrote: > > I am fairly new to ASP--I have been using it about 2 months. I did > > these tests (below), and it doesn't make sense to me. False is equal > > to 0, and that's fine. True should be equal to 1, > > Why do you think that? > See > http://msdn.microsoft.com/library/en-us/script56/html/38045e3b-d4fb-4958-b6c3-1e500872d64f.asp > > > > but it's not. Actually, True should be equal to anything but False, null, > > and 0. > > No, that's not the way it works. In vbscript, if an expression evluates > to -1 then the statement is true. Otherwise, it is false > > > Is there a workaround for this? Or do I need to change all my > > comparisons to = 1 instead of = true? > > Huh? Why would you need to do that? Give me an example of something that is > failing you because you are saying "= true" instead of "= -1" > > > > > response.write True = 1 'prints False > > response.write True = 0 'prints False > > response.write False = 1 'prints False > > response.write False = 0 'prints True > > > > Try: > Response.Write CBool(-1) > Response.Write CBool(0) > Response.Write CBool(1) > Response.Write CBool(null) > > > Just fyi, I am trying to convert our database from Access to MySQL. > > You're familiar with Access? True is not even equal to 1 in Access! > > Where did you get the idea that it was equal to 1 in Access? > > > Access stores boolean as true/false, > > In actuality, Access (Jet) stores 0 for false/off/no and -1 for true/on/yes. > This is easy to find out on your own. Create a table with a single Yes/No > field, put some data inot it, then run this sql statement: > > select boolean_column, cint(boolean_column) as int_equivalent > from yourtable > > > and MySQL stores booleans as 1 > > and 0, which is why I have this problem. > > > > I don't work with MySQL but I don't think MySQL has a boolean datatype; at > least it doesn't if it's similar to SQL Server, which has a bit datatype, > not boolean. What's the difference, you ask? A boolean can have two values: > true or false. A bit can have 3 possible values: true, false or null. > > The OLE DB provider commonly handles conversions between vbscript and sql. > So if you run a query against Access, you treat the data returned as if it > was a native vbscript boolean subtype. The same thing will occur if you go > against mysql or sql server: the bit datatype will be correctly translated > to the vbscript boolean value. > > > -- > Microsoft MVP - ASP/ASP.NET > Please reply to the newsgroup. This email account is my spam trap so I > don't check it very often. If you must reply off-line, then remove the > "NO SPAM" Yeah, and I don't really see a better option than using CBool(). It won't
be quick but at least it will work. --Jason Show quote "John Fullmer" <jk***@hotmail.com> wrote in message news:1149176515.871969.307760@f6g2000cwb.googlegroups.com... > Good example of this is the .checked value of a checkbox. it will > return a -1 if checked (vbscript). Easy to work around with a > CBool(obj.checked) or cint(obj.checked) * -1 depending on the desired > output. > > ~ John Fullmer > > > Bob Barrows [MVP] wrote: >> Jason wrote: >> > I am fairly new to ASP--I have been using it about 2 months. I did >> > these tests (below), and it doesn't make sense to me. False is equal >> > to 0, and that's fine. True should be equal to 1, >> >> Why do you think that? >> See >> http://msdn.microsoft.com/library/en-us/script56/html/38045e3b-d4fb-4958-b6c3-1e500872d64f.asp >> >> >> > but it's not. Actually, True should be equal to anything but False, >> > null, >> > and 0. >> >> No, that's not the way it works. In vbscript, if an expression evluates >> to -1 then the statement is true. Otherwise, it is false >> >> > Is there a workaround for this? Or do I need to change all my >> > comparisons to = 1 instead of = true? >> >> Huh? Why would you need to do that? Give me an example of something that >> is >> failing you because you are saying "= true" instead of "= -1" >> >> > >> > response.write True = 1 'prints False >> > response.write True = 0 'prints False >> > response.write False = 1 'prints False >> > response.write False = 0 'prints True >> > >> >> Try: >> Response.Write CBool(-1) >> Response.Write CBool(0) >> Response.Write CBool(1) >> Response.Write CBool(null) >> >> > Just fyi, I am trying to convert our database from Access to MySQL. >> >> You're familiar with Access? True is not even equal to 1 in Access! >> >> Where did you get the idea that it was equal to 1 in Access? >> >> > Access stores boolean as true/false, >> >> In actuality, Access (Jet) stores 0 for false/off/no and -1 for >> true/on/yes. >> This is easy to find out on your own. Create a table with a single Yes/No >> field, put some data inot it, then run this sql statement: >> >> select boolean_column, cint(boolean_column) as int_equivalent >> from yourtable >> >> > and MySQL stores booleans as 1 >> > and 0, which is why I have this problem. >> > >> >> I don't work with MySQL but I don't think MySQL has a boolean datatype; >> at >> least it doesn't if it's similar to SQL Server, which has a bit datatype, >> not boolean. What's the difference, you ask? A boolean can have two >> values: >> true or false. A bit can have 3 possible values: true, false or null. >> >> The OLE DB provider commonly handles conversions between vbscript and >> sql. >> So if you run a query against Access, you treat the data returned as if >> it >> was a native vbscript boolean subtype. The same thing will occur if you >> go >> against mysql or sql server: the bit datatype will be correctly >> translated >> to the vbscript boolean value. >> >> >> -- >> Microsoft MVP - ASP/ASP.NET >> Please reply to the newsgroup. This email account is my spam trap so I >> don't check it very often. If you must reply off-line, then remove the >> "NO SPAM" > |
|||||||||||||||||||||||