Aug-31-2017, 12:33 AM
I've started to experiment with python database and have the simple demo below working.
BUT, I'm concerned about the date column in the table... it seems to print OK but is the data "type" really a date type?
I ask because I read here http://www.cs.toronto.edu/~nn/csc309/gui...nsFIN.html
that the sql date data type format should be yyyy-mm-dd
BUT, if you notice in the code I inadvertently entered the date as month/day/year...
SO, the question is did the date go in the record as a date or as a string or what?
How do I have Python print out the data type for each column in a table?
This is important later when you attempt to sort by or search for a date or whatever.
Thanks for any help.
BUT, I'm concerned about the date column in the table... it seems to print OK but is the data "type" really a date type?
I ask because I read here http://www.cs.toronto.edu/~nn/csc309/gui...nsFIN.html
that the sql date data type format should be yyyy-mm-dd
BUT, if you notice in the code I inadvertently entered the date as month/day/year...
SO, the question is did the date go in the record as a date or as a string or what?
How do I have Python print out the data type for each column in a table?
This is important later when you attempt to sort by or search for a date or whatever.
Thanks for any help.
import sqlite3 connection = sqlite3.connect('demo.db') cursor = connection.cursor() cursor.execute ("CREATE TABLE tableA(id integer primary key not null, Name varchar2(25), Date date, notes varchar2(200))") connection.commit() cursor.execute ("INSERT INTO tableA values(1,'Elvis','8/29/17','bla bla bla')") cursor.execute ("INSERT INTO tableA values(2,'Sting','8/31/17','do da do da day')") connection.commit() cursor.execute ("SELECT * FROM tableA") while True: row = cursor.fetchone() if row == None: break print (row[0],row[1],row[2])