本文整理汇总了C#中DataStore.RunQuery方法的典型用法代码示例。如果您正苦于以下问题:C# DataStore.RunQuery方法的具体用法?C# DataStore.RunQuery怎么用?C# DataStore.RunQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataStore
的用法示例。
在下文中一共展示了DataStore.RunQuery方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
/// <summary>Main run method for performing our calculations and storing data.</summary>
/// <param name="dataStore">The data store.</param>
/// <exception cref="ApsimXException">
/// Could not find model data table: + ObservedTableName
/// or
/// Could not find observed data table: + ObservedTableName
/// </exception>
public void Run(DataStore dataStore)
{
if (PredictedTableName != null && ObservedTableName != null)
{
dataStore.DeleteTable(this.Name);
DataTable predictedDataNames = dataStore.RunQuery("PRAGMA table_info(" + PredictedTableName + ")");
DataTable observedDataNames = dataStore.RunQuery("PRAGMA table_info(" + ObservedTableName + ")");
if (predictedDataNames == null)
throw new ApsimXException(this, "Could not find model data table: " + ObservedTableName);
if (observedDataNames == null)
throw new ApsimXException(this, "Could not find observed data table: " + ObservedTableName);
IEnumerable<string> commonCols = from p in predictedDataNames.AsEnumerable()
join o in observedDataNames.AsEnumerable() on p["name"] equals o["name"]
select p["name"] as string;
StringBuilder query = new StringBuilder("SELECT ");
foreach (string s in commonCols)
{
if (s == FieldNameUsedForMatch || s == FieldName2UsedForMatch || s == FieldName3UsedForMatch)
query.Append("I.'@field', ");
else
query.Append("I.'@field' AS '[email protected]', R.'@field' AS '[email protected]', ");
query.Replace("@field", s);
}
query.Append("FROM " + ObservedTableName + " I INNER JOIN " + PredictedTableName + " R USING (SimulationID) WHERE I.'@match1' = R.'@match1'");
if (FieldName2UsedForMatch != null)
query.Append(" AND I.'@match2' = R.'@match2'");
if (FieldName3UsedForMatch != null)
query.Append(" AND I.'@match3' = R.'@match3'");
query.Replace(", FROM", " FROM"); // get rid of the last comma
query.Replace("I.'SimulationID' AS 'Observed.SimulationID', R.'SimulationID' AS 'Predicted.SimulationID'", "I.'SimulationID' AS 'SimulationID'");
query = query.Replace("@match1", FieldNameUsedForMatch);
query = query.Replace("@match2", FieldName2UsedForMatch);
query = query.Replace("@match3", FieldName3UsedForMatch);
DataTable predictedObservedData = dataStore.RunQuery(query.ToString());
if (predictedObservedData != null)
dataStore.WriteTable(null, this.Name, predictedObservedData);
dataStore.Disconnect();
}
}