I have tried almost everything and nothing is working and I can't find anything relevant to this over the stackoverflow. My task is simple. I am trying to insert the data to the table and also reading back using python but I am not getting what is the issue. Here is my code. I have two functions in class one is this to insert the data.
async def insertDataIntoTable(self, username, email, password):
tableName = f'{self.config.get("TABLE_NAME")}'
query = f"INSERT INTO {tableName}(username, email, user_pass) VALUES (?, ?, ?)"
self.cursor.execute(query, (username, email, password))
results = self.cursor.fetchone()
self.database.commit()
print(results)
And I am getting the following output when I run the above function.
Traceback (most recent call last):
File "/home/virchual/python/discordBots/registerBot/extensions/maria.py", line 65, in <module>
ruc(maria.insertDataIntoTable('vir', 'em@gm', 'passy'))
File "/home/virchual/anaconda3/envs/discord/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
return future.result()
File "/home/virchual/python/discordBots/registerBot/extensions/maria.py", line 35, in insertDataIntoTable
results = self.cursor.fetchone()
mariadb.ProgrammingError: Cursor doesn't have a result set
It's not inserting it into the table I have checked through the terminal and I can insert data using the terminal.
Another function is to check if a user with the username exists in the table. The code is below.
async def userExistsWithUsername(self, username):
self.cursor.execute(
f"SELECT * FROM {self.config.get('TABLE_NAME')} WHERE username=?", (username,))
res = self.cursor.fetchone()
if res == None:
return False
return True
Here res is always None even if I insert data into the table using the terminal. It never finds that data in the table. Can someone please help?