I'm trying to store the employeeid value from employee table, to get the specific row I use the following command on Python:
cursor.execute("SELECT*FROM EMPLOYEE WHERE first_name = %s AND last_name = %s", (employee['firstname'],employee['lastname']))
followed by
employeeid=cursor.fetchone()[0]
why does employeeid have value Nonetype?
The reason fetchone()[0] returns None is almost certainly that the first column in the first row matching your WHERE clause has a NULL value.
Since you're just doing SELECT * rather than providing a column list, the first column could be any of the columns in the table. If you specifically want the employeeid column, you should SELECT employeeid.
Also, since you're not using ORDER BY, the first row could be any of the matching rows. So make sure there aren't multiple rows matching your WHERE clause (unless you expect there to be). It's possible that you have one "good" row with a value of 23, plus another "bad" row with a value of NULL.
As StefanPochmann points out, it's also possible that you didn't find any rows, and you've misinterpreted the results. If a query returns nothing, the fetchone() call will either return None, or raise an exception. In this first case, your statement would cause an error like TypeError: 'NoneType' object is not subscriptable, because cursor.fetchone()[0] is effectively doing None[0]. In the second case, the exception from fetchone itself might mention NoneType somewhere. In neither case is employeeid ending up with the value NoneType as you claim, but if you're not looking in the right place, you might have somehow convinced yourself that it is.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With