(true = 1)返回false? [英] (true = 1) returns false?

查看:89
本文介绍了(true = 1)返回false?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是ASP的新手 - 我已经使用了大约2个月。我做了这些

测试(下面),这对我来说没有意义。 False等于0,并且

表示没问题。 True应该等于1,但事实并非如此。实际上,True

应该等于False,null和0之外的任何东西。有没有解决方法

这个?或者我是否需要将所有比较更改为= 1而不是=

true?


response.write True = 1''打印False

response.write True = 0''打印错误

response.write False = 1''打印错误

response.write False = 0''打印真的


只是fyi,我正在尝试将我们的数据库从Access转换为MySQL。访问

将布尔值存储为真/假,并且MySQL将布尔值存储为1和0,这是为什么我有这个问题。


提前感谢您的回复。


- 贾森

网站管理员

代课教学,

犹他州立大学

解决方案

Jason写道:

我对ASP很新 - 我去过使用它约2个月。我做了这些测试(下面),对我来说没有意义。假等于0,这很好。真应该等于1,


你为什么这么认为?


http://msdn.microsoft.com/library/en。 .,500872d64f.asp


但不是。实际上,True应该等于False,null,
和0.


不,这不是它的工作方式。在vbscript中,如果表达式将

调整为-1,则该语句为真。否则,它是假的

这是否有解决方法?或者我是否需要将所有
比较更改为= 1而不是= true?


嗯?你为什么要这么做?给我一个例子,说明因为你说= true而导致你失败​​的事情。而不是= -1

response.write True = 1''打印错误
response.write True = 0''打印错误
response.write False = 1 ''打印错误
response.write False = 0''打印真实


尝试:

Response.Write CBool​​(-1)

Response.Write CBool​​(0)

Response.Write CBool​​(1)

Response.Write CBool​​(null)

只是fyi,我正在尝试将数据库从Access转换为MySQL。


您熟悉Access吗? Access中的True甚至不等于1!


你在哪里得到它在Access中等于1的想法?

Access将boolean存储为true / false,


实际上,Access(Jet)存储0表示false / off / no和-1表示true / on / yes。

这是很容易找到你自己。创建一个包含单个Yes / No

字段的表,将一些数据放入其中,然后运行此sql语句:


select boolean_column,cint(boolean_column) as int_equivalent

来自yourtable

和MySQL将布尔值存储为1
和0,这就是我遇到此问题的原因。




我不使用MySQL,但我不认为MySQL有一个布尔数据类型;在

至少它不会与SQL Server类似,它有一点数据类型,

不是布尔值。你问,有什么区别?布尔值可以有两个值:

true或false。一点可以有3个可能的值:true,false或null。

OLE DB提供程序通常处理vbscript和sql之间的转换。

所以如果你运行对Access的查询,您将返回的数据视为

是本机vbscript布尔子类型。如果你对mysql或sql server使用
会发生同样的事情:bit数据类型将正确转换为
到vbscript布尔值。

-

Microsoft MVP - ASP / ASP.NET

请回复新闻组。这个电子邮件帐户是我的垃圾邮件陷阱所以我

不经常检查它。如果您必须离线回复,请删除

无垃圾邮件




" Bob巴罗斯[MVP]" <再****** @ NOyahoo.SPAMcom>在消息中写道

news:uq ************** @ TK2MSFTNGP03.phx.gbl ...

Jason写道:

我是ASP的新手 - 我已经使用了大约2个月。我做了这些测试(下面),对我来说没有意义。假等于0,这很好。真应该等于1,
但它不是。实际上,True应该等于False,null,
和0.
不,这不是它的工作方式。在vbscript中,如果表达式将
调整为-1,则该语句为真。否则,它是假的




我应该以不同的方式提出我的问题。这就是我所要求的

但是,如果VBscript遵循传统的真假定义。

是有一个解决方法吗?或者我需要将所有的比较改为= 1而不是= true?



嗯?你为什么要这么做?给我一个例子,说明
失败了,因为你说的是​​= true。而不是= -1




MySQL将true存储为1,而不是-1。

只是fyi,我我正在尝试将我们的数据库从Access转换为MySQL。
您熟悉Access吗? Access中的True甚至不等于1!




不熟悉Access,没有。

你从哪里得到的想法是在Access中它等于1?


我没有这么说,但它现在无关紧要了。

