Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
7037 Lượt xem

For odoo 8:::

Now using this I can get one value

sqary1="SELECT name FROM p_task where id ="+str(mem_id)

  str2= str(self.env.cr.fetchone()[0])

if my query is this:::::::::::::::             "SELECT ALL  FROM p_task"
then I get multiple values.How I can enter all this values in a python array?
what to write instead of str(self.env.cr.fetchone()[0]) to catch this multiple values in an array

TIA

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

You need create a cursor, then execute the instruction "fetchall()" and assign the result to a variable. Finally you can manipulate the collection of tuples:

sql=" select * from table "

cursor=conn_local.cursor()
cursor.execute(sql)
datos=cursor.fetchall()
cursor.close()
conn_local.close()

#Manipulation of the collection of tuples

if len(datos) > 0:

    for indice in range(len(datos)):
        fila= datos[indice]
        mensaje_salida=mensaje_salida + fila


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 3 15
5425
2
thg 5 24
1747
2
thg 5 24
1912
1
thg 5 21
4539
4
thg 10 19
10352