الحصول على معلومات العمود في cx_oracle عندما يكون الجدول فارغا؟
سؤال
أنا أعمل على معالج لوحدة تسجيل بيثون. هذا يسجل أساسا إلى قاعدة بيانات أوراكل.
أنا أستخدم cx_oracle، وشيء لا أعرف كيفية الحصول عليه هو قيم الأعمدة عندما يكون الجدول فارغا.
cursor.execute('select * from FOO')
for row in cursor:
# this is never executed because cursor has no rows
print '%s\n' % row.description
# This prints none
row = cursor.fetchone()
print str(row)
row = cursor.fetchvars
# prints useful info
for each in row:
print each
الإخراج هو:
None
<cx_Oracle.DATETIME with value [None, None, None, None, None, None, None, None, None, None, None, None, None, None, None
, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None
, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None]>
<cx_Oracle.STRING with value [None, None, None, None, None, None, None, None, None, None, None, None, None, None, None,
None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None,
None, None, None, None, None, None, None, None, None, None, None, None, None, None, None]>
الآن النظر إلى بيانات Var يمكنني أن أرى أنواع البيانات، وأحجامها (عد عدم التسجيل؟) ولكن هذا مفقود اسم العمود.
كيف يمكنني الذهاب حول هذا؟
المحلول
اعتقد ان description
قد تكون السمة ما تبحث عنه. يرجع هذا قائمة من tuples التي تصف أعمدة البيانات التي تم إرجاعها. إنه يعمل بسعادة شديد إذا لم تكن هناك صوف عاد، على سبيل المثال:
>>> استيراد cx_oracle >>> c = cx_oracle.connect ("اسم المستخدم"، "كلمة المرور") >>> cr = c.cursor () >>> cr.Execute ("حدد * من المزدوج حيث 1 = 0") <__ المدمج __. OracleCursor علىu003Ccx_Oracle.Connection to user username@local> >>>> cr.Description [('dummy'،u003Ctype 'cx_Oracle.STRING'> ، 1، 1، 0، 0، 1)
لا تنتمي إلى StackOverflow