简体   繁体   English

在选择语句中更新mysql

[英]Update mysql in select statement

my problem is easy to explain: In my config file from pure-ftp there is only one INSERT-Statement allowed to read the password. 我的问题很容易解释:在纯ftp的配置文件中,只有一个INSERT-Statement允许读取密码。 It is like this: 就像这样:

SELECT password FROM ftpuser WHERE userid = "\L"

"\\L" is the placeholder for the userid. “ \\ L”是用户标识的占位符。 It works perfectly, but I need to count the access to the ftp-server. 它工作正常,但是我需要计算对ftp服务器的访问量。 There is a field in this table called "accessed". 该表中有一个称为“已访问”的字段。 So I need to run this SQL, too: 因此,我也需要运行以下SQL:

UPDATE ftpuser SET accessed = accessed + 1 WHERE userid = "\L"

Is there any way to bring this two statements to one, with "password" as result? 有什么办法可以将这两个语句合而为一,结果是“ password”? Or is there another way to trigger the access from pure-ftp, maybe? 还是有另一种方法可以触发来自纯FTP的访问? Thank you very much! 非常感谢你!

Sebastian 塞巴斯蒂安

If it's a question of preserving atomicity, then provided your table is stored using a transactional engine (eg InnoDB), you can wrap the whole thing in a transaction with a locking read : 如果是保留原子性的问题,那么如果您的表是使用事务引擎(例如InnoDB)存储的,则可以将整个内容包装在具有锁定读取的事务中:

START TRANSACTION;
SELECT password FROM ftpuser WHERE userid = '\L' FOR UPDATE;
UPDATE ftpuser SET accessed = accessed + 1 WHERE userid = '\L';
COMMIT;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM