#πŸ”’ inserting null data into database if some values are None

37 messages Β· Page 1 of 1 (latest)

long shore
#

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.

rose oreBOT
#

@long shore

Python help channel opened

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.

long shore
#

I'm just testing stuff

plain spire
#

you're leaving your database open to sql injection

long shore
#

I've already caught a few lectures on it

plain spire
#

(almost) all sql libraries have sanitisation methods

#

sqlite uses question marks, postgres uses numbers preceded with dollar signs

plain spire
long shore
#

lazy

plain spire
plain spire
plain spire
fathom stirrup
long shore
#

I could've made the varaible names longer

fathom stirrup
#

when None parse literally, it is None in string

#

while in sql, None is null

plain spire
plain spire
fathom stirrup
plain spire
#

exactly

long shore
#

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```
slender frigateBOT
#

This is not a Modmail thread.

plain spire
#

fuck

#

!code

rose oreBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

plain spire
#

whats a UUID?

long shore
#

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?

rose oreBOT
#
Python help channel closed

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.