> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kasoftware.com/llms.txt
> Use this file to discover all available pages before exploring further.

# dbListColumns

> 列出数据库服务器上表或视图中的列。

export const siteNameShort = "知行之桥";

列出数据库服务器上的表或视图中的列。根据配置和目标数据库类型，其中一些参数和输出属性可能不相关。

## 必需的参数

* **driver**：跨平台版本中的 JDBC 驱动程序类名称，或 .NET 版本中的 ADO.NET 提供程序名称。
* **conn**：连接字符串或数据库 URL。
* **table**：从中列出列的表或视图。

## 可选的参数

* **schema**：表所在的数据库 Schema 名称。该 Schema 通常称为一组表的 *命名空间*。
* **catalog**：数据库服务器中的 Catalog。这通常称为 *数据库*。如果不提供值，则返回数据库服务器中所有 Catalog 的列。

## 输出属性

* **db:columnname**：指定表或视图中的列名称。
* **db:datatype**：指定表或视图中列的 SQL 数据类型。
* **db:columnsize**：指定表或视图中列的大小。
* **db:iskey**：布尔值（true 或 false），指示该列是否为主键列。
* **db:nullable**：布尔值（true 或 false），指示该列是否可为 null。
* **db:readonly**：布尔值（true 或 false），指示该列是否为只读。
* **db:autoincrement**：布尔值（true 或 false），指示该列是否为自动增量列。

## 示例

在此示例中，目标数据库服务器是 MySQL，目标表是 `actor`。请注意，连接字符串中没有 `database` 参数：如果在连接字符串中指定了数据库，则不需要 `catalog` 参数。此脚本将目标表的所有属性写入输出文件。

```xml theme={null}
<!-- Initializing the output item -->
<arc:set attr="output.data" />
<!-- Creating the input db item and the necessary attributes -->
<arc:set attr="db.driver" value="cdata.jdbc.mysql.MySQLDriver" />
<arc:set attr="db.catalog" value="sakila" />
<arc:set attr="db.table" value="actor" />
<arc:set attr="db.conn" value="jdbc:cdata:mysql:server=localhost;port=3306;user=root;password=Password123;"/>

<arc:call op="dbListColumns" in="db" out="results" >
  <!-- adding result data from the operation to an output item that will be pushed out as a file -->
  <arc:set attr="output.data">[output.data]\nColumn Name=[results.db:columnname]\nData Type=[results.db:datatype]\nSize=[results.db:columnsize]\nKey=[results.db:iskey]\nNullable=[results.db:nullable]\nReadOnly=[results.db:readonly]\nAutoInc=[results.db:autoincrement]\n-----</arc:set>
</arc:call>

<!-- setting the filename and pushing the file out --> 
<arc:set attr="output.filename" value="results.txt" />
<arc:push item="output" />
```

输出：

```
Column Name=actor_id
Data Type=SMALLINT UNSIGNED
Size=2
Key=True
Nullable=False
ReadOnly=False
AutoInc=True
-----
Column Name=first_name
Data Type=VARCHAR
Size=45
Key=False
Nullable=False
ReadOnly=False
AutoInc=False
-----
Column Name=last_name
Data Type=VARCHAR
Size=45
Key=False
Nullable=False
ReadOnly=False
AutoInc=False
-----
Column Name=last_update
Data Type=TIMESTAMP
Size=19
Key=False
Nullable=False
ReadOnly=False
AutoInc=False
-----
```

只要在安装并运行 {siteNameShort} 的计算机上安装了驱动程序，就可以修改上面的示例以定位其他数据库。针对 .NET 调整此示例时，需要按如下方式更改 `driver` 和 `conn` 输入：

```xml theme={null}
<arc:set attr="db.driver" value="System.Data.CData.MySql" /> 
<arc:set attr="db.conn" value="Server=localhost;Database=sakila;UID=root;Password=Password123;"/>
```
