MySQL Forums
Forum List  »  General

Re: Able to run statement in CLI and return a correct value but when run in a script it returns None
Posted by: Nick Davies
Date: November 01, 2021 10:50AM

Thank you for the suggestion but it's not a permissions issue as I use the same credentials in Grafana and they work. Only in the python script do I get the return as None

Here is relevant parts of the code from the script;
import mariadb
import sys

# Connect to MariaDB Platform
try:
conn = mariadb.connect(
user="*****",
password="*****",
host="localhost",
port=3306,
database="cryptodb"
)
cur = conn.cursor()

pricevar = "SELECT SUM(CASE type WHEN 'purchase' THEN TokenAmount WHEN 'sale' THEN -TokenAmount WHEN 'swap' THEN -TokenAmount WHEN 'gain' THEN TokenAmount END) FROM cryptotbl WHERE Token = '" + (data['data'][coin]['symbol'] + "'")
print(pricevar)
currentvalue = cur.execute(pricevar)

I've got a JSON payload that provides the coin symbol: (data['data'][coin]['symbol'])


I load the statement into the pricevar variable and then execute it, this is where it returns None.

All these steps work in the CLI so I'm not sure why I can't replicate that in the script.

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.