Ejemplo n.º 1
0
        def _insertTestCase(db):
            c = db.cursor()

            # constructs a statement of form "... VALUES (%s,%s,%s,%s)"
            # w/o autovalue tcid
            stmt = "INSERT INTO testcase (%s) VALUES (%s)" % (
                string.join(TC_KEYS[1:], ","),
                getInsertPlaceHolders(TC_KEYS[1:]),
            )
            self.dbg(stmt)

            values = orderedValues(TC_KEYS[1:], tcDict)
            self.dbg("values= %s" % values)
            c.execute(stmt, values)
            dbs[0] = c.lastrowid
            self.dbg("tcid= %d" % dbs[0])

            if actionDicts:
                for ad in actionDicts:
                    ad["tcid"] = dbs[0]

                # constructs a statement of form "... VALUES (%s,%s,%s,%s)"
                stmt = "INSERT INTO testaction (%s) VALUES (%s)" % (
                    string.join(TA_KEYS[1:], ","),
                    getInsertPlaceHolders(TA_KEYS[1:]),
                )
                self.dbg(stmt)
                # build list from action value lists
                actions = []
                for d in actionDicts:
                    actions.append(orderedValues(TA_KEYS[1:], d))

                # insert all actions in one step
                c.executemany(stmt, actions)
Ejemplo n.º 2
0
 def get_version(self, db=None):
     """Return the current version of the database."""
     if not db:
         db = self.get_db_cnx()
     cursor = db.cursor()
     cursor.execute("SELECT value FROM system WHERE name='database_version'")
     row = cursor.fetchone()
     return row and int(row[0])
Ejemplo n.º 3
0
 def environment_created(self):
     """Insert default data into the database."""
     db = self.env.get_db_cnx()
     cursor = db.cursor()
     for table, cols, vals in db_default.data:
         cursor.executemany("INSERT INTO %s (%s) VALUES (%s)" % (table,
                            ','.join(cols), ','.join(['%s' for c in cols])),
                            vals)
     db.commit()
 def fn(db):
     cur = db.cursor()
     cur.execute("DELETE FROM custom_report WHERE uuid=%s", (uuid,))
     cur.execute("INSERT INTO report (title, author, description, query) "
                 "VALUES (%s, %s, %s, %s)",
                 (title, author, description, query))
     new_id.append(db.get_last_id(cur,'report'));
     cur.execute("INSERT INTO custom_report "
                 "(id, uuid, maingroup, subgroup, version, ordering) "
                 "VALUES (%s, %s, %s, %s, %s, %s)",
                 (new_id[0], uuid, maingroup, subgroup, version, ordering))
Ejemplo n.º 5
0
        def _updateTestItem(db):
            c = db.cursor()

            # constructs a statement of form "... SET a=%s, b=%s"
            if table == TA_TABLE:
                stmt = ("UPDATE %s SET " % table) + value_stmt + " WHERE id=%s"
            else:
                stmt = ("UPDATE %s SET " % table) + value_stmt + " WHERE tcid=%s"
            self.dbg(stmt)
            self.dbg(values + [id])
            c.execute(stmt, values + [id])
Ejemplo n.º 6
0
        def _getTestCases(db):
            c = db.cursor()

            # build statement
            stmt = "SELECT * FROM testcase"
            if querystring:
                stmt = stmt + " WHERE " + querystring

            self.dbg(stmt)
            c.execute(stmt, values)
            dbs[0] = c.fetchall()
            self.dbg(dbs[0])
Ejemplo n.º 7
0
        def _getTestActions(db):
            global rows
            c = db.cursor()

            # build statement
            stmt = "SELECT * FROM testaction"
            if querystring:
                stmt = stmt + " WHERE " + querystring

            self.dbg(stmt)
            c.execute(stmt, values)
            dbs[0] = c.fetchall()
            self.dbg(dbs[0])
Ejemplo n.º 8
0
 def upgrade_environment(self, db):
     cursor = db.cursor()
     dbver = self.env.get_version()
     for i in range(dbver + 1, db_default.db_version + 1):
         name  = 'db%i' % i
         try:
             upgrades = __import__('upgrades', globals(), locals(), [name])
             script = getattr(upgrades, name)
         except AttributeError:
             err = 'No upgrade module for version %i (%s.py)' % (i, name)
             raise TracError, err
         script.do_upgrade(self.env, i, cursor)
     cursor.execute("UPDATE system SET value=%s WHERE "
                    "name='database_version'", (db_default.db_version,))
     self.log.info('Upgraded database version from %d to %d',
                   dbver, db_default.db_version)
 def _insert_report(self, title, author, description, query, uuid,
                    maingroup, subgroup, version, ordering):
     """ Adds a row the custom_report_table """
     self.log.debug("Inserting new report '%s' with uuid '%s'" %
                    (title, uuid))
     new_id = []
     with self.env.db_transaction as db:
         cur = db.cursor()
         cur.execute("DELETE FROM custom_report WHERE uuid=%s", (uuid, ))
         cur.execute(
             "INSERT INTO report (title, author, description, query) "
             "VALUES (%s, %s, %s, %s)", (title, author, description, query))
         new_id.append(db.get_last_id(cur, 'report'))
         cur.execute(
             "INSERT INTO custom_report "
             "(id, uuid, maingroup, subgroup, version, ordering) "
             "VALUES (%s, %s, %s, %s, %s, %s)",
             (new_id[0], uuid, maingroup, subgroup, version, ordering))
     return new_id[0]