Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
82 views
in Technique[技术] by (71.8m points)

python - How to store speacial symbols in SQLITE

This is my table

@client.event
async def on_ready():
    db = sqlite3.connect('Smilewin.sqlite')
    cursor = db.cursor()
    cursor.execute('''
        CREATE TABLE IF NOT EXISTS Introduce(
        guild_id TEXT,
        channel_id TEXT,
        boarder TEXT,
        status TEXT
        )
        ''')

enter image description here

I wanted to store anything from a normal text to something like this ☆? ゜?☆? ゜?☆? ゜?☆? ゜?☆? ゜?☆ (basically anything)

When I try to store ☆? ゜?☆? ゜?☆? ゜?☆? ゜?☆? ゜?☆ It is giving an error.

Traceback (most recent call last):
  File "C:UsersardilDesktopDesktop appANAPAHCodeReactV9Smilewin-envlibsite-packagesdiscordclient.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "c:UsersardilDesktopDesktop appANAPAHCodeReactV9SmileWinbot.py", line 618, in on_command_error
    raise error
  File "C:UsersardilDesktopDesktop appANAPAHCodeReactV9Smilewin-envlibsite-packagesdiscordextcommandsot.py", line 902, in invoke
    await ctx.command.invoke(ctx)
  File "C:UsersardilDesktopDesktop appANAPAHCodeReactV9Smilewin-envlibsite-packagesdiscordextcommandscore.py", line 864, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:UsersardilDesktopDesktop appANAPAHCodeReactV9Smilewin-envlibsite-packagesdiscordextcommandscore.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'str' object has no attribute 'text'

The code which I use to store that special symbols is:

@client.command()
@commands.has_permissions(administrator=True)
async def setboarder(ctx, *,boarder):
    db = sqlite3.connect('Smilewin.sqlite')
    cursor = db.cursor()
    cursor.execute(f"SELECT boarder FROM Introduce WHERE guild_id = {ctx.guild.id}")
    result = cursor.fetchone
    if result is None:
        sql = ("INSERT INTO Introduce(guild_id, boarder) VALUES(?,?)")
        val = (ctx.guild.id , boarder)
        embed = discord.Embed(
            colour= 0x00FFFF,
            title = "?????????????????????",
            description= f"?????????????????? {boarder}"
        )

        message = await ctx.send(embed=embed)
        await message.add_reaction('?')
    
    elif result is not None:
        sql = ("UPDATE Introduce boarder = ? WHERE guild_id = ?")
        val = (boarder , ctx.guild.id)
        embed = discord.Embed(
            colour= 0x00FFFF,
            title = "?????????????????????",
            description= f"???????????????????? {boarder}"
        )

        message = await ctx.send(embed=embed)
        await message.add_reaction('?')
        
    cursor.execute(sql, val)
    db.commit() 
    cursor.close()
    db.close()

I want to know is it possible to store that kind of data in sqlite. If yes how can I do it please provide some example. thank you so much

question from:https://stackoverflow.com/questions/65951534/how-to-store-speacial-symbols-in-sqlite

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There is an error in your update query which may or may not have some bearing on the problem.

"UPDATE Introduce boarder = ? WHERE guild_id = ?"

is missing the keyword SET. The statement should be:

"UPDATE Introduce SET boarder = ? WHERE guild_id = ?"

I don't see how the exception traceback relates to this problem. It also seems unrelated to whether the db can store your unicode strings; it can.

Try fixing this bug and see how you go.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...