-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDb_connection.py
More file actions
50 lines (44 loc) · 2.02 KB
/
Db_connection.py
File metadata and controls
50 lines (44 loc) · 2.02 KB
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
#!/usr/bin/python
# vim:sw=4:softtabstop=4:expandtab:set fileencoding=ISO8859-2
#
# Db_connection.py, part of the FleetPanel
#
# Copyright (c) 2008-2009 Pawe³ 'Reef' Polewicz
# All rights reserved.
#
# This software is licensed as described in the file LICENSE, which
# you should have received as part of this distribution. The terms
# are also available at http://www.opensource.org/licenses/mit-license.php.
import MySQLdb
class Db_connection:
def __init__(self):
self.db = MySQLdb.connection(host="127.0.0.1", user="db_username", passwd="db_password", db="db_database_name")
def query(self, myquery):
self.db.query( myquery )
r = self.db.store_result()
return r
def get_jumps(self, li_systems):
query_base = "SELECT mss.solarSystemName,mss2.solarSystemName FROM mapSolarSystemJumps AS mssj JOIN mapSolarSystems AS mss ON (mss.solarSystemID=fromSolarSystemID) JOIN mapSolarSystems AS mss2 ON (mssj.toSolarSystemID=mss2.solarSystemID)"
if li_systems=="*":
my_query = query_base + ";"
else:
set_systems = set(li_systems)
my_systems = ", ".join( map( lambda x: '"' + x + '"', set_systems) )
my_query = query_base + " WHERE mss.solarSystemName IN (%s);" % my_systems
db_result = self.query( my_query )
for row in db_result.fetch_row(0):
yield row[0], row[1]
def get_region_id_sysname(self, li_systems):
query_base = "SELECT mr.regionName,mss.solarSystemID,mss.solarSystemName FROM mapSolarSystems AS mss JOIN mapRegions AS mr ON (mss.regionID=mr.regionID)"
if li_systems=="*":
my_query = query_base + ";"
else:
my_systems = ", ".join( map( lambda x: '"' + x + '"', li_systems ) )
my_query = query_base + " WHERE mss.solarSystemName IN (%s);" % my_systems
self.db.query( my_query )
r = self.db.store_result()
for region, id, system in r.fetch_row(0):
yield region, id, system
def close(self):
self.db.close()
#