B
B
beduin012016-03-01 13:55:22
Python
beduin01, 2016-03-01 13:55:22

Why SQL query returns None?

The essence of this is the request:

SELECT prod_type_id FROM "PROD_TYPE" WHERE prod_type_id=2

In the SQL editor, it returns the number 2. Now I call the same query in Python and it returns none. What is the reason?
currDst.execute(("""SELECT prod_type_id FROM "PROD_TYPE" WHERE prod_type_id=%s""") %prod_type_id)
      pt = currDst.fetchone()
      print "pt: ", pt # упорно возвращает pt:  None хотя заспрос содержит данные

56d5743e742a5.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Valery Ryaboshapko, 2016-03-01
@beduin01

Are you sure prod_type_id contains 2?
Well, and a mandatory recommendation that you do not need to collect SQL queries from strings, but you need to bind parameters.
Also, it looks like you are trying to mimic a JOIN in python code.

V
Vladimir Kuts, 2016-03-01
@fox_12

Try this when you raise the connection to the database:
connDst.autocommit(True)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question