DataReader を使用したクエリ
CData ADO.NET Provider for Google Drive では、次の2つのネイティブ.NET インターフェースを使用して、Google Drive からデータを取得できます。GoogleDriveDataAdapter オブジェクトおよびGoogleDriveDataReader オブジェクト。各オブジェクトは同じタスク(データの取得)を実行しますが、実行方法が異なります。GoogleDriveDataAdapter オブジェクトはクエリに一致するすべてのデータを取得しますが、GoogleDriveDataReader オブジェクトは必要に応じてインクリメントしながら一部のデータだけをフェッチします。
GoogleDriveDataReader の使用
GoogleDriveDataReader はページ単位でデータを取得できるため、GoogleDriveDataAdapter よりもデータの取得が高速です。GoogleDriveDataReader からデータを読み取っていくと、必要に応じて一定の間隔で、データソースからの結果の次のページが要求されます。このため、結果が高速に返されます。 次の例は、Files テーブルからすべてのカラムを選択します。
C#
string connectionString = "InitiateOAuth=GETANDREFRESH;OAuthClientId=myClientId;OAuthClientSecret=myClientSecret;OAuthSettingsLocation=myOAuthSettings.txt;";
using (GoogleDriveConnection connection = new GoogleDriveConnection(connectionString)) {
GoogleDriveCommand cmd = new GoogleDriveCommand("SELECT * FROM Files", connection);
GoogleDriveDataReader rdr = cmd.ExecuteReader();
while (rdr.Read()) {
Console.WriteLine(String.Format("\t{0} --> \t\t{1}", rdr["Id"], rdr["Name"]));
}
}
VB.NET
Dim connectionString As String = "InitiateOAuth=GETANDREFRESH;OAuthClientId=myClientId;OAuthClientSecret=myClientSecret;OAuthSettingsLocation=myOAuthSettings.txt;"
Using connection As New GoogleDriveConnection(connectionString)
Dim cmd As New GoogleDriveCommand("SELECT * FROM Files", connection)
Dim rdr As GoogleDriveDataReader = cmd.ExecuteReader()
While rdr.Read()
Console.WriteLine([String].Format(vbTab & "{0} --> " & vbTab & vbTab & "{1}", rdr("Id"), rdr("Name")))
End While
End Using