db_trans.py
Go to the documentation of this file.
1 
2 
3 from odb import *
4 import profiler
5 import socket
6 
7 USER = 'root'
8 PASSWORD = ''
9 DATABASE = 'trans_data'
10 
12  # access patterns:
13  # -> lookup individual entries by string_id
14  # -> lookup entry by string
15  def _defineRows(self):
16  self.d_addColumn("string_id", kInteger, primarykey=1, autoincrement=1)
17  # we can't actually index this... but we can index part with myisam
18  self.d_addColumn("string", kBigString, indexed=1)
19 
20 ## hmm, on second thought, storing this is in the database is kind
21 ## of silly..., since it essentially could change with each run. It may
22 ## not even be necessary to store this anywhere except in memory while
23 ## trans is running
25  # access patterns:
26  # -> find "same" entry by filename/offset
27  # -> dump all locations for a version
28  # -> maybe: find all locations for a filename
29  def _defineRows(self):
30  self.d_addColumn("loc_id", kInteger, primarykey=1, autoincrement=1)
31  self.d_addColumn("string_id", kInteger, indexed=1)
32  self.d_addColumn("version", kInteger, default=0)
33  self.d_addColumn("filename", kVarString, 255, indexed=1)
34  self.d_addColumn("location", kVarString, 255)
35  # this can either be:
36  # ofs:x:y
37  # hdf:foo.bar.baz
38 
40  # access patterns:
41  # -> dump all for a language
42  # -> lookup entry by string_id/lang
43  def _defineRows(self):
44  self.d_addColumn("string_id", kInteger, primarykey=1)
45  self.d_addColumn("lang", kFixedString, 2, primarykey=1)
46  self.d_addColumn("string", kBigString)
47 
48 class DB(Database):
49  def __init__(self, db, debug=0):
50  self.db = db
51  self._cursor = None
52  self.debug = debug
53 
54  self.addTable("strings", "nt_trans_strings", TransStringTable)
55  self.addTable("locs", "nt_trans_locs", TransLocTable)
56  self.addTable("maps", "nt_trans_maps", TransMapTable)
57 
58  def defaultCursor(self):
59  # share one cursor for this db object!
60  if self._cursor is None:
61  if self.debug:
62  self._cursor = profiler.ProfilerCursor(self.db.cursor())
63  else:
64  self._cursor = self.db.cursor()
65 
66  return self._cursor
67 
68 def trans_connect(host = 'localhost', debug=0):
69  # try to optimize connection if on this machine
70  if host != 'localhost':
71  local_name = socket.gethostname()
72  if string.find(local_name, '.') == -1:
73  local_name = local_name + ".neotonic.com"
74  if local_name == host:
75  host = 'localhost'
76 
77  if debug: p = profiler.Profiler("SQL", "Connect -- %s:trans" % (host))
78  db = MySQLdb.connect(host = host, user=USER, passwd = PASSWORD, db=DATABASE)
79  if debug: p.end()
80 
81  retval = DB(db, debug=debug)
82  return retval
def trans_connect(host='localhost', debug=0)
Definition: db_trans.py:68
def __init__(self, db, debug=0)
Definition: db_trans.py:49
def d_addColumn(self, col_name, ctype, size=None, primarykey=0, notnull=0, indexed=0, default=None, unique=0, autoincrement=0, autoguid=0, safeupdate=0, enum_values=None, no_export=0, relations=None, foreign_key=None, compress_ok=0, int_date=0)
Definition: odb.py:1074
def addTable(self, attrname, tblname, tblclass, rowClass=None, check=0, create=0, rowListClass=None, replication=None)
Definition: odb.py:483
hmm, on second thought, storing this is in the database is kind of silly..., since it essentially cou...
Definition: db_trans.py:24


pyclearsilver
Author(s): Scott Noob Hassan
autogenerated on Mon Jun 10 2019 15:51:13