質問編集履歴
7
コード修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -21,8 +21,6 @@
|
|
21
21
|
### 該当のソースコード
|
22
22
|
|
23
23
|
修正1
|
24
|
-
|
25
|
-
result.resolveにはundefined
|
26
24
|
|
27
25
|
```javascript
|
28
26
|
|
@@ -54,13 +52,13 @@
|
|
54
52
|
|
55
53
|
await connection.query(query, (err, rows, fields) => {
|
56
54
|
|
57
|
-
result = Boolean(rows[0].result);
|
55
|
+
result = Boolean(rows[0].result); // ★3番目に呼ばれる
|
58
56
|
|
59
57
|
});
|
60
58
|
|
61
59
|
|
62
60
|
|
63
|
-
return result;
|
61
|
+
return result; // ★1番目に呼ばれる
|
64
62
|
|
65
63
|
}
|
66
64
|
|
@@ -68,81 +66,13 @@
|
|
68
66
|
|
69
67
|
// 呼び出し元
|
70
68
|
|
71
|
-
http.createServer(function (req, res) {
|
69
|
+
http.createServer(async function (req, res) {
|
72
70
|
|
73
71
|
if (req.method == 'POST') {
|
74
72
|
|
75
|
-
var result = isRegistered('hogehoge');
|
73
|
+
var result = awit isRegistered('hogehoge');
|
76
74
|
|
77
|
-
console.log(result.resolve);
|
75
|
+
console.log(result.resolve);// ★2番目に呼ばれる
|
78
|
-
|
79
|
-
}
|
80
|
-
|
81
|
-
}).listen(8080);
|
82
|
-
|
83
|
-
```
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
修正2
|
88
|
-
|
89
|
-
resultはundefined
|
90
|
-
|
91
|
-
```javascript
|
92
|
-
|
93
|
-
var http = require('http');
|
94
|
-
|
95
|
-
const mysql = require('mysql');
|
96
|
-
|
97
|
-
var result;
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
const connection = mysql.createConnection({
|
102
|
-
|
103
|
-
host: '',
|
104
|
-
|
105
|
-
user: 'aaa',
|
106
|
-
|
107
|
-
password: 'bbb',
|
108
|
-
|
109
|
-
port: '3306'
|
110
|
-
|
111
|
-
});
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
function isRegistered(id) {
|
116
|
-
|
117
|
-
var result = false;
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
var query = `SELECT EXISTS (SELECT * FROM hoges WHERE id = '${id}') as result;`;
|
122
|
-
|
123
|
-
connection.query(query, (err, rows, fields) => {
|
124
|
-
|
125
|
-
result = Boolean(rows[0].result);
|
126
|
-
|
127
|
-
});
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
return result;
|
132
|
-
|
133
|
-
}
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
// 呼び出し元
|
138
|
-
|
139
|
-
http.createServer(function (req, res) {
|
140
|
-
|
141
|
-
if (req.method == 'POST') {
|
142
|
-
|
143
|
-
isRegistered('hogehoge');
|
144
|
-
|
145
|
-
console.log(result);
|
146
76
|
|
147
77
|
}
|
148
78
|
|
6
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -22,7 +22,7 @@
|
|
22
22
|
|
23
23
|
修正1
|
24
24
|
|
25
|
-
resultには
|
25
|
+
result.resolveにはundefined
|
26
26
|
|
27
27
|
```javascript
|
28
28
|
|
@@ -74,7 +74,7 @@
|
|
74
74
|
|
75
75
|
var result = isRegistered('hogehoge');
|
76
76
|
|
77
|
-
console.log(result);
|
77
|
+
console.log(result.resolve);
|
78
78
|
|
79
79
|
}
|
80
80
|
|
5
コード修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -72,7 +72,9 @@
|
|
72
72
|
|
73
73
|
if (req.method == 'POST') {
|
74
74
|
|
75
|
-
var result =
|
75
|
+
var result = isRegistered('hogehoge');
|
76
|
+
|
77
|
+
console.log(result);
|
76
78
|
|
77
79
|
}
|
78
80
|
|
@@ -138,7 +140,9 @@
|
|
138
140
|
|
139
141
|
if (req.method == 'POST') {
|
140
142
|
|
141
|
-
|
143
|
+
isRegistered('hogehoge');
|
144
|
+
|
145
|
+
console.log(result);
|
142
146
|
|
143
147
|
}
|
144
148
|
|
4
回答を受けてコード修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -20,7 +20,9 @@
|
|
20
20
|
|
21
21
|
### 該当のソースコード
|
22
22
|
|
23
|
+
修正1
|
23
24
|
|
25
|
+
resultにはtrueのみ
|
24
26
|
|
25
27
|
```javascript
|
26
28
|
|
@@ -80,6 +82,72 @@
|
|
80
82
|
|
81
83
|
|
82
84
|
|
85
|
+
修正2
|
86
|
+
|
87
|
+
resultはundefined
|
88
|
+
|
89
|
+
```javascript
|
90
|
+
|
91
|
+
var http = require('http');
|
92
|
+
|
93
|
+
const mysql = require('mysql');
|
94
|
+
|
95
|
+
var result;
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
const connection = mysql.createConnection({
|
100
|
+
|
101
|
+
host: '',
|
102
|
+
|
103
|
+
user: 'aaa',
|
104
|
+
|
105
|
+
password: 'bbb',
|
106
|
+
|
107
|
+
port: '3306'
|
108
|
+
|
109
|
+
});
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
function isRegistered(id) {
|
114
|
+
|
115
|
+
var result = false;
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
var query = `SELECT EXISTS (SELECT * FROM hoges WHERE id = '${id}') as result;`;
|
120
|
+
|
121
|
+
connection.query(query, (err, rows, fields) => {
|
122
|
+
|
123
|
+
result = Boolean(rows[0].result);
|
124
|
+
|
125
|
+
});
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
return result;
|
130
|
+
|
131
|
+
}
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
// 呼び出し元
|
136
|
+
|
137
|
+
http.createServer(function (req, res) {
|
138
|
+
|
139
|
+
if (req.method == 'POST') {
|
140
|
+
|
141
|
+
var result = db.isRegistered('hogehoge');
|
142
|
+
|
143
|
+
}
|
144
|
+
|
145
|
+
}).listen(8080);
|
146
|
+
|
147
|
+
```
|
148
|
+
|
149
|
+
|
150
|
+
|
83
151
|
### 試したこと
|
84
152
|
|
85
153
|
|
3
コード修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -24,6 +24,8 @@
|
|
24
24
|
|
25
25
|
```javascript
|
26
26
|
|
27
|
+
var http = require('http');
|
28
|
+
|
27
29
|
const mysql = require('mysql');
|
28
30
|
|
29
31
|
const connection = mysql.createConnection({
|
@@ -40,7 +42,7 @@
|
|
40
42
|
|
41
43
|
|
42
44
|
|
43
|
-
function isRegistered(id) {
|
45
|
+
async function isRegistered(id) {
|
44
46
|
|
45
47
|
var result = false;
|
46
48
|
|
@@ -48,7 +50,7 @@
|
|
48
50
|
|
49
51
|
var query = `SELECT EXISTS (SELECT * FROM hoges WHERE id = '${id}') as result;`;
|
50
52
|
|
51
|
-
connection.query(query, (err, rows, fields) => {
|
53
|
+
await connection.query(query, (err, rows, fields) => {
|
52
54
|
|
53
55
|
result = Boolean(rows[0].result);
|
54
56
|
|
@@ -59,6 +61,20 @@
|
|
59
61
|
return result;
|
60
62
|
|
61
63
|
}
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
// 呼び出し元
|
68
|
+
|
69
|
+
http.createServer(function (req, res) {
|
70
|
+
|
71
|
+
if (req.method == 'POST') {
|
72
|
+
|
73
|
+
var result = db.isRegistered('hogehoge');
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
}).listen(8080);
|
62
78
|
|
63
79
|
```
|
64
80
|
|
2
コード修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -23,6 +23,8 @@
|
|
23
23
|
|
24
24
|
|
25
25
|
```javascript
|
26
|
+
|
27
|
+
const mysql = require('mysql');
|
26
28
|
|
27
29
|
const connection = mysql.createConnection({
|
28
30
|
|
1
コード追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -23,6 +23,20 @@
|
|
23
23
|
|
24
24
|
|
25
25
|
```javascript
|
26
|
+
|
27
|
+
const connection = mysql.createConnection({
|
28
|
+
|
29
|
+
host: '',
|
30
|
+
|
31
|
+
user: 'aaa',
|
32
|
+
|
33
|
+
password: 'bbb',
|
34
|
+
|
35
|
+
port: '3306'
|
36
|
+
|
37
|
+
});
|
38
|
+
|
39
|
+
|
26
40
|
|
27
41
|
function isRegistered(id) {
|
28
42
|
|