无法通过一列名称选择现有行
我有一个 sqlite3 数据库,其中有一个名为 users
的表。该表有一个名为 activation_token
的列,其类型为 VARCHAR(255)
。
该表中有一行填充了该列,
900395b3d2faf7d553f719df666d1a755fb7aef0
我希望以下内容返回该记录,但我没有得到任何输出:
SELECT * FROM users
WHERE activation_token = '900395b3d2faf7d553f719df666d1a755fb7aef0';
事实上,这个命令的输出真的让我感到困惑,
SELECT activation_token FROM users
where activation_token != '900395b3d2faf7d553f719df666d1a755fb7aef0';
900395b3d2faf7d553f719df666d1a755fb7aef0
我做错了什么?
.schema users
的输出,以验证我获得的列名称是否正确:
CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "email" varchar(255), "crypted_password" varchar(255), "salt" varchar(255), "created_at" datetime, "updated_at" datetime, "remember_me_token" varchar(255) DEFAULT NULL, "remember_me_token_expires_at" datetime DEFAULT NULL, "activation_state" varchar(255) DEFAULT NULL, "activation_token" varchar(255) DEFAULT NULL, "activation_token_expires_at" datetime DEFAULT NULL, "reset_password_token" varchar(255) DEFAULT NULL, "reset_password_token_expires_at" datetime DEFAULT NULL, "reset_password_email_sent_at" datetime DEFAULT NULL, "last_login_at" datetime DEFAULT NULL, "last_logout_at" datetime DEFAULT NULL, "last_activity_at" datetime DEFAULT NULL, "failed_logins_count" integer DEFAULT 0, "lock_expires_at" datetime DEFAULT NULL);
CREATE INDEX "index_users_on_activation_token" ON "users" ("activation_token");
CREATE INDEX "index_users_on_last_logout_at_and_last_activity_at" ON "users" ("last_logout_at", "last_activity_at");
CREATE INDEX "index_users_on_remember_me_token" ON "users" ("remember_me_token");
SELECT '->' 的输出||激活令牌 || '<-' FROM users;
来验证没有空格:
->900395b3d2faf7d553f719df666d1a755fb7aef0<-
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要检查 activate_token 列中实际存在的值,我建议执行以下操作:
如果值的开头或结尾有一些空格,百分号应该显而易见。
To check what value is actually in the activation_token column I would recommend the following:
The percent signs should make it obvious if there is some whitespace at the beginning or end of the value.
您的
activation_token
值为'900395b3d2faf7d553f719df666d1a755fb7aef0'
,其尾随有一些空格。例如:SQLite 邮件列表中的这篇文章可能会引起您的兴趣:
PostgreSQL 9 表现出相同的行为,MySQL 5.1 保留空格但忽略它们进行比较;可能有配置选项可以改变这种行为。我没有其他方便的东西,所以我无法检查其他任何东西。
You have an
activation_token
value that is'900395b3d2faf7d553f719df666d1a755fb7aef0'
with some trailing spaces on it. For example:This post from the SQLite mailing list might be of interest:
PostgreSQL 9 exhibits the same behavior, MySQL 5.1 preserves the spaces but ignores them for comparisons; there may be configuration options to alter this behavior. I don't have anything else handy so I can't check any others.
在第二个查询中,您
SELECT
名为activation_code
的列,同时根据activation_token
进行限制。我认为您同时存在这两列,并且在您的查询中混淆了它们。In your second query, you
SELECT
a column calledactivation_code
while you restrict based onactivation_token
. I think you have both columns present and confuse them in your queries.