dbListColumns

Version 23.4.8841


dbListColumns


データベースサーバーのテーブルまたはビューのカラムをリストします。Depending on your configuration and the target database type, some of these parameters and output attributes might not be relevant.

必要なパラメータ

  • driver:クロスプラットフォーム版ではJDBC ドライバーのクラス名、.NET 版ではADO.NET プロバイダー名。
  • conn:接続文字列、またはデータベースURL。
  • table:カラムをリストするテーブルまたはビュー。

オプションのパラメータ

  • schema:The name of the database schema in which the table resides.The schema is commonly referred to as the namespace of a group of tables.
  • catalog:The catalog in the database server. This is commonly referred to as the database. If you do not provide a value, columns from all catalogs in the database server are returned.

アウトプット属性

  • db:columnname:The name of the column in the specified table or view.
  • db:datatype:The SQL data type of the column in the specified table or view.
  • db:columnsize:The size of the column in the specified table or view.
  • db:iskey:Boolean (true or false) indicating if the column is the primary key column.
  • db:nullable:Boolean (true or false) indicating if the column is nullable.
  • db:readonly:Boolean (true or false) indicating if the column is read-only.
  • db:autoincrement:Boolean (true or false) indicating if the column is an autoincrement column.

例

In this example, the targeted database server is MySQL and the targeted table is actor. Notice that there is no database parameter in the connection string: if the database is specified in the connection string, the catalog parameter is not required. This script writes all the attributes of the target table to an output file.

<!-- 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
-----

Arc がインストールおよび実行されているマシンにドライバーがインストールされている場合に限り、上記の例を変更して別のデータベースを対象にすることができます。例を.NET 用に調整するには、driver とconn のインプットを次のように変更する必要があります。

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