Ver a proveniência

Fix a couble Database bugs.

tags/v1.0^2
Ben Kurtovic há 10 anos
ascendente
cometimento
d6ccdbd16d
1 ficheiros alterados com 8 adições e 7 eliminações
  1. +8
    -7
      bitshift/database/__init__.py

+ 8
- 7
bitshift/database/__init__.py Ver ficheiro

@@ -16,15 +16,15 @@ class Database(object):
"""Represents the MySQL database.""" """Represents the MySQL database."""


def __init__(self, migrate=False): def __init__(self, migrate=False):
self._connect()
self._conn = self._connect()
self._check_version(migrate) self._check_version(migrate)


def _connect(self): def _connect(self):
"""Establish a connection to the database.""" """Establish a connection to the database."""
root = os.path.dirname(os.path.abspath(__file__)) root = os.path.dirname(os.path.abspath(__file__))
default_file = os.path.join(root, ".my.cnf") default_file = os.path.join(root, ".my.cnf")
self._conn = oursql.connect(read_default_file=default_file,
autoping=True, autoreconnect=True)
return oursql.connect(db="bitshift", read_default_file=default_file,
autoping=True, autoreconnect=True)


def _migrate(self, cursor, current): def _migrate(self, cursor, current):
"""Migrate the database to the latest schema version.""" """Migrate the database to the latest schema version."""
@@ -58,8 +58,9 @@ class Database(object):
def _insert_symbols(self, cursor, code_id, sym_type, symbols): def _insert_symbols(self, cursor, code_id, sym_type, symbols):
"""Insert a list of symbols of a given type into the database.""" """Insert a list of symbols of a given type into the database."""
sym_types = ["functions", "classes", "variables"] sym_types = ["functions", "classes", "variables"]
query1 = "INSERT INTO symbols VALUES (?, ?, ?)"
query2 = "INSERT INTO symbol_locations VALUES (?, ?, ?, ?, ?, ?)"
query1 = "INSERT INTO symbols VALUES (DEFAULT, ?, ?, ?)"
query2 = """INSERT INTO symbol_locations VALUES
(DEFAULT, ?, ?, ?, ?, ?, ?)"""


for (name, decls, uses) in symbols: for (name, decls, uses) in symbols:
cursor.execute(query1, (code_id, sym_types.index(sym_type), name)) cursor.execute(query1, (code_id, sym_types.index(sym_type), name))
@@ -105,8 +106,8 @@ class Database(object):
query1 = """INSERT INTO code VALUES (?, ?) query1 = """INSERT INTO code VALUES (?, ?)
ON DUPLICATE KEY UPDATE code_id=code_id""" ON DUPLICATE KEY UPDATE code_id=code_id"""
query2 = """INSERT INTO codelets VALUES query2 = """INSERT INTO codelets VALUES
(?, ?, ?, ?, ?, ?, ?, ?)"""
query3 = "INSERT INTO authors VALUES (?, ?, ?)"
(DEFAULT, ?, ?, ?, ?, ?, ?, ?, ?)"""
query3 = "INSERT INTO authors VALUES (DEFAULT, ?, ?, ?)"


code_id = mmh3.hash64(codelet.code.encode("utf8"))[0] code_id = mmh3.hash64(codelet.code.encode("utf8"))[0]
origin, url = self._decompose_url(codelet.url) origin, url = self._decompose_url(codelet.url)


Carregando…
Cancelar
Guardar