scieditor2 5 version 7

2019/09/03 23:27 by yamasyuh68
  :追加された部分   :削除された部分
(差分が大きい場合、文字単位では表示しません)
hoge 今日code sql
---
```
import os , sqlite3 , datetime

=======================
=======================
=======================
class openfiledb():
    def __init__(self):
        self.db=os.path.join(os.path.dirname(__file__) , 'openfile.db')
        conn = sqlite3.connect(self.db)
        c = conn.cursor()
        c.execute('create table IF NOT EXISTS database(path PRIMARY KEY,line,times,date)')
        c.close()
        conn.commit()
        conn.close()

=======================
    def save(self,fname,line):
        conn = sqlite3.connect(self.db)
        c = conn.cursor()
        date="{0:%Y%m%d}".format( datetime.datetime.now() )
        try:
            c.execute( "INSERT INTO database (path,line,times,date) VALUES (?,?,?,?)" , (fname,line,1,date ))
        except:
            c.execute('select  times from database where path = ?',(fname, ))
            times=c.fetchone()[0]+1
            print(times)
            c.execute('update database set line= ? ,times=? ,date=? where path = ? ', ( line, times, date ,fname ))
        c.close()
        conn.commit()
        conn.close()

=======================

```

      
import os , sqlite3 , datetime

class openfiledb():
    def __init__(self):
        self.db=os.path.join(os.path.dirname(__file__) , 'openfile.db')
        conn = sqlite3.connect(self.db)
        c = conn.cursor()
        c.execute('create table IF NOT EXISTS database(path PRIMARY KEY,line,times,date)')
        c.close()
        conn.commit()
        conn.close()

    def save(self,fname,line):
        conn = sqlite3.connect(self.db)
        c = conn.cursor()
        date="{0:%Y%m%d}".format( datetime.datetime.now() )
        try:
            c.execute( "INSERT INTO database (path,line,times,date) VALUES (?,?,?,?)" , (fname,line,1,date ))
        except:
            c.execute('select  times from database where path = ?',(fname, ))
            times=c.fetchone()[0]+1
            print(times)
            c.execute('update database set line= ? ,times=? ,date=? where path = ? ', ( line, times, date ,fname ))
        c.close()
        conn.commit()
        conn.close()