Simple sqlite question

When i use:

for i in Selection:
    Q = "SELECT columnA FROM DB WHERE wbcode='"+i+"' and commodity='1'"
    cursor.execute(Q)
    ydata[i] = cursor.fetchall()

I get:

ydata = {'GBR': [(u'695022',), (u'774291',), (u'791499',)... ]}

How can I change my code to get:

ydata = {'GBR': [695022, 774291, 791499,...]}

Many thanks. obs: this is just a simplified example. try to refrain from the recommendations for SQL injection.

+5
source share
2 answers
[int(x[0]) for x in cursor.fetchall()]
+4
source

Based on this and your other question, you need to understand the proximity of SQLite and how you populate the database. Other databases require the values ​​stored in the column to be of the same type β€” for example, all rows or all integers. SQLite allows you to store something so that the type in each row is different.

, , , . - , .

, SQLite , . , , , , / , SQLite , "1" 1, "1 1" "1 1".

, . , , .

http://www.sqlite.org/datatype3.html

CSV-, APSW ".help import", , .

+2

All Articles