[Python-es] consulta SQL

monoBOT monobot.soft en gmail.com
Vie Jun 18 13:50:40 CEST 2010


muchas gracias a los 2!!!


2010/6/18 Antonio Beamud Montero <antonio.beamud en gmail.com>

> monoBOT escribió:
>
>> Hola ... como puedo obtener la cantidad de columnas de una tabla?
>>
>> hice lo siguiente de modo rudimentario pero seguramente existe una forma
>> mucho mas directa ... alguna pista?
>>
>>
>> orden = 'SELECT * FROM nombretabla WHERE id = 1' cursor.execute(orden)
>>  for objeto in cursor:
>>    valor = len(objeto)-1
>> ------------------------------------------------------------------------
>>
>>
>>
>
> de http://www.python.org/dev/peps/pep-0249/:
>
> Cursor Objects should respond to the following methods and
>   attributes:
>
>       .description                     This read-only attribute is a
> sequence of 7-item
>           sequences.
>           Each of these sequences contains information describing
>           one result column:
>             (name,               type_code,               display_size,
>              internal_size,               precision,               scale,
>             null_ok)
>
>           The first two items (name and type_code) are mandatory,
>           the other five are optional and are set to None if no
>           meaningful values can be provided.
>
>           This attribute will be None for operations that
>           do not return rows or if the cursor has not had an
>           operation invoked via the .execute*() method yet.
>                      The type_code can be interpreted by comparing it to
> the
>
>
> Es decir, si haces len(cursor.description) te dice el total de columnas.
>
>
>
> _______________________________________________
> Python-es mailing list
> Python-es en python.org
> http://mail.python.org/mailman/listinfo/python-es
> FAQ: http://python-es-faq.wikidot.com/
>
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://mail.python.org/pipermail/python-es/attachments/20100618/e53ba03b/attachment.html>


Más información sobre la lista de distribución Python-es