pythonでfoobarのalternativeを作る 8 version 1

2019/05/15 22:41 by yamasyuh68
  :追加された部分   :削除された部分
(差分が大きい場合、文字単位では表示しません)
自分のPCの音楽ファイルをタグでデータベース化 8
190515 の開発日記

DBの簡易ビューア
見るだけ、data取得は出来ない
```
import sqlite3

db=r'database.db'

conn = sqlite3.connect( db )
c = conn.cursor()
c.execute("select * from sqlite_master where type='table'")
table=c.fetchone()[1] # 最初のテーブル名
# print(table)

des=c.execute('select * from {}'.format(table) ).description
colis=[item[0] for item in des]
# print(colis)
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

print('DATABASE--{}'.format(db))
print('  TABLE --{}'.format(table))
print('')

all=[colis,nonull,null]
for i in all:
    for ii in i :
        print('{:>10}'.format(ii) , end='')
    print('')

c.close()
conn.close()
input('')
```
- コンソール、GUIはこれから

- **テーブルとカラムにプレースホルダーは使えない**らしい
でも`format`でいける
やっぱpythonからsqliteつかうのはやりづらいわ**┐('д')┌**
- 


      

190515 の開発日記

DBの簡易ビューア
見るだけ、data取得は出来ない

import sqlite3

db=r'database.db'

conn = sqlite3.connect( db )
c = conn.cursor()
c.execute("select * from sqlite_master where type='table'")
table=c.fetchone()[1] # 最初のテーブル名
# print(table)

des=c.execute('select * from {}'.format(table) ).description
colis=[item[0] for item in des]
# print(colis)
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

print('DATABASE--{}'.format(db))
print('  TABLE --{}'.format(table))
print('')

all=[colis,nonull,null]
for i in all:
    for ii in i :
        print('{:>10}'.format(ii) , end='')
    print('')

c.close()
conn.close()
input('')
  • コンソール、GUIはこれから

  • テーブルとカラムにプレースホルダーは使えないらしい
    でもformatでいける
    やっぱpythonからsqliteつかうのはやりづらいわ**┐('д')┌**