RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题

问题[sqlite3]

Martin Hope
Nqweqweqwe
Asked: 2024-01-17 17:02:17 +0000 UTC

sqlite3 `cursor.execute()` 和 `conn.execute()` 有什么区别?

  • 6

我用UPDATE、 、执行了不同的命令SELECT,INSERT并且不理解光标和 conn 之间的区别。两者的工作原理相同。你能解释一下吗

sqlite3
  • 2 个回答
  • 37 Views
Martin Hope
ia_prosto_coder
Asked: 2023-09-19 17:21:11 +0000 UTC

创建其中两个字段引用同一个表的 VIEW 时,列名不明确

  • 5

有一个员工表,其中有一个 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

但我遇到了同样的错误。现在我不明白了。领域不同。告诉我哪里出了问题以及如何正确解决这个问题

sqlite3
  • 1 个回答
  • 16 Views
Martin Hope
Вишнуджан Вайнштэйн
Asked: 2022-08-19 23:56:13 +0000 UTC

如何检查数据库中是否有数据输入

  • 0

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('Успешная авторизация!')
python sqlite3
  • 1 个回答
  • 18 Views
Martin Hope
heyman
Asked: 2022-08-17 15:25:23 +0000 UTC

将用户添加到 sqlite3 数据库

  • 0

我在不和谐中有自己的机器人,如果用户不在数据库中,那么他必须在那里输入,但我无法在 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

discord.py sqlite3
  • 1 个回答
  • 16 Views
Martin Hope
Timoha
Asked: 2022-07-17 21:31:27 +0000 UTC

如何将所有用户添加到数据库中?仅输入机器人。Discord.py 和 Sqlite3

  • 0

这是我的代码:

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('Бот готов к работе!')

问题是只有创建的机器人被输入到我的数据库中。 在此处输入图像描述 其他参与者没有进入,尽管他们似乎是。帮忙求求!!

python sqlite3
  • 1 个回答
  • 132 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5