Ticket #7783: pgnulls.diff

File pgnulls.diff, 1022 bytes (added by bthomas@…, 16 years ago)

Patch to map the is_nullable column from information_schema to the null_ok item in cursor.description

  • django/db/backends/postgresql_psycopg2/introspection.py

     
    1515
    1616def get_table_description(cursor, table_name):
    1717    "Returns a description of the table, with the DB-API cursor.description interface."
    18     cursor.execute("SELECT * FROM %s LIMIT 1" % quote_name(table_name))
    19     return cursor.description
     18    cursor.execute("SELECT column_name, is_nullable FROM information_schema.columns WHERE table_name = '%s'" % table_name)
     19    nullmap = dict(cursor.fetchall())
     20    cursor.execute("SELECT * FROM %s WHERE 1=0" % quote_name(table_name))
     21    def fixdesc(row,nullmap=nullmap):
     22        ret = list(row)
     23        ret[6] = nullmap[unicode(ret[0])] == u'YES'
     24        return tuple(ret)
     25    return map(fixdesc, cursor.description)
    2026
    2127def get_relations(cursor, table_name):
    2228    """
Back to Top