Esempio n. 1
0
    def setUp(self):
        self.database = scout.Database(':memory:')

        self.database.begin()
        c = self.database.cursor

        self.term = 'package3-module2'
        self.sql_begin = 'SELECT package, module ' \
            'FROM modules LEFT JOIN packages ON modules.id_pkg=packages.id_pkg'

        sql = """
CREATE TABLE modules (id_modules INT PRIMARY KEY NOT NULL, module VARCHAR(64) NOT NULL, id_pkg INT NOT NULL);
CREATE TABLE packages(id_pkg INT PRIMARY KEY NOT NULL, package VARCHAR(64) NOT NULL);
INSERT INTO packages(id_pkg, package) VALUES(1, 'package1');
INSERT INTO packages(id_pkg, package) VALUES(2, 'package2');
INSERT INTO packages(id_pkg, package) VALUES(3, 'package3');
INSERT INTO modules(id_modules, module, id_pkg) VALUES(1, 'package1-module1', 1);
INSERT INTO modules(id_modules, module, id_pkg) VALUES(2, 'package1-module2', 1);
INSERT INTO modules(id_modules, module, id_pkg) VALUES(3, 'package1-module3', 1);
INSERT INTO modules(id_modules, module, id_pkg) VALUES(4, 'package2-module1', 2);
INSERT INTO modules(id_modules, module, id_pkg) VALUES(5, 'package2-module2', 2);
INSERT INTO modules(id_modules, module, id_pkg) VALUES(6, 'package2-module3', 2);
INSERT INTO modules(id_modules, module, id_pkg) VALUES(7, 'package3-module1', 3);
INSERT INTO modules(id_modules, module, id_pkg) VALUES(8, 'package3-module2', 3);
INSERT INTO modules(id_modules, module, id_pkg) VALUES(9, 'package3-module3', 3);
CREATE INDEX modules_module_idx ON modules(module);
"""

        for cmd in sql.splitlines():
            c.execute(cmd)
Esempio n. 2
0
 def query_repo(self, repo, term, inversesearch = False):
     db = scout.Database(self._name + '-' + repo)
     if not inversesearch:
         r = db.query('SELECT package, path, binary FROM binary LEFT JOIN path ON binary.id_path=path.id_path LEFT JOIN package ON binary.id_pkg=package.id_pkg WHERE binary=?', term)
     else:
         r = db.query('SELECT package, path, binary FROM binary LEFT JOIN path ON binary.id_path=path.id_path LEFT JOIN package ON binary.id_pkg=package.id_pkg WHERE package=?', term)
     if r == None:
         return None
     if isinstance(r, list):
         return [ [repo] + list(x) for x in r]
     else:
         return [ [repo] + list(r) ]