Cmdlets for Couchbase

Build 21.0.7930

SELECT INTO ステートメント

SELECT INTO ステートメントを使って、書式付きデータをファイルにエクスポートできます。

SQL クエリを使ったデータのエクスポート

次のクエリは、comma-separated values(CSV)ファイルフォーマットにデータをエクスポートします。

C#

String connectionString = "User='myusername';Password='mypassword';Server='http://couchbase40'";

using (CouchbaseConnection connection = new CouchbaseConnection(connectionString)) {
  CouchbaseCommand cmd = new CouchbaseCommand("SELECT Name, TotalDue INTO [csv://Customer.txt] FROM [Customer] WHERE CustomerId = '12345' ", connection);
  int rowsAffected = cmd.ExecuteNonQuery();
} 

VB.NET

Dim connectionString As [String] = "User='myusername';Password='mypassword';Server='http://couchbase40'" 

Using connection As New CouchbaseConnection(connectionString)
  Dim cmd As New CouchbaseCommand("SELECT Name, TotalDue INTO [csv://Customer.txt] FROM [Customer] WHERE CustomerId = '12345'", connection)
  Dim rowsAffected As Integer = cmd.ExecuteNonQuery()
End Using
URI で他のファイルフォーマットを指定できます。以下の例は、tab-separated values(TSV)にエクスポートします。

C#

String connectionString = "User='myusername';Password='mypassword';Server='http://couchbase40'";

using (CouchbaseConnection connection = new CouchbaseConnection(connectionString)) {
  CouchbaseCommand cmd = new CouchbaseCommand("SELECT * INTO [Customer] IN [csv://filename=c:/Customer.csv;delimiter=tab] FROM [Customer] WHERE CustomerId = '12345'", connection);
  int rowsAffected = cmd.ExecuteNonQuery();
} 

VB.NET

Dim connectionString As [String] = "User='myusername';Password='mypassword';Server='http://couchbase40'" 

Using connection As New CouchbaseConnection(connectionString)
  Dim cmd As New CouchbaseCommand("SELECT * INTO [Customer] IN [csv://filename=c:/Customer.csv;delimiter=tab] FROM [Customer] WHERE CustomerId = '12345'", connection)
  Dim rowsAffected As Integer = cmd.ExecuteNonQuery()
End Using

Copyright (c) 2021 CData Software, Inc. - All rights reserved.
Build 21.0.7930