Shane Morris
Shane Morris

Reputation: 95

Python SQLite Return Value

I am trying to return a numeric value from this statement:

c = db.execute("""SELECT *, rowid FROM members WHERE barcode = '%s' AND debit > 0 LIMIT 50""" % (s,))

But I get this as the returned value:

sqlite3.Cursor object at 0xb6cb2720

What should I do with this cursor object to get the results?

Upvotes: 3

Views: 19267

Answers (4)

Shane Morris
Shane Morris

Reputation: 95

One of my problems was, I was using the wrong SQL query to get the data I wanted. See:

c = db.execute("""SELECT "debit" FROM "members" WHERE "barcode" = '%s' LIMIT 1""" % (s,))

I would then get the response:

(0,)

Which was what I needed. Now to actually work out how to compare it - I need to say "if c is not equal to (0,) then print 'cross' else print 'tick'..."

Upvotes: 0

VitOk
VitOk

Reputation: 1

I just convert to list of tuples

sql="SELECT *, rowid FROM members WHERE barcode = '%s' AND debit > 0 LIMIT 50" % (s,)
c = list(db.execute(sql)

Upvotes: 0

Issac_n
Issac_n

Reputation: 89

try this>>print(cursorObject.fetchone()[0])

Upvotes: 0

chishaku
chishaku

Reputation: 4643

Try this:

for row in c:
    print row['rowid']

Upvotes: 4

Related Questions