You can execute the select statement to query data in tables.
Note For more information about the select statement, see Query data.
Prerequisites
- An OTSClient instance is initialized. For more information, see Initialization.
- A mapping table is created. For more information, see Create mapping tables.
Parameters
Parameter | Description |
---|---|
query | The SQL statement. Configure the parameter based on the required feature. |
Examples
Execute the select pk0,pk1,col0,col1,date_col,geo_col from test_table limit 20
statement to query data in the table named test_table and set the maximum number
of rows that you want to return to 20. The system returns the request type, the schema
of the returned results, and the returned results of the query statement.
/// <summary>
/// Query data.
/// </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"));
}
}