我不能使用MySQL,但我不是认为MySQL有一个布尔数据类型;至少它不是它与SQL Server类似,它有一点数据类型,不是布尔值。你问,有什么区别?布尔值可以有两个值:true或false。一点可以有3个可能的值:true,false或
null。


MySQL将布尔值存储为整数(我认为是无符号的),大一个字节。 0是

false,1是真。我还没有对此进行过测试,但我认为MySQL会将除0之外的任何值视为
为真。但是,当您将值存储为true时,它将存储为

为1.

OLE DB提供程序通常处理vbscript和sql之间的转换。
因此,如果您对Access运行查询,则会将返回的数据视为
是本机vbscript布尔子类型。如果你对mysql或sql server这样做会发生同样的事情:bit数据类型将被正确翻译为vbscript布尔值。




那就是问题,它没有被MySQL正确翻译。

我不确定我是否使用OLE DB。

这是我用来连接的代码:


Dim sConnection,mysqlConn

sConnection =" DRIVER = {MySQL ODBC 3.51 Driver}; SERVER = localhost;

DATABASE = myDB; UID =用户; PASSWORD =通过; OPTION = 3"

设置mysqlConn = Server.CreateObject(" ADODB.Connection")

mysqlConn.Open(sConnection)


那是使用OLE DB提供程序吗?


相关部分将是你如何将这些数据传递给MySQL而不是连接的价值比b / b
字符串...

您希望使用参数化查询而不是将文本填充到SQL

语句中(如果这是问题)。它将处理这个以及

,因为日期格式和十进制值可能出现问题,其文本为

依赖于国家/地区......


MySQL论坛可能是一个更好的地方(例如,如果这个东西

特定于你用于你的列的dat类型,这被定义为

布尔值还是整数?)...


-

Patrice


Jason < bigwheels16 hotmail> écritdansle message de news:
KO ********* @ comcast.com ...

Bob Barrows [MVP]" <再****** @ NOyahoo.SPAMcom>在消息中写道
新闻:uq ************** @ TK2MSFTNGP03.phx.gbl ...

Jason写道:

我对ASP很新 - 我已经使用了大约2个月。我做了这些测试(下面),对我来说没有意义。假等于0,这很好。真应该等于1,
但它不是。实际上,True应该等于False,
null和0。



不,这不是它的工作方式。在vbscript中,如果表达式将
调整为-1,则该语句为真。否则,它是假的



我应该以不同的方式表达我的问题。这就是我的要求
但是,如果VBscript遵循传统的定义为true和
false。

是有一个解决方法吗?或者我需要将所有的比较改为= 1而不是= true?



嗯?你为什么要这么做?给我一个例子,说明
失败了,因为你说的是​​= true。而不是= -1



MySQL将true存储为1,而不是-1。

只是fyi,我正在尝试将我们的数据库从Access转换为MySQL。



您熟悉Access吗? Access中的True甚至不等于1!



不熟悉Access,没有。


你在哪里得到它在Access中等于1的想法?



我没有这么说,但它现在无关紧要了。

我不使用MySQL,但我不认为MySQL有一个布尔数据类型;至少它不会与SQL Server类似,它有点像
datatype,而不是布尔值。你问,有什么区别?布尔值可以有两个值:true或false。一点可以有3个可能的值:true,false
或null。



MySQL将布尔值存储为整数(我认为是无符号的),一个字节大。 0
是假的,1是真的。我没有测试过这个,但我认为MySQL将0以外的任何值视为真。但是,当您将值存储为true时,它将存储为1.


OLE DB提供程序通常处理vbscript和 sql。因此,如果您对Access运行查询,则将返回的数据视为
,如果它是本机vbscript布尔子类型。如果你反对mysql或sql server,也会发生同样的事情:bit数据类型将被正确转换为vbscript布尔值。



那个''问题是,它没有被MySQL正确翻译。
我不确定我是否使用OLE DB。
这是我用来连接的代码:

Dim sConnection,mysqlConn
sConnection =" DRIVER = {MySQL ODBC 3.51 Driver}; SERVER = localhost;
DATABASE = myDB; UID =用户; PASSWORD =通过; OPTION = 3"
设置mysqlConn = Server.CreateObject(" ADODB.Connection")
mysqlConn.Open(sConnection)

是否使用OLE DB提供程序?



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. 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
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...500872d64f.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"



"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:uq**************@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?


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:
KO******************************@comcast.com...


"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:uq**************@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?



这篇关于(true = 1)返回false?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