Ejemplo n.º 1
0
    def test_query_column_name(self):
        # test for bug: http://groups.google.com/group/geoalchemy/browse_thread/thread/6b731dd1673784f9
        from sqlalchemy.orm.query import Query
        query = Query(Road.road_geom).filter(Road.road_geom == '..').__str__()
        ok_('AsBinary(roads.road_geom)' in query, 'table name is part of the column expression (select clause)')
        ok_('WHERE Equals(roads.road_geom' in query, 'table name is part of the column expression (where clause)')

        query_wkb = Select([Road.road_geom]).where(Road.road_geom == 'POINT(0 0)').__str__()
        ok_('SELECT AsBinary(roads.road_geom)' in query_wkb, 'AsBinary is added')
        ok_('WHERE Equals(roads.road_geom' in query_wkb, 'AsBinary is not added in where clause')

        # test for RAW attribute
        query_wkb = Select([Road.road_geom.RAW]).__str__()
        ok_('SELECT roads.road_geom' in query_wkb, 'AsBinary is not added')

        ok_(session.query(Road.road_geom.RAW).first())

        query_srid = Query(func.SRID(Road.road_geom.RAW))
        ok_('SRID(roads.road_geom)' in query_srid.__str__(), 'AsBinary is not added')
        ok_(session.scalar(query_srid))

        eq_(session.scalar(Select([func.SRID(Spot.spot_location)]).where(Spot.spot_id == 1)),
                None,
                'AsBinary is added and the SRID is not returned')
        eq_(str(session.scalar(Select([func.SRID(Spot.spot_location.RAW)]).where(Spot.spot_id == 1))),
                '4326',
                'AsBinary is not added and the SRID is returned')

        spot_alias = aliased(Spot)
        query_wkt = Select([func.wkt(spot_alias.spot_location.RAW)]).__str__()
        ok_('SELECT wkt(spots_1.spot_location' in query_wkt, 'Table alias is used in select clause')
        ok_('FROM spots AS spots_1' in query_wkt, 'Table alias is used in from clause')
Ejemplo n.º 2
0
    def __repr__ (self):

        if self.start is not None:
            start = self.start.isoformat()
        else:
            start = "ever"
        if self.end is not None:
            end = self.end.isoformat()
        else:
            end = "ever"
        repr = "SCMQuery from %s to %s\n" % (start, end)
        repr += Query.__str__(self)
        return repr
Ejemplo n.º 3
0
    def __repr__ (self):

        if self.start is not None:
            start = self.start.isoformat()
        else:
            start = "ever"
        if self.end is not None:
            end = self.end.isoformat()
        else:
            end = "ever"
        repr = "Query from %s to %s\n" % (start, end)
        repr = "  Joined: %s\n" % str(self.joined)
        repr += Query.__str__(self)
        return repr
Ejemplo n.º 4
0
    def test_query_column_name(self):
        # test for bug: http://groups.google.com/group/geoalchemy/browse_thread/thread/6b731dd1673784f9
        from sqlalchemy.orm.query import Query
        query = Query(Road.road_geom).filter(Road.road_geom == '..').__str__()
        ok_('AsBinary(roads.road_geom)' in query,
            'table name is part of the column expression (select clause)')
        ok_('WHERE Equals(roads.road_geom' in query,
            'table name is part of the column expression (where clause)')

        query_wkb = Select([Road.road_geom
                            ]).where(Road.road_geom == 'POINT(0 0)').__str__()
        ok_('SELECT AsBinary(roads.road_geom)' in query_wkb,
            'AsBinary is added')
        ok_('WHERE Equals(roads.road_geom' in query_wkb,
            'AsBinary is not added in where clause')

        # test for RAW attribute
        query_wkb = Select([Road.road_geom.RAW]).__str__()
        ok_('SELECT roads.road_geom' in query_wkb, 'AsBinary is not added')

        ok_(session.query(Road.road_geom.RAW).first())

        query_srid = Query(func.SRID(Road.road_geom.RAW))
        ok_('SRID(roads.road_geom)' in query_srid.__str__(),
            'AsBinary is not added')
        ok_(session.scalar(query_srid))

        eq_(
            session.scalar(
                Select([func.SRID(Spot.spot_location)
                        ]).where(Spot.spot_id == 1)), None,
            'AsBinary is added and the SRID is not returned')
        eq_(
            str(
                session.scalar(
                    Select([func.SRID(Spot.spot_location.RAW)
                            ]).where(Spot.spot_id == 1))), '4326',
            'AsBinary is not added and the SRID is returned')

        spot_alias = aliased(Spot)
        query_wkt = Select([func.wkt(spot_alias.spot_location.RAW)]).__str__()
        ok_('SELECT wkt(spots_1.spot_location' in query_wkt,
            'Table alias is used in select clause')
        ok_('FROM spots AS spots_1' in query_wkt,
            'Table alias is used in from clause')