dissabte, 17 de febrer del 2018



PlyGround with Python 1

how easy is python and sqlite3

import sqlite3
import datetime

def createDataBase():
conn = sqlite3.connect('control.db')
c = conn.cursor()
c.execute('create table control( nombre TEXT, fechaini timestamp, fechafin timestamp)')
c.close()

def pupulateDataBase():
conn = sqlite3.connect('control.db')
c = conn.cursor()
c.execute('insert into control values (?,?,?)',('registro 1',datetime.datetime.now(),datetime.datetime.now()))
conn.commit()
conn.close()

def pupulateDataBaseWhitNull():
conn = sqlite3.connect('control.db')
c = conn.cursor()
c.execute('insert into control values (?,?,?)',('registro 1',datetime.datetime.now(),None))
conn.commit()
conn.close()
def fetchDataBase():
conn = sqlite3.connect('control.db')
c = conn.cursor()
for row in c.execute('SELECT * FROM control'):
print(row)


createDataBase()
pupulateDataBase()
pupulateDataBaseWhitNull()
fetchDataBase()


(test) C:\Users\jordi\jordi\workspaces\python\test>python testsqlite.py
('registro 1', '2018-02-17 10:48:47.235088', '2018-02-17 10:48:47.235088')
('registro 1', '2018-02-17 10:48:47.354523', None)

Cap comentari:

Publica un comentari a l'entrada