/// <summary> /// Constructor /// </summary> /// <param name="manifestToken">A token used to infer the capabilities of the store</param> public SampleProviderManifest(string manifestToken) : base(SampleProviderManifest.GetProviderManifest()) { // GetStoreVersion will throw ArgumentException if manifestToken is null, empty, or not recognized. _version = StoreVersionUtils.GetStoreVersion(manifestToken); _token = manifestToken; }
protected override bool DbDatabaseExists(DbConnection connection, int?commandTimeout, StoreItemCollection storeItemCollection) { if (connection == null) { throw new ArgumentNullException("connection must not be null"); } if (storeItemCollection == null) { throw new ArgumentNullException("storeItemCollection must not be null"); } SampleConnection sampleConnection = connection as SampleConnection; if (sampleConnection == null) { throw new ArgumentException("connection must be a valid SampleConnection"); } string databaseName = GetDatabaseName(sampleConnection); bool exists = false; UsingMasterConnection(sampleConnection, conn => { StoreVersion storeVersion = StoreVersionUtils.GetStoreVersion(conn); string databaseExistsScript = DdlBuilder.CreateDatabaseExistsScript(databaseName); int result = (int)CreateCommand(conn, databaseExistsScript, commandTimeout).ExecuteScalar(); exists = (result == 1); }); return(exists); }
internal static string GetVersionHint(StoreVersion version) { switch (version) { case StoreVersion.Sql9: return(SampleProviderManifest.TokenSql9); case StoreVersion.Sql10: return(SampleProviderManifest.TokenSql10); } throw new ArgumentException("Could not determine storage version; a valid storage connection or a version hint is required."); }
internal static string GetVersionHint(StoreVersion version) { switch (version) { case StoreVersion.Sql9: return SampleProviderManifest.TokenSql9; case StoreVersion.Sql10: return SampleProviderManifest.TokenSql10; } throw new ArgumentException("Could not determine storage version; a valid storage connection or a version hint is required."); }
private static void ValidateVersion(string manifestToken) { if (string.IsNullOrWhiteSpace(manifestToken)) { throw new ArgumentException("Could not determine storage version. manifestToken is null or whitespace string."); } // GetSqlVersion will throw ArgumentException if manifestToken is null, empty, or not recognized. StoreVersion storeVersion = StoreVersionUtils.GetStoreVersion(manifestToken); // SQL spatial support is only available for SQL Server 2008 and later if (storeVersion < StoreVersion.Sql10) { throw new InvalidOperationException("Spatial types and functions are only supported by SQL Server 2008 or later."); } }
protected override string GetDbProviderManifestToken(DbConnection connection) { if (connection == null) { throw new ArgumentException("connection"); } SampleConnection sampleConnection = connection as SampleConnection; if (sampleConnection == null) { throw new ArgumentException("The connection is not of type 'SampleConnection'."); } if (string.IsNullOrEmpty(sampleConnection.ConnectionString)) { throw new ArgumentException("Could not determine storage version; a valid storage connection or a version hint is required."); } bool closeConnection = false; try { if (sampleConnection.State != ConnectionState.Open) { sampleConnection.Open(); closeConnection = true; } StoreVersion version = StoreVersionUtils.GetStoreVersion(sampleConnection); if (version == StoreVersion.Sql9) { return(SampleProviderManifest.TokenSql9); } else { return(StoreVersionUtils.GetVersionHint(version)); } } finally { if (closeConnection) { sampleConnection.Close(); } } }
/// <summary> /// Create a SampleCommand object, given the provider manifest and command tree /// </summary> private DbCommand CreateCommand(DbProviderManifest manifest, DbCommandTree commandTree) { if (manifest == null) { throw new ArgumentNullException("manifest"); } if (commandTree == null) { throw new ArgumentNullException("commandTree"); } SampleProviderManifest sampleManifest = (manifest as SampleProviderManifest); if (sampleManifest == null) { throw new ArgumentException("The provider manifest given is not of type 'SampleProviderManifest'."); } StoreVersion version = sampleManifest.Version; SampleCommand command = new SampleCommand(); List <DbParameter> parameters; CommandType commandType; command.CommandText = SqlGenerator.GenerateSql(commandTree, version, out parameters, out commandType); command.CommandType = commandType; if (command.CommandType == CommandType.Text) { command.CommandText += Environment.NewLine + Environment.NewLine + "-- provider: " + this.GetType().Assembly.FullName; } // Get the function (if any) implemented by the command tree since this influences our interpretation of parameters EdmFunction function = null; if (commandTree is DbFunctionCommandTree) { function = ((DbFunctionCommandTree)commandTree).EdmFunction; } // Now make sure we populate the command's parameters from the CQT's parameters: foreach (KeyValuePair <string, TypeUsage> queryParameter in commandTree.Parameters) { SqlParameter parameter; // Use the corresponding function parameter TypeUsage where available (currently, the SSDL facets and // type trump user-defined facets and type in the EntityCommand). FunctionParameter functionParameter; if (null != function && function.Parameters.TryGetValue(queryParameter.Key, false, out functionParameter)) { parameter = CreateSqlParameter(functionParameter.Name, functionParameter.TypeUsage, functionParameter.Mode, DBNull.Value); } else { parameter = CreateSqlParameter(queryParameter.Key, queryParameter.Value, ParameterMode.In, DBNull.Value); } command.Parameters.Add(parameter); } // Now add parameters added as part of SQL gen (note: this feature is only safe for DML SQL gen which // does not support user parameters, where there is no risk of name collision) if (null != parameters && 0 < parameters.Count) { if (!(commandTree is DbInsertCommandTree) && !(commandTree is DbUpdateCommandTree) && !(commandTree is DbDeleteCommandTree)) { throw new InvalidOperationException("SqlGenParametersNotPermitted"); } foreach (DbParameter parameter in parameters) { command.Parameters.Add(parameter); } } return(command); }