SQL を使用した一括更新
動詞: sqlBulkUpdate
以下から使用可能: < Enterprise>
データ表にマッピングしたデータを使用して、SQL データベース表を更新します。ただし、データ表の ID がデータベース表の ID と同じ場合にのみ更新します。
構文
sqlBulkUpdate --dataTable(DataTable) --connection(DbConnection) --tablename(String) [--batchsize(Numeric)] [--mappings(String)] [--timeout(TimeSpan)] (Boolean)=value
入力
| スクリプト | Designer | 必須 | 許容タイプ | 説明 |
|---|---|---|---|---|
| --dataTable | データ表 | 必須 | データ表 | SQL データベース表と比較するデータ表。 |
| -- 接続 | 接続 | 必須 | データベース接続 | データベース接続の変数。 有効な接続ストリングを使用したデータベース接続が必要です。 オプション: |
| --tablename | 表名 | 必須 | テキスト | データを更新する既存の SQL 表の名前。 |
| --batchsize | バッチ・サイズ | オプション | 数値 | 一度に更新された表の行数。 1 以上の数値を入力する必要があります。 |
| --mappings | マッピング | オプション | テキスト | SQL 表の値を使用した、指定された 「データ表」 列のマッピング。 新規マッピングを追加すると、以下のフィールドが表示されます。- 列名: マップする 「データ・テーブル」 列の名前。- 列番号: マップする 「データ・テーブル」 列の番号。 列番号は 1 から始まります。-名前なしフィールド: SQL 表の列名を参照します。「列名」または「列番号」のどちらか一方のフィールドにのみ、値を入力する必要があります。 |
| -- タイムアウト | タイムアウト | オプション | 時間幅、数値、テキスト | コマンド実行の最大待機時間。 |
出力
| スクリプト | Designer | 許容タイプ | 説明 |
|---|---|---|---|
| 値 | 成功 | Boolean | データベース表が正常に更新された場合は「True」が返され、そうでない場合は「False」が返されます。 |
例
Excel 表にマッピングしたデータのうち、ID が表の主キーと同じものを使用して、データベース表を更新します。
defVar --name sqliteConnection --type DbConnection
defVar --name booksTable --type DataTable
defVar --name bookContentTableFile --type DataTable
defVar --name excelFileBooks --type Excel
defVar --name updateResult --type Boolean
// Download the following file to execute the command.
// Connect to the DB.
sqliteConnect --connectionString "Data Source=bdTechnologyUpdate.db;Version=3;UseUTF16Encoding=True;" sqliteConnection=connection
// Execute a query with SELECT to display the book table.
sqlExecuteReader --connection ${sqliteConnection} --statement "SELECT * FROM books;" booksTable=value
logMessage --message "${booksTable}" --type "Info"
// Book table contents before update:
// 1, The Mater Algorithm: How the Search for the Ultimate Machine Learnig Algorithm Recreated Our Universe, Pedro Domingos, Novatec, 344
// 2, Steve Jobs, Walter Isaacson, Companhia das Letras, 624
// 3, Elon Musk: How spacex and tesla's billionarie CEO is shaping our world, Ashlee Vance, Intrínseca, 416
// 4, Brief answers to big questions, Stephen Hawking, Intrínseca, 256
// Download the following file to execute the command.
// Open the Excel file.
excelOpen --file "excelTableDataBooksUpdate.xlsx" excelFileBooks=value
// Get the table in Excel.
excelGetTable --file ${excelFileBooks} --getfirstsheet --entiretable --hasheaders bookContentTableFile=value
// Updates publisher names and number of pages.
sqlBulkUpdate --dataTable ${bookContentTableFile} --connection ${sqliteConnection} --tablename books --mappings "number=4=publisher,number=5=numPage,number=1=idBook" updateResult=value
sqlExecuteReader --connection ${sqliteConnection} --statement "SELECT * FROM books" booksTable=value
logMessage --message "${booksTable}" --type "Info"
// Book table contents after update:
// 1, The Mater Algorithm: How the Search for the Ultimate Machine Learnig Algorithm Recreated Our Universe, Pedro Domingos, Novatec, 344
// 2, Steve Jobs, Walter Isaacson, Companhia das Letras, 624
// 3, Elon Musk: How spacex and tesla's billionarie CEO is shaping our world, Ashlee Vance, Intrínseca, 416
// 4, Brief answers to big questions, Stephen Hawking, Intrínseca, 256
ファイルのダウンロード-bdTechnologyUpdate.db
上記のスクリプトを正しく操作するには、ファイルをダウンロードし、最初のファイルのパスを SQLite Connection コマンドの Connection String パラメーターに挿入する必要があります。 および 「Excel ファイルを開く」 コマンドの File パラメーターの 2 番目のパス。