Skip to content

Conversation

@nattster
Copy link

@nattster nattster commented Jul 4, 2017

As suggested by @shaib that Oracle backends encountered this issue as well,
they workaround by grouping parameter with same value & type. Then send modified SQL & named parameter to Database engine.

This code transform following SQL:

cursor.execute('''
SELECT 
    SUBSTRING([auth_user].[username], ?, ?) AS [first_letter], 
    COUNT_BIG([auth_user].[id]) AS [user_count] 
FROM [auth_user] 
GROUP BY SUBSTRING([auth_user].[username], ?, ?) 
ORDER BY [first_letter] ASC
''', (1, 1, 1, 1)
)

into:

cursor.execute('''
DECLARE @args0 INT = ?
SELECT 
    SUBSTRING([auth_user].[username], @args0, @args0) AS [first_letter], 
    COUNT_BIG([auth_user].[id]) AS [user_count] 
FROM [auth_user] 
GROUP BY SUBSTRING([auth_user].[username], @args0, @args0) 
ORDER BY [first_letter] ASC
''', (1, )
)

Since, pyodbc does not support Named Parameter. I have to declare variable instead.
I know that this pull request need a lot of code clean up.

It is working for me now, but would like you to help review it to improve, especially the part that map Python Data Type to SQL DataType. Suggestions/correction are greatly appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant