8 | | raise NotImplementedError |
| 25 | """ |
| 26 | Returns a dictionary of {field_index: (field_index_other_table, other_table)} |
| 27 | representing all relationships to the given table. Indexes are 0-based. |
| 28 | """ |
| 29 | my_field_dict = _name_to_index(cursor, table_name) |
| 30 | cursor.execute("sp_fkeys @fktable_name='%s'" % u"ForeginTable1") |
| 31 | their_field_dicts = {} |
| 32 | result = {} |
| 33 | for row in util.dictfetchall(cursor): |
| 34 | if row[u'FKTABLE_NAME'] != table_name: |
| 35 | continue |
| 36 | if not their_field_dicts.get(row[u'PKTABLE_NAME']): |
| 37 | their_field_dicts[row[u'PKTABLE_NAME'] |
| 38 | ] = _name_to_index(cursor, row[u'PKTABLE_NAME']) |
| 39 | their_fields = their_field_dicts[row[u'PKTABLE_NAME']] |
| 40 | result[my_field_dict[row[u'FKCOLUMN_NAME']]] = ( |
| 41 | their_fields[row[u'PKCOLUMN_NAME']], |
| 42 | row[u'PKTABLE_NAME']) |
| 43 | return result |
| 44 | |
11 | | raise NotImplementedError |
| 47 | """ |
| 48 | Returns a dictionary of fieldname -> infodict for the given table, |
| 49 | where each infodict is in the format: |
| 50 | {'primary_key': boolean representing whether it's the primary key, |
| 51 | 'unique': boolean representing whether it's a unique index} |
| 52 | """ |
| 53 | cursor.execute("sp_helpindex @objname='%s'" % table_name) |
| 54 | indexes = {} |
| 55 | try: |
| 56 | rows = cursor.fetchall() |
| 57 | except adodbapi.adodbapi.Error, e: |
| 58 | if e.args == (None,): |
| 59 | rows = [] # this is a workaround because I don't understand |
| 60 | # why this error comes up. Will report to adodbapi |
| 61 | else: |
| 62 | raise |
| 63 | |
| 64 | for row in rows: |
| 65 | flags = row[1] |
| 66 | flagdict = {'primary_key': 'primary key' in flags, |
| 67 | 'unique': 'unique' in flags} |
| 68 | indexes[row[2]] = flagdict |
| 69 | return indexes |
| 70 | |