Execute sqlite3 “dot” commands from Python or register collation in command line utility

前端 未结 6 1143
轮回少年
轮回少年 2021-02-07 01:34

My sqlite3 database contains a \"collate\" column-constraint. I\'ve placed it in the schema for the table, to prevent accidentally neglecting to use the necessary collation. How

6条回答
  •  伪装坚强ぢ
    2021-02-07 02:02

    subprocess.run() is preferred oversubprocess.call(). Below is my answer:

    import subprocess
    schema = subprocess.run(
        ['sqlite3',
         'xxx.db',
         '.schema'
        ],
        capture_output=True
    ).output.decode('utf-8')
    
    print(schema)
    

提交回复
热议问题