Example #1
0
def sqladdressbookquery(filter, addressbookid=None):
    """
    Convert the supplied addressbook-query into a partial SQL statement.

    @param filter: the L{Filter} for the addressbook-query to convert.
    @return: a C{tuple} of (C{str}, C{list}), where the C{str} is the partial SQL statement,
            and the C{list} is the list of argument substitutions to use with the SQL API execute method.
            Or return C{None} if it is not possible to create an SQL query to fully match the addressbook-query.
    """
    try:
        expression = buildExpression(filter, sqllitegenerator.FIELDS)
        sql = sqllitegenerator(expression, addressbookid, None)
        return sql.generate()
    except ValueError:
        return None
Example #2
0
def sqladdressbookquery(filter, addressbookid=None):
    """
    Convert the supplied addressbook-query into a partial SQL statement.

    @param filter: the L{Filter} for the addressbook-query to convert.
    @return: a C{tuple} of (C{str}, C{list}), where the C{str} is the partial SQL statement,
            and the C{list} is the list of argument substitutions to use with the SQL API execute method.
            Or return C{None} if it is not possible to create an SQL query to fully match the addressbook-query.
    """
    try:
        expression = buildExpression(filter, sqllitegenerator.FIELDS)
        sql = sqllitegenerator(expression, addressbookid, None)
        return sql.generate()
    except ValueError:
        return None
Example #3
0
    def test_query(self):
        """
        Basic query test - single term.
        Only UID can be queried via sql.
        """

        filter = carddavxml.Filter(
            *[carddavxml.PropertyFilter(
                carddavxml.TextMatch.fromString("Example"),
                **{"name": "UID"}
            )]
        )
        filter = Filter(filter)

        expression = buildExpression(filter, self._queryFields)
        sql = SQLQueryGenerator(expression, self, 1234)
        select, args = sql.generate()

        self.assertEqual(select.toSQL(), SQLFragment("select distinct RESOURCE_NAME, VCARD_UID from ADDRESSBOOK_OBJECT where ADDRESSBOOK_HOME_RESOURCE_ID = ? and VCARD_UID like (? || (? || ?))", [1234, "%", "Example", "%"]))
        self.assertEqual(args, {})
Example #4
0
    def test_query(self):
        """
        Basic query test - single term.
        Only UID can be queried via sql.
        """

        filter = carddavxml.Filter(
            *[carddavxml.PropertyFilter(
                carddavxml.TextMatch.fromString("Example"),
                **{"name":"UID"}
            )]
        )
        filter = Filter(filter)

        expression = buildExpression(filter, self._queryFields)
        sql = SQLQueryGenerator(expression, self, 1234)
        select, args = sql.generate()

        self.assertEqual(select.toSQL(), SQLFragment("select distinct RESOURCE_NAME, VCARD_UID from ADDRESSBOOK_OBJECT where ADDRESSBOOK_HOME_RESOURCE_ID = ? and VCARD_UID like (? || (? || ?))", [1234, "%", "Example", "%"]))
        self.assertEqual(args, {})