Search code examples
carraysreturnodbc

How can I return an SQLPOINTER Array in C?


I have a simple program that reads data from a Database, I am using ODBC, but I want to save the data or a row in an Array. I have it saved in an SQLPOINTER col[50]. How can I return the entire array? Is it possible? NB, I do not want to print the data in the array, I simply just want the values in the Array(I have that already), and return the entire array so that who ever calls the function has the data that they queried from the Database. Can anyone offer any advise? I am sort of a newbie so please have a little patience :-) Thank you very much. The function that I have is:

SQLPOINTER ColPtrArray[50]
SQLPOINTER db_getData(SQLHSTMT handle)
{   
    retcode = SQLFetch(handle);
    CHECK_ERROR(retcode, "SQLFetch()", handle, SQL_HANDLE_STMT);
    if(retcode == SQL_SUCCESS)
    {
        printf("\nSQL_SUCCESS\n");
        return ColPtrArray;
    }

    exit:
    printf("JJJ");
}

Can the return work? How can the caller handle the array that is returned? When SQLFETCH is executed, the array gets populated with the values of the table. This function, i did not include. Yes, not all paths return a value. Thanks for pointing that out.


Solution

  • I solved it. For the guy that said that my code makes no sense, thank you for the unnecessary comment, but he is right. I cannot return an entire array. What I did is pass in an array as one of the arguments and copied the values of the array to the array that was passed. I also changed that all paths returned a value. thanks for pointing that out. Maybe it is not the best solution, what do you guys think?