'Get the column name of the primary key for the given table.'

def get_primary_key_column(self, cursor, table_name):

    cursor.execute('SELECT    sql    FROM    sqlite_master    WHERE    tbl_name    =    %s    AND    type    =    %s', [table_name, 'table'])
    results = cursor.fetchone()[0].strip()
    results = results[(results.index('(') + 1):results.rindex(')')]
    for field_desc in results.split(','):
        field_desc = field_desc.strip()
        m = re.search('"(.*)".*PRIMARY    KEY$', field_desc)
        if m:
            return m.groups()[0]
    return None
