我用UPDATE
、 、执行了不同的命令SELECT
,INSERT
并且不理解光标和 conn 之间的区别。两者的工作原理相同。你能解释一下吗
ia_prosto_coder
Asked:
2023-09-19 17:21:11 +0000 UTC
有一个员工表,其中有一个 fio 字段。文本。结果表中有字段sender_id 和receiver_id。两者都是整数。当尝试创建视图时
CREATE VIEW "problem_list_view" AS
select problem_list.id,
problem_list.date_start,
users.fio as fio_sender,
problem_list.problem_text,
problem_list.solution_text,
users.fio as fio_reciever,
problem_list.date_end,
statuses.name as status
from problem_list
left JOIN users on problem_list.sender_id = users.id
left join users on problem_list.receiever_id = users.id
left join statuses on problem_list.status_id = statuses.id
我得到错误模糊列名: And this is clear to me, sql indicates ambiguity. 我在结果表中添加了两个字段 fio_s 和 fio_r,这样就会有区别。
CREATE VIEW "problem_list_view" AS
select problem_list.id,
problem_list.date_start,
users.fio_s as fio_sender,
problem_list.problem_text,
problem_list.solution_text,
users.fio_r as fio_reciever,
problem_list.date_end,
statuses.name as status
from problem_list
left JOIN users on problem_list.sender_id = users.id
left join users on problem_list.receiever_id = users.id
left join statuses on problem_list.status_id = statuses.id
但我遇到了同样的错误。现在我不明白了。领域不同。告诉我哪里出了问题以及如何正确解决这个问题
Вишнуджан Вайнштэйн
Asked:
2022-08-19 23:56:13 +0000 UTC
sql3 = ("""SELECT password FROM inut_regist WHERE password =(?)""") cursor.execute(sql3, [user_password])
sql4 = ('''SELECT login FROM inut_regist WHERE login =(?)''')
cursor.execute(sql4, [user_login])
if :
self.label.setText('Ошибка авторизации!')
else:
self.label.setText('Успешная авторизация!')
heyman
Asked:
2022-08-17 15:25:23 +0000 UTC
我在不和谐中有自己的机器人,如果用户不在数据库中,那么他必须在那里输入,但我无法在 on_message 事件中弄清楚如何做到这一点。
@bot.event
async def on_message(message):
if cursor.execute(f"SELECT id FROM users WHERE id = {message.author.id}").fetchone()[0] is None:
cursor.execute(f"INSERT INTO users VALUES ({message.author.id}, 100, 'Нету', 0, 0)")
conn.commit()
cursor.execute(f"INSERT INTO inventory VALUES ({message.guild.id}, {message.author.id}, '')")
else:
pass
bot.process_commands(message)
检查用户是否有 id 时出错。但是如果它抛出错误,我如何检查它是否为 None
Traceback (most recent call last):
File "C:\Users\semnf\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "c:\Users\semnf\OneDrive\Рабочий стол\DiscBot\hello.py", line 62, in on_message
if cursor.execute(f"SELECT id FROM users WHERE id = {message.author.id}").fetchone()[0] is None:
TypeError: 'NoneType' object is not subscriptable
Timoha
Asked:
2022-07-17 21:31:27 +0000 UTC
这是我的代码:
import discord
from discord.ext import commands
import sqlite3
from config import settings
client = commands.Bot(command_prefix = settings['PREFIX'])
client.remove_command('help')
connection = sqlite3.connect('server.db')
cursor = connection.cursor()
@client.event
async def on_ready():
cursor.execute("""CREATE TABLE IF NOT EXISTS users (
name TEXT,
id INT,
cash BIGINT,
rep INT,
lvl INT
)""")
connection.commit()
for guild in client.guilds:
for member in guild.members:
cursor.execute(f"SELECT id FROM users where id={member.id}")
if cursor.fetchone() is None:
cursor.execute(f"INSERT INTO users (name, id, cash, rep, lvl) VALUES ('{member}', {member.id}, 0, 0, 1)")
connection.commit()
else:
pass
print('Бот готов к работе!')