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

问题描述 投票:0回答:2

我使用python创建了一些sqlite表模式。

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

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

sql python-3.x sqlite database-schema
2个回答
3
投票

在最新版本(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
);

1
投票

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

> .header on
> .mode column
> pragma table_info('table_name');

给出输出:

    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
© www.soinside.com 2019 - 2024. All rights reserved.