blue-yonder / turbodbc

Turbodbc is a Python module to access relational databases via the Open Database Connectivity (ODBC) interface. The module complies with the Python Database API Specification 2.0.
http://turbodbc.readthedocs.io/en/latest
MIT License
607 stars 85 forks source link

Issues Parsing Multiple Result Sets #385

Open david-engelmann opened 1 year ago

david-engelmann commented 1 year ago

the cursor object description is not updated when cursor.nextset is called. I'll need to dive deeper to see where the issue occurs. The problem is that when parsing multiple result sets you can't tell which set you are looking at

david-engelmann commented 1 year ago

Branch for tracking progress.

@for_one_database
def test_next_set_with_many_column_names(dsn, configuration):                                                                                                                                                                                                            
    cursor = connect(dsn, **get_credentials(configuration)).cursor()                                                                                                                                                                                                     
    cursor.execute("SELECT 1 as Column1;Select 2 as Column2;Select 3 as Column3;Select 4 as Column4")                                                                                                                                                                
    result_one = cursor.fetchallnumpy()                                                                                                                                                                                                                                  
    print(result_one)                                                                                                                                                                                                                                                   
    cursor.nextset()                                                                                                                                                                                                                                                   
    result_two = cursor.fetchallnumpy()                                                                                                                                                                                                                                
    print(result_two)                                                                                                                                                                                                                                                    
    cursor.nextset()                                                                                                                                                                                                                                                  
    result_three = cursor.fetchallnumpy()                                                                                                                                                                                                                             
    print(result_three)                                                                                                                                                                                                                                                  
    cursor.nextset()                                                                                                                                                                                                                                                   
    result_four = cursor.fetchallnumpy()                                                                                                                                                                                                                               
    print(result_four)

----------------------------- Captured stdout call -----------------------------

OrderedDict([('column1', masked_array(data=[1], mask=False,  fill_value=999999))])
OrderedDict([('column1', masked_array(data=[2], mask=False,  fill_value=999999))])
OrderedDict([('column1', masked_array(data=[3], mask=False,  fill_value=999999))])
OrderedDict([('column1', masked_array(data=[4], mask=False,  fill_value=999999))])
david-engelmann commented 1 year ago

Relevant Documentation of SQLMoreResults

I believe the most relevant section is as follows:

When SQLMoreResults returns SQL_ERROR or SQL_SUCCESS_WITH_INFO, an associated SQLSTATE value can be obtained by calling SQLGetDiagRec with a HandleType of SQL_HANDLE_STMT and a Handle of StatementHandle.