You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -67,7 +73,7 @@ When you're developing locally, add your application settings in the local.setti
67
73
68
74
Note: This tutorial requires that a SQL database is setup as shown in [Create a SQL Server](./GeneralSetup.md#create-a-sql-server).
69
75
70
-
- Open your app that you created in [Create a Function App](./GeneralSetup.md#create-a-function-app) in VS Code
76
+
- Open your app that you created in [Setup Function App](#setup-function-app) in VS Code
71
77
- Press 'F1' and search for 'Azure Functions: Create Function'
72
78
- Choose HttpTrigger -> (Provide a package name) -> (Provide a function name) -> anonymous
73
79
- In the file that opens, replace the `public HttpResponseMessage run` block with the below code.
@@ -91,8 +97,8 @@ Note: This tutorial requires that a SQL database is setup as shown in [Create a
91
97
92
98
*In the above, "select * from Employees" is the SQL script run by the input binding. The CommandType on the line below specifies whether the first line is a query or a stored procedure. On the next line, the ConnectionStringSetting specifies that the app setting that contains the SQL connection string used to connect to the database is "SqlConnectionString." For more information on this, see the [SQLInput Attribute](#sqlinput-attribute) section*
- Paste the below in the file. These are the column names of our SQL table. Note that the casing of the Object field names and the table column names must match.
97
103
98
104
```java
@@ -156,23 +162,155 @@ Note: This tutorial requires that a SQL database is setup as shown in [Create a
156
162
157
163
#### Query String
158
164
159
-
_TODO_
165
+
The input binding executes the `SELECT * FROM Products WHERE Cost = @Cost` query, returning the result as Product[], where Product is a user-defined object. The Parameters argument passes the {cost} specified in the URL that triggers the function, getproducts/{cost}, as the value of the @Cost parameter in the query. CommandType is set to `Text`, since the constructor argument of the binding is a raw query.
166
+
167
+
```java
168
+
@FunctionName("GetProducts")
169
+
public HttpResponseMessage run(
170
+
@HttpTrigger(
171
+
name = "req",
172
+
methods = {HttpMethod.GET},
173
+
authLevel = AuthorizationLevel.ANONYMOUS,
174
+
route = "getproducts/{cost}")
175
+
HttpRequestMessage<Optional<String>> request,
176
+
@SQLInput(
177
+
name = "products",
178
+
commandText = "SELECT * FROM Products WHERE Cost = @Cost",
`Product` is a user-defined object that follows the structure of the Products table. It represents a row of the Products table, with field names and types copying those of the Products table schema. For example, if the Products table has three columns of the form
189
+
190
+
- **ProductId**: int
191
+
- **Name**: varchar
192
+
- **Cost**: int
193
+
194
+
Then the `Product` class would look like
195
+
196
+
```java
197
+
public class Product {
198
+
@JsonProperty("ProductId")
199
+
private int ProductId;
200
+
@JsonProperty("Name")
201
+
private String Name;
202
+
@JsonProperty("Cost")
203
+
private int Cost;
204
+
205
+
public Product() {
206
+
}
207
+
208
+
public Product(int productId, String name, int cost) {
209
+
ProductId = productId;
210
+
Name = name;
211
+
Cost = cost;
212
+
}
213
+
214
+
public int getProductId() {
215
+
return ProductId;
216
+
}
217
+
218
+
public void setProductId(int productId) {
219
+
this.ProductId = productId;
220
+
}
221
+
222
+
public String getName() {
223
+
return Name;
224
+
}
225
+
226
+
public void setName(String name) {
227
+
this.Name = name;
228
+
}
229
+
230
+
public int getCost() {
231
+
return Cost;
232
+
}
233
+
234
+
public void setCost(int cost) {
235
+
this.Cost = cost;
236
+
}
237
+
}
238
+
```
160
239
161
240
#### Empty Parameter Value
162
241
163
-
_TODO_
242
+
In this case, the parameter value of the @Name parameter is an empty string.
243
+
244
+
```java
245
+
@FunctionName("GetProductsNameEmpty")
246
+
public HttpResponseMessage run(
247
+
@HttpTrigger(
248
+
name = "req",
249
+
methods = {HttpMethod.GET},
250
+
authLevel = AuthorizationLevel.ANONYMOUS,
251
+
route = "getproducts-nameempty/{cost}")
252
+
HttpRequestMessage<Optional<String>> request,
253
+
@SQLInput(
254
+
name = "products",
255
+
commandText = "SELECT * FROM Products WHERE Cost = @Cost and Name = @Name",
If the `{name}` specified in the `getproducts-namenull/{name}` URL is "null", the query returns all rows for which the Name column is `NULL`. Otherwise, it returns all rows for which the value of the Name column matches the string passed in `{name}`
268
+
269
+
```java
270
+
@FunctionName("GetProductsNameNull")
271
+
public HttpResponseMessage run(
272
+
@HttpTrigger(
273
+
name = "req",
274
+
methods = {HttpMethod.GET},
275
+
authLevel = AuthorizationLevel.ANONYMOUS,
276
+
route = "getproducts-namenull/{name}")
277
+
HttpRequestMessage<Optional<String>> request,
278
+
@SQLInput(
279
+
name = "products",
280
+
commandText = "IF @Name IS NULL SELECT * FROM Products WHERE Name IS NULL ELSE SELECT * FROM Products WHERE Name = @Name",
`SelectProductsCost` is the name of a procedure stored in the user's database. In this case, *CommandType* is `StoredProcedure`. The parameter value of the `@Cost` parameter in the procedure is once again the `{cost}` specified in the `getproducts-storedprocedure/{cost}` URL.
0 commit comments