|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. See License.txt in the project root for license information. |
| 3 | + |
| 4 | +using Microsoft.Azure.Functions.Worker.Extensions.Abstractions; |
| 5 | + |
| 6 | +namespace Microsoft.Azure.Functions.Worker.Extension.Sql |
| 7 | +{ |
| 8 | + public sealed class SqlInputAttribute : InputBindingAttribute |
| 9 | + { |
| 10 | + /// <summary> |
| 11 | + /// Creates an instance of the <see cref="SqlAttribute"/>, specifying the Sql attributes |
| 12 | + /// the function supports. |
| 13 | + /// </summary> |
| 14 | + /// <param name="commandText">The text of the command.</param> |
| 15 | + public SqlInputAttribute(string commandText) |
| 16 | + { |
| 17 | + this.CommandText = commandText; |
| 18 | + } |
| 19 | + |
| 20 | + /// <summary> |
| 21 | + /// The name of the app setting where the SQL connection string is stored |
| 22 | + /// (see https://docs.microsoft.com/dotnet/api/microsoft.data.sqlclient.sqlconnection). |
| 23 | + /// The attributes specified in the connection string are listed here |
| 24 | + /// https://docs.microsoft.com/dotnet/api/microsoft.data.sqlclient.sqlconnection.connectionstring |
| 25 | + /// For example, to create a connection to the "TestDB" located at the URL "test.database.windows.net" using a User ID and password, |
| 26 | + /// create a ConnectionStringSetting with a name like SqlServerAuthentication. The value of the SqlServerAuthentication app setting |
| 27 | + /// would look like "Data Source=test.database.windows.net;Database=TestDB;User ID={userid};Password={password}". |
| 28 | + /// </summary> |
| 29 | + public string ConnectionStringSetting { get; set; } |
| 30 | + |
| 31 | + /// <summary> |
| 32 | + /// Either a SQL query or stored procedure that will be run in the database referred to in the ConnectionString. |
| 33 | + /// </summary> |
| 34 | + public string CommandText { get; set; } |
| 35 | + |
| 36 | + /// <summary> |
| 37 | + /// Specifies whether <see cref="CommandText"/> refers to a stored procedure or SQL query string. |
| 38 | + /// Use <see cref="CommandType.StoredProcedure"/> for the former, <see cref="CommandType.Text"/> for the latter |
| 39 | + /// </summary> |
| 40 | + public System.Data.CommandType CommandType { get; set; } = System.Data.CommandType.Text; |
| 41 | + |
| 42 | + /// <summary> |
| 43 | + /// Specifies the parameters that will be used to execute the SQL query or stored procedure specified in <see cref="CommandText"/>. |
| 44 | + /// Must follow the format "@param1=param1,@param2=param2". For example, if your SQL query looks like |
| 45 | + /// "select * from Products where cost = @Cost and name = @Name", then Parameters must have the form "@Cost=100,@Name={Name}" |
| 46 | + /// If the value of a parameter should be null, use "null", as in @param1=null,@param2=param2". |
| 47 | + /// If the value of a parameter should be an empty string, do not add anything after the equals sign and before the comma, |
| 48 | + /// as in "@param1=,@param2=param2" |
| 49 | + /// Note that neither the parameter name nor the parameter value can have ',' or '=' |
| 50 | + /// </summary> |
| 51 | + public string Parameters { get; set; } |
| 52 | + } |
| 53 | +} |
0 commit comments