I have this to insert match details into a matchhistory database, most of the time there won't be all 8 players participating, so some of the players will be set to None, when I try to run this it says, OperationalError: no such column: None is there a way for it ignore those values if I enter none? or is there a better way to do this.
#π inserting null data into database if some values are None
37 messages Β· Page 1 of 1 (latest)
@long shore
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
why are you using f strings?
I'm just testing stuff
you're leaving your database open to sql injection
I've already caught a few lectures on it
(almost) all sql libraries have sanitisation methods
sqlite uses question marks, postgres uses numbers preceded with dollar signs
so why include it?
lazy
also holy shit why is this all in one table
π€¦π½ββοΈ
could you have written this any longer
that the reason of the error
I could've made the varaible names longer
also you didnt include a traceback or a line number
was going to mention that the issue was probably not sanitising the query, then i saw the million different ways it can go wrong and was focused more on that
(there is also reason why you should do that every time, not matter if it just you using it
exactly
so I changed it to this, and one of my paramters is a UUID and it's saying
Ignoring exception in command mma submit:
Traceback (most recent call last):
File "C:\Users\Nvega\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\discord\commands\core.py", line 138, in wrapped
ret = await coro(arg)
^^^^^^^^^^^^^^^
File "C:\Users\Nvega\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\discord\commands\core.py", line 1078, in
_invoke
await self.callback(self.cog, ctx, **kwargs)
File "d:\Test\cogs\submit.py", line 50, in submit
await cursor.execute(f'''INSERT INTO matchhistory (type, player1, player2, player3, player4, player5, player6, player7, player8, team1score, team2score, wager, sponsor1, sponsor2, sponsor3, sponsor4, doubled, gameID, doubledteam1score, doubledteam2score) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)''', (type, player1, player2,player3, player4, player5, player6, player7, player8, team1score, team2score, wager, sponsor1, sponsor2, sponsor3, sponsor4, doubled, matchID, doubledteam1score, doubledteam2score))
File "C:\Users\Nvega\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\aiosqlite\cursor.py", line 48, in execute await self._execute(self._cursor.execute, sql, parameters)
File "C:\Users\Nvega\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\aiosqlite\cursor.py", line 40, in _execute
return await self._conn._execute(fn, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Nvega\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\aiosqlite\core.py", line 132, in _execute return await future
^^^^^^^^^^^^
File "C:\Users\Nvega\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\aiosqlite\core.py", line 115, in run
result = function()
^^^^^^^^^^
sqlite3.ProgrammingError: Error binding parameter 18: type 'UUID' is not supported
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Nvega\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\discord\bot.py", line 1137, in invoke_application_command
await ctx.command.invoke(ctx)
File "C:\Users\Nvega\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\discord\commands\core.py", line 435, in invoke
await injected(ctx)
File "C:\Users\Nvega\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\discord\commands\core.py", line 138, in wrapped
ret = await coro(arg)
^^^^^^^^^^^^^^^
File "C:\Users\Nvega\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\discord\commands\core.py", line 1486, in
_invoke
await command.invoke(ctx)
File "C:\Users\Nvega\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\discord\commands\core.py", line 435, in invoke
await injected(ctx)
File "C:\Users\Nvega\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\discord\commands\core.py", line 146, in wrapped
raise ApplicationCommandInvokeError(exc) from exc
discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: ProgrammingError: Error binding parameter 18: type 'UUID' is not supported```
?tag code
This is not a Modmail thread.
theres your issue then
whats a UUID?
a string
damn
never doing fstring bs again
thanks for the enlightment
so when I do it this way, does sqlite take the None before that it was saying was strings and interepting it as null now?
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.