/// <summary> /// Constructor for this class /// </summary> /// <param name="providers"> /// Query and fragment providers of type <see cref="IDatabaseQueryProvider"/> or <see cref="IQueryFragmentProvider"/> /// </param> public DatabaseService(params Type[] providers) { Queries = new Dictionary <string, DatabaseQuery>(); FillQueryLibrary(Queries, providers); // Make sure we've loaded the database queries if ((!StaticQueries.ContainsKey(DatabaseQueryPrefix + "sequence.generic")) && (!Queries.ContainsKey(DatabaseQueryPrefix + "sequence.generic"))) { FillQueryLibrary(Queries, typeof(DatabaseQueryProvider)); } }
/// <summary> /// Get a query from the library /// </summary> /// <param name="queryName"> /// The name of the query to retrieve /// </param> /// <returns> /// The database query /// </returns> /// <exception cref="System.Collections.Generic.KeyNotFoundException"> /// Thrown when the query name is not found in the query library /// </exception> public DatabaseQuery GetQuery(string queryName) { if (StaticQueries.ContainsKey(queryName)) { return(StaticQueries[queryName]); } if (Queries.ContainsKey(queryName)) { return(Queries[queryName]); } throw new KeyNotFoundException(String.Format("Unable to find query {0}", queryName)); }
/// <summary> /// Get the last inserted identity value; ODBC users must provide their own implementation (long) /// </summary> /// <returns> /// The identity if the query is defined; an exception if not. /// </returns> /// <exception cref="InvalidOperationException"> /// If there is no query defined /// </exception> public override long LongLastIdentity() { if (!StaticQueries.ContainsKey(DatabaseQueryPrefix + "identity.odbc")) { if (!Queries.ContainsKey(DatabaseQueryPrefix + "identity.odbc")) { throw new InvalidOperationException(String.Format(_noQuery, DatabaseQueryPrefix)); } } using (var reader = SelectOne(DatabaseQueryPrefix + "identity.odbc")) return(LongValue(reader, 0)); }