pythonでfoobarのalternativeを作る 9 version 1
:追加された部分
:削除された部分
(差分が大きい場合、文字単位では表示しません)
自分のPCの音楽ファイルをタグでデータベース化 9
結構簡単だった(・∀・)ノ
```
import wx ,sqlite3
import sqlviewer_ui
class MyFrame( sqlviewer_ui.MyFrame1 ):
def __init__( self, parent ):
sqlviewer_ui.MyFrame1.__init__( self, parent )
self.db=r'e:\Programs\python\_研究\database\database.db'
self.btn_refresh(0)
def btn_refresh( self, event ):
conn = sqlite3.connect( self.db )
c = conn.cursor()
c.execute("select * from sqlite_master where type='table'")
table=c.fetchone()[1] # 最初のテーブル名
des=c.execute('select * from {}'.format(table) ).description
colis=[item[0] for item in des]
i=0
nonull=[]
null=[]
for col in colis :
res=c.execute( 'select count(*) from {} where {} IS NULL'.format(table,colis[i]) )
null.append(res.fetchall()[0][0])
res=c.execute( 'select count(*) from {} where {} IS NOT NULL'.format(table,colis[i]) )
nonull.append(res.fetchall()[0][0])
i+=1
self.m_staticText1.SetLabel('DATABASE -- {}'.format(self.db))
self.m_staticText2.SetLabel(' Table -- {}'.format(table))
all=[colis,nonull,null]
line=''
for i in all:
for ii in i :
line += '{:>10}'.format(ii)
line += '\r\n'
self.m_textCtrl1.SetValue(line)
self.table=table
c.close()
conn.close()
def btn_go( self, event ):
col=self.m_textCtrl2.GetValue()
exp=self.m_textCtrl3.GetValue()
num=self.m_textCtrl4.GetValue()
line='select '+col+' from '+self.table+' where '+exp+' limit '+num
self.m_listBox1.Append(line)
conn = sqlite3.connect( self.db )
c = conn.cursor()
for l in c.execute(line):
self.m_listBox1.Append(l[0])
print(l)
c.close()
conn.close()
def btn_bye( self, event ):
quit()
if __name__ == '__main__':
app = wx.App(False)
frame = MyFrame(None)
frame.Show(True)
app.MainLoop()
```
結構簡単だった(・∀・)ノ
import wx ,sqlite3
import sqlviewer_ui
class MyFrame( sqlviewer_ui.MyFrame1 ):
def __init__( self, parent ):
sqlviewer_ui.MyFrame1.__init__( self, parent )
self.db=r'e:\Programs\python\_研究\database\database.db'
self.btn_refresh(0)
def btn_refresh( self, event ):
conn = sqlite3.connect( self.db )
c = conn.cursor()
c.execute("select * from sqlite_master where type='table'")
table=c.fetchone()[1] # 最初のテーブル名
des=c.execute('select * from {}'.format(table) ).description
colis=[item[0] for item in des]
i=0
nonull=[]
null=[]
for col in colis :
res=c.execute( 'select count(*) from {} where {} IS NULL'.format(table,colis[i]) )
null.append(res.fetchall()[0][0])
res=c.execute( 'select count(*) from {} where {} IS NOT NULL'.format(table,colis[i]) )
nonull.append(res.fetchall()[0][0])
i+=1
self.m_staticText1.SetLabel('DATABASE -- {}'.format(self.db))
self.m_staticText2.SetLabel(' Table -- {}'.format(table))
all=[colis,nonull,null]
line=''
for i in all:
for ii in i :
line += '{:>10}'.format(ii)
line += '\r\n'
self.m_textCtrl1.SetValue(line)
self.table=table
c.close()
conn.close()
def btn_go( self, event ):
col=self.m_textCtrl2.GetValue()
exp=self.m_textCtrl3.GetValue()
num=self.m_textCtrl4.GetValue()
line='select '+col+' from '+self.table+' where '+exp+' limit '+num
self.m_listBox1.Append(line)
conn = sqlite3.connect( self.db )
c = conn.cursor()
for l in c.execute(line):
self.m_listBox1.Append(l[0])
print(l)
c.close()
conn.close()
def btn_bye( self, event ):
quit()
if __name__ == '__main__':
app = wx.App(False)
frame = MyFrame(None)
frame.Show(True)
app.MainLoop()