Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/PipingSoilProfileReader.cs =================================================================== diff -u -r33d4f4e7e5404dcc6470dd3d34168b30410109eb -ra3934ff3a7c84cc1734049e904c9635b79b6cf5c --- Ringtoets/Piping/src/Ringtoets.Piping.IO/PipingSoilProfileReader.cs (.../PipingSoilProfileReader.cs) (revision 33d4f4e7e5404dcc6470dd3d34168b30410109eb) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/PipingSoilProfileReader.cs (.../PipingSoilProfileReader.cs) (revision a3934ff3a7c84cc1734049e904c9635b79b6cf5c) @@ -17,6 +17,7 @@ { private const string pipingMechanismName = "Piping"; + private const string profileCountColumn = "ProfileCount"; private const string dimensionColumn = "Dimension"; private const string isAquiferColumn = "IsAquifer"; private const string profileNameColumn = "ProfileName"; @@ -33,12 +34,12 @@ private const string layerCountColumn = "LayerCount"; private const string mechanismParameterName = "mechanism"; - private SQLiteConnection connection; - private SQLiteDataReader dataReader; - private readonly string databaseFileName; private readonly string databaseRequiredVersion = "15.0.5.0"; + private SQLiteConnection connection; + private SQLiteDataReader dataReader; + /// /// Creates a new instance of which will use the /// as its source. The reader will not point to any record at the start. Use to start reading @@ -62,6 +63,11 @@ } /// + /// Gets the total number of profiles that can be read from the database. + /// + public int Count { get; private set; } + + /// /// Gets the value true if profiles can be read using the . /// false otherwise. /// @@ -106,7 +112,7 @@ var profileName = Read(profileNameColumn); var layerCount = Read(layerCountColumn); var bottom = Read(bottomColumn); - + var soilProfileBuilder = new SoilProfileBuilder1D(profileName, bottom); for (var i = 1; i <= layerCount; i++) @@ -123,7 +129,7 @@ var profileName = Read(profileNameColumn); var layerCount = Read(layerCountColumn); var intersectionX = Read(intersectionXColumn); - + var soilProfileBuilder = new SoilProfileBuilder2D(profileName, intersectionX); for (int i = 1; i <= layerCount; i++) @@ -136,7 +142,7 @@ { var exception = new PipingSoilProfileReadException( string.Format(Resources.PipingSoilProfileReader_CouldNotParseGeometryOfLayer_0_InProfile_1_, i, profileName), e); - + while (i++ <= layerCount) { MoveNext(); @@ -170,7 +176,7 @@ private T Read(string columnName) { - return (T)dataReader[columnName]; + return (T) dataReader[columnName]; } private void OpenConnection(string dbFile) @@ -233,11 +239,24 @@ /// private void InitializeDataReader() { + string versionQuery = string.Format( "SELECT Value FROM _Metadata WHERE Key = 'VERSION' AND Value = '{0}';", databaseRequiredVersion ); + string countQuery = string.Format(string.Join( + " ", + "SELECT", + "(SELECT COUNT(*)", + "FROM Mechanism as m", + "JOIN MechanismPointLocation as mpl ON mpl.ME_ID = m.ME_ID", + "JOIN SoilProfile2D as p2 ON p2.SP2D_ID = mpl.SP2D_ID", + "WHERE m.ME_Name = @{0})", + " + ", + "(SELECT COUNT(*)", + "FROM SoilProfile1D) as {1};"), mechanismParameterName, profileCountColumn); + string materialPropertiesQuery = string.Format( string.Join(" ", "(SELECT", @@ -368,7 +387,7 @@ layer2DPropertiesQuery, mechanismParameterName); - CreateDataReader(versionQuery + query2D + query1D, new SQLiteParameter + CreateDataReader(versionQuery + countQuery + query2D + query1D, new SQLiteParameter { DbType = DbType.String, Value = pipingMechanismName, @@ -392,6 +411,7 @@ { dataReader = query.ExecuteReader(); CheckVersion(); + GetCount(); } catch (SQLiteException e) { @@ -405,11 +425,18 @@ { if (!dataReader.HasRows) { - throw new PipingSoilProfileReadException(String.Format( + throw new PipingSoilProfileReadException(string.Format( Resources.PipingSoilProfileReader_DatabaseFileIncorrectVersions_Requires_0, databaseRequiredVersion)); } dataReader.NextResult(); } + + private void GetCount() + { + dataReader.Read(); + Count = (int)Read(profileCountColumn); + dataReader.NextResult(); + } } } \ No newline at end of file