tanrj / pyodbc

Automatically exported from code.google.com/p/pyodbc
MIT No Attribution
0 stars 0 forks source link

foreignKeys() doesn't work #43

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create database from attached scripts.
2. Run appropriate (MSQQL or MySQL) attached python scripts.

What is the expected output? What do you see instead?
Expected: List of tables and foreign keys.
Instead: Just list of tables.

What version of the product are you using? On what operating system?
WinXP Prof SP3 
Python 2.6.1
pyodbc:
  pyodbc-2.1.1.win32-py2.6.exe, or
  pyodbc-2.1.2.win32-py2.6.exe, or
  pyodbc-2.1.3.win32-py2.6.exe  
SQL Server 2005 Express, or
MySQL 5.0.67 + mysql-connector-odbc-3.51.27

Please provide any additional information below.

Original issue reported on code.google.com by vgarnash...@gmail.com on 2 Apr 2009 at 8:03

Attachments:

GoogleCodeExporter commented 8 years ago
Excellent tests.  The issue is you are calling foreignKeys for the wrong table. 

The first parameter is the primary-key table.  The SQLForeignKey documentation 
is a
bit confusing: http://msdn.microsoft.com/en-us/library/ms709315.aspx

You can either search using "test2":

  for row in conn.cursor().foreignKeys("test2", params['db'], ""):

Or (more likely what you want), use the foreignTable keyword parameter:

  for row in conn.cursor().foreignKeys(foreignTable="test1"):

The parameters (see foreignKeys in http://code.google.com/p/pyodbc/wiki/Cursor) 
are
in the same order as the MSDN ODBC documentation, so that might help.

Original comment by mkleehammer on 19 Apr 2009 at 11:11

GoogleCodeExporter commented 8 years ago

Original comment by mkleehammer on 21 Nov 2010 at 4:43