File tree Expand file tree Collapse file tree 1 file changed +9
-14
lines changed Expand file tree Collapse file tree 1 file changed +9
-14
lines changed Original file line number Diff line number Diff line change @@ -20,29 +20,24 @@ async function queryDatabase() {
20
20
try {
21
21
const result = await input ( [ 'number' ] ) ;
22
22
input_number = result . number
23
- } catch ( err ) {
24
- console . error ( err ) ;
25
- }
26
23
27
- // 1. Naive way of passing the parameter to the query
28
- //const select_query = `select * from students WHERE student_number = ${input_number};`
24
+ // 1. Naive way of passing the parameter to the query
25
+ //const select_query = `select * from students WHERE student_number = ${input_number};`
29
26
30
- // 2. Escaping the parameter ( replacing the unwanted characters)
31
- //const select_query = `select * from students WHERE student_number =` + connection.escape(input_number);
32
-
33
- // 3. Using a question mark syntax to do the escaping (AKA prepared statements)
34
- const select_query = `select * from students WHERE student_number = ?`
27
+ // 2. Escaping the parameter ( replacing the unwanted characters)
28
+ //const select_query = `select * from students WHERE student_number =` + connection.escape(input_number);
29
+ // 3. Using a question mark syntax to do the escaping (AKA prepared statements)
30
+ const select_query = `select * from students WHERE student_number = ?`
35
31
36
- connection . connect ( ) ;
37
- try {
32
+ connection . connect ( ) ;
38
33
console . log ( select_query ) ;
39
34
var results = await execQuery ( select_query , input_number ) ;
40
35
} catch ( error ) {
41
36
console . error ( error ) ;
42
37
}
43
38
44
- for ( i in results ) {
45
- console . log ( results [ i ] ) ;
39
+ for ( r of results ) {
40
+ console . log ( r ) ;
46
41
}
47
42
connection . end ( ) ;
48
43
}
You can’t perform that action at this time.
0 commit comments