通过select语句查询表中数据。
说明 关于select语句的更多信息,请参见查询数据。
前提条件
参数
参数 | 说明 |
---|---|
query | SQL语句,请根据所需功能进行设置。 |
示例
使用select pk0,pk1,col0,col1,date_col,geo_col from test_table limit 20
语句查询test_table表中数据且最多返回20行数据。系统会返回查询语句的请求类型、返回值Schema、返回结果等信息。
/// <summary>
/// 查询数据。
/// </summary>
/// <param name="otsClient"></param>
public static void QueryData(OTSClient otsClient)
{
SQLQueryRequest sqlQueryRequest = new SQLQueryRequest("select pk0,pk1,col0,col1,date_col,geo_col from test_table limit 20");
SQLQueryResponse sqlQueryResponse = otsClient.SQLQuery(sqlQueryRequest);
SQLTableMeta sqlTableMeta = sqlQueryResponse.GetSQLResultSet().GetSQLTableMeta();
Console.WriteLine(JsonConvert.SerializeObject(sqlTableMeta.GetSchema()));
ISQLResultSet resultSet = sqlQueryResponse.GetSQLResultSet();
while (resultSet.HasNext())
{
ISQLRow row = resultSet.Next();
Console.WriteLine(row.GetString("pk0") + " , " + row.GetLong("pk1") + " , " + row.GetString("col0") + " , " +
row.GetLong("col1") + " , " + row.GetString("date_col") + " , " + row.GetString("geo_col"));
}
}