예제 #1
0
파일: sqlite.py 프로젝트: piranna/AntiORM
    def _multiple_statement_standard__list(self, stmts):
        """
        Factory for functions with multiple statements by list

        @param stmts: the list of sql queries
        @type stmts: iterable of strings

        @return: the optimized function
        @rtype: method function
        """
        sql = named2pyformat(''.join(stmts))

        def _wrapped_method(self, list_kwargs):
            """
            Exec the statement and return the a list of lists of results

            @param list_kwargs: a list with the keyword arguments of the query
            @type list_kwargs: list of dicts

            @return: the list of lists of results of execute
            @rtype: list of lists
            """
            list_kwargs = map(_quote_sql_fromdict, list_kwargs)

            result = []
            with self.tx_manager as conn:
                cursor = conn.cursor()

                for kwargs in list_kwargs:
                    result.append(cursor.executescript(sql % kwargs))
            return result

        return _wrapped_method
예제 #2
0
파일: sqlite.py 프로젝트: piranna/AntiORM
    def _multiple_statement_standard__dict(self, stmts):
        """
        Factory for functions with multiple statements by dict

        @param stmts: the list of sql queries
        @type stmts: iterable of strings

        @return: the optimized function
        @rtype: method function
        """
        sql = named2pyformat(''.join(stmts))

        def _wrapped_method(self, kwargs):
            """
            Exec the statement and return the result of executes

            @param kwargs: the keyword arguments of the query
            @type kwargs: dict

            @return: the result of executes
            @rtype: list
            """
            kwargs = _quote_sql_fromdict(kwargs)

            with self.tx_manager as conn:
                cursor = conn.cursor()

                return cursor.executescript(sql % kwargs)

        return _wrapped_method
예제 #3
0
파일: utils.py 프로젝트: piranna/AntiORM
 def test_named2pyformat(self):
     self.assertEqual(named2pyformat(""), "")
     self.assertEqual(named2pyformat("asdf"), "asdf")
     self.assertEqual(named2pyformat("a :formated word"),
                      "a %(formated)s word")