如何使用SQLite3格式化.schema输出?

Sté*_*ane 1 sql sqlite database-schema python-3.x

我使用python创建了一些sqlite表架构。

当我使用sqlite3客户端并发出.schema命令时,我可以看到输出已预先格式化,如用作该executescript()函数参数的SQL源文件中所示。

有什么方法可以用来格式化.schema命令的输出?

rav*_*int 5

在最新版本(3.13.0)中,您拥有

>sqlite3 test.dat
SQLite version 3.13.0 2016-05-18 10:57:30

sqlite> create table test ( a integer,b integer, c integer,d float,e text, f primary key);

sqlite> .schema
CREATE TABLE test ( a integer,b integer, c integer,d float,e text, f primary key);

sqlite> .schema --indent
CREATE TABLE test(
  a integer,
  b integer,
  c integer,
  d float,
  e text,
  f primary key
);
Run Code Online (Sandbox Code Playgroud)


Evh*_*vhz 5

我也在为此寻找解决方案。
命令:

> .header on
> .mode column
> pragma table_info('table_name');
Run Code Online (Sandbox Code Playgroud)

给出输出:

    cid         name        type         notnull     dflt_value  pk
----------  ----------  -----------  ----------  ----------  ----------
0           id          varchar(24)  1                       1
1           uuid        varchar(36)  1                       0
2           title       varchar(200  1                       0
3           slug        varchar(191  1                       0
Run Code Online (Sandbox Code Playgroud)

  • 或者你可以像这样运行 sqlite:`sqlite3 --column --header` (2认同)