Sunday, 29 November 2020

Avoid None in cursor.description?

I'm using sqlite3 in Python.

My table :

cursor.execute("""create table student(rno int, name char(20), grade char, gender char, avg decimal(5,2), dob date);""")

Where cursor is the name of my cursor object ...

I've used cursor.description to display the column names. But there are seven strings in each tuple in which six are None

print(cursor.description)
Output : (('rno', None, None, None, None, None, None), ('name', None, None, None, None, None, None), ('grade', None, None, None, None, None, None), ('gender', None, None, None, None, None, None), ('avg', None, None, None, None, None, None), ('dob', None, None, None, None, None, None))

From API, it is clear that first two elements of each tuple is must.

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.

But it's not for me. Why?

EDIT : I've the following records :

cursor.execute('select * from student')
Output : 
(1, 'BASKAR', 'C', 'M', 75.2, '1998-05-17')
(2, 'SAJINI', 'A', 'F', 95.6, '2002-11-01')
(3, 'VARUN', 'B', 'M', 80.6, '2001-03-14')
(4, 'PRIYA', 'A', 'F', 98.6, '2002-01-01')
(5, 'TARUN', 'D', 'M', 62.3, '1999-02-01')
(6, 'for_date', 'A', 'F', 99, '2001-12-23')

Still the output of cursor.description remains same.

Also what changes shall I make in my table to get the values for the other elements which are set as None???

Any relavant help is appreciated....



from Avoid None in cursor.description?

No comments:

Post a Comment