示例#1
0
    def match_test_syntax(self, msg, sql):
        """
        Begins/rolls back a transaction at the start/end of a
        test. Accepts a special query syntax: 

        <BEGIN|ROLLBACK> TEST "<test name>";
        """
        for rx, stmt, test in (
            (self.begin_test_re, 'BEGIN', True),
            (self.rollback_test_re, 'ROLLBACK', False),
        ):
            m = rx.match(sql)
            if m:
                # Need to keep track of whether we're currently inside of a test
                # or not. Inside of a test, BEGINs are translated to SAVEPOINTs.
                # Outside of a test they're ignored. (Some drivers, like psyco,
                # automatically issue the BEGINs, so it's not really possible to
                # require that the frontend only issue the begin statements
                # within tests.)
                self.protocol.signalTest(test)

                name = m.groups()[0]
                log.msg('%s test: %s' % (stmt, name))
                ret = self.translate(messages.query('%s; -- %s' %
                                                    (stmt, name)))
                return True, ret

        return self.no_match
示例#2
0
    def match_test_syntax(self, msg, sql):
        """
        Begins/rolls back a transaction at the start/end of a
        test. Accepts a special query syntax: 

        <BEGIN|ROLLBACK> TEST "<test name>";
        """
        for rx, stmt, test in ((self.begin_test_re, 'BEGIN', True), 
                               (self.rollback_test_re, 'ROLLBACK', False),):
            m = rx.match(sql)
            if m:
                # Need to keep track of whether we're currently inside of a test
                # or not. Inside of a test, BEGINs are translated to SAVEPOINTs. 
                # Outside of a test they're ignored. (Some drivers, like psyco, 
                # automatically issue the BEGINs, so it's not really possible to
                # require that the frontend only issue the begin statements 
                # within tests.)
                self.protocol.signalTest(test)

                name = m.groups()[0]
                log.msg('%s test: %s' % (stmt, name))
                ret = self.translate(messages.query('%s; -- %s' % (stmt, name)))
                return True, ret

        return self.no_match
示例#3
0
 def savepoint(self):
     """
     Pushes a new savepoint onto the stack. Names the savepoint uniquely. 
     Returns the query message to be sent to the backend.
     """
     name = 'sp_%s' % str(time.time()).replace('.', '_')
     self.savepoints.append(name)
     return messages.query('SAVEPOINT %s' % name)
示例#4
0
 def savepoint(self):
     """
     Pushes a new savepoint onto the stack. Names the savepoint uniquely. 
     Returns the query message to be sent to the backend.
     """
     name = 'sp_%s' % str(time.time()).replace('.', '_')
     self.savepoints.append(name)
     return messages.query('SAVEPOINT %s' % name)
示例#5
0
 def cleanUpSavepoints(self):
     if not self.protocol.inTest():
         return
     if self.savepoints:
         self.protocol.writePeer(
             [messages.query('ROLLBACK TO SAVEPOINT %s -- cleanup' % (sp,))
              for sp in reversed(self.savepoints)])
         del self.savepoints[:]
         self._ignoreBackendMessages('CZ')
示例#6
0
 def cleanUpSavepoints(self):
     if not self.protocol.inTest():
         return
     if self.savepoints:
         self.protocol.writePeer([
             messages.query('ROLLBACK TO SAVEPOINT %s -- cleanup' % (sp, ))
             for sp in reversed(self.savepoints)
         ])
         del self.savepoints[:]
         self._ignoreBackendMessages('CZ')
示例#7
0
 def translateSavepoint(self, msg, sqlFormat):
     """
     Replaces the msg in the stream with a savepoint operation, and causes
     the backend's replies regarding the savepoint to be ignored. Requires
     a SQL format string that performs the operation, given the name of the
     savepoint. Outside of a test, or if there are no savepoints, msg is
     dropped.
     """
     if self.protocol.inTest() and self.savepoints:
         m = self.translate(
             messages.query(sqlFormat % self.savepoints.pop()))
         self._ignoreBackendMessages('CZ')
     else:
         m = self.drop(msg)
     return True, m
示例#8
0
 def translateSavepoint(self, msg, sqlFormat):
     """
     Replaces the msg in the stream with a savepoint operation, and causes
     the backend's replies regarding the savepoint to be ignored. Requires
     a SQL format string that performs the operation, given the name of the
     savepoint. Outside of a test, or if there are no savepoints, msg is
     dropped.
     """
     if self.protocol.inTest() and self.savepoints:
         m = self.translate(
             messages.query(sqlFormat % self.savepoints.pop()))
         self._ignoreBackendMessages('CZ')
     else:
         m = self.drop(msg)
     return True, m