-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew_mysql.js
68 lines (56 loc) · 2.39 KB
/
new_mysql.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : '',
database : 'real_db',
port : '3307',
socket : 'tmp/mysql.sock'
});
function get_territories_with_playerID() {
connection.query('select players.p_id, territoryID_to_territory_name.t_name from players join playerID_to_territoryID on players.p_id = playerID_to_territoryID.p_id join territoryID_to_territory_name on playerID_to_territoryID.t_id = territoryID_to_territory_name.t_id', function(err, rows, fields){
if(!err) {
console.log(rows);
}
else {
console.log("ERROR: ", err);
}
});
}
function get_infrantry_number_with_territory_name(territory_name) {
connection.query('select territoryID_to_territory_name.t_name, territoryID_to_infrantry.infrantry_number from territoryID_to_territory_name join territoryID_to_infrantry where territoryID_to_territory_name.t_id = territoryID_to_infrantry.t_id AND territoryID_to_territory_name.t_name = ' + "'"+territory_name+"'", function(err, rows, fields){
if(!err) {
console.log(rows);
//console.log(fields);
}
else {
console.log("ERROR: ", err);
}
});
}
function add_troop_to_territory(territory_name) {
}
function subtract_troop_to_territory(territory_name) {
}
function change_owned_territory(playerID1, playerID2, territory_name) {
}
/*
function get_infrantry_from_territory(territory) {
connection.query('SELECT * from territoryID_to where id = ' + "'"+territory+"'", function(err, rows, fields) {
if(!err) {
//console.log("The number of infrantries are: ", rows[0].infrantry);
console.log(rows);
}
else {
console.log('ERROR!', err);
}
});
}
*/
/*
select territoryID_to_territory_name.t_name, territoryID_to_infrantry.infrantry_number from territoryID_to_territory_name join territoryID_to_infrantry on territoryID_to_territory_name.t_id = territoryID_to_infrantry.t_id;
select territoryID_to_territory_name.t_name, territoryID_to_infrantry.infrantry_number from territoryID_to_territory_name join territoryID_to_infrantry where territoryID_to_territory_name.t_id = territoryID_to_infrantry.t_id AND territoryID_to_territory_name.t_id = 1;
*/
get_territories_with_playerID();
//get_infrantry_number_with_territory_name('Paris');
connection.end();