Changeset 726


Ignore:
Timestamp:
Jan 12, 2016, 11:33:00 AM (4 years ago)
Author:
cito
Message:

Use query parameter again

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.x/pg.py

    r725 r726  
    424424            if schemas:  # non-empty path
    425425                # search schema for this object in the current search path
     426                # (we could also use unnest with ordinality here to spare
     427                # one query, but this is only possible since PostgreSQL 9.4)
    426428                q = ' UNION '.join(
    427429                    ["SELECT %d::integer AS n, '%s'::name AS nspname"
    428430                        % s for s in enumerate(schemas)])
    429                 q = ("SELECT nspname FROM pg_class"
    430                     " JOIN pg_namespace"
    431                     " ON pg_class.relnamespace = pg_namespace.oid"
     431                q = ("SELECT nspname FROM pg_class r"
     432                    " JOIN pg_namespace s ON r.relnamespace = s.oid"
    432433                    " JOIN (%s) AS p USING (nspname)"
    433                     " WHERE pg_class.relname = '%s'"
    434                     " ORDER BY n LIMIT 1" % (q, cl))
    435                 schema = self.db.query(q).getresult()
     434                    " WHERE r.relname = $1 ORDER BY n LIMIT 1" % q)
     435                schema = self.db.query(q, (cl,)).getresult()
    436436                if schema:  # schema found
    437437                    schema = schema[0][0]
  • trunk/pg.py

    r725 r726  
    436436            if schemas:  # non-empty path
    437437                # search schema for this object in the current search path
     438                # (we could also use unnest with ordinality here to spare
     439                # one query, but this is only possible since PostgreSQL 9.4)
    438440                q = ' UNION '.join(
    439441                    ["SELECT %d::integer AS n, '%s'::name AS nspname"
    440442                        % s for s in enumerate(schemas)])
    441                 q = ("SELECT nspname FROM pg_class"
    442                     " JOIN pg_namespace"
    443                     " ON pg_class.relnamespace = pg_namespace.oid"
     443                q = ("SELECT nspname FROM pg_class r"
     444                    " JOIN pg_namespace s ON r.relnamespace = s.oid"
    444445                    " JOIN (%s) AS p USING (nspname)"
    445                     " WHERE pg_class.relname = '%s'"
    446                     " ORDER BY n LIMIT 1" % (q, cl))
    447                 schema = self.db.query(q).getresult()
     446                    " WHERE r.relname = $1 ORDER BY n LIMIT 1" % q)
     447                schema = self.db.query(q, (cl,)).getresult()
    448448                if schema:  # schema found
    449449                    schema = schema[0][0]
Note: See TracChangeset for help on using the changeset viewer.