[unixODBC-support] Does unixODBC on Mac OS X works?

Lorenzo Moretti lorenzo.moretti at bologna.enea.it
Thu Apr 7 16:45:11 BST 2005


Hi Eric

>  > > DBMI-ODBC driver error: SQLConnect():
>>  > [unixODBC][Driver Manager]Driver's SQLAllocHandle on SQL_HANDLE_HENV
>>  > failed (0)
>
>I'm not sure if this is at all relevent, but at one point while
>developing my driver, I was getting similar errors.  (In my case,
>it was actually IM005, Driver's SQLAllocHandle on SQL_HANDLE_HDBC
>failed.)
>
>This happened because I'd mis-linked the driver, accidently including
>the driver manager in the library list.  The application had requested
>ODBC version 2, in which case the driver manager prefers to call
>SQLAllocEnv/SQLAllocConnect etc. over SQLAllocHandle.  Since my driver
>does not provide a handle allocation routine other than SQLAllocHandle,
>but was linked to the driver manager, the driver manager ended up
>calling itself, rather than SQLAllocHandle in the driver, and that
>lead to the IM005 error.
>
>This is probably not what's happening in your case, but I just thought
>I'd mention it as a possibility.
>
>Eric

This is interesting.
Do you think that I have to change the source code in the application?


The application is GRASS and the code is this:

#include <dbmi.h>
#include "odbc.h"
#include "globals.h"
#include "proto.h"

int open_connection ()
{
     SQLRETURN   ret; 

     /* Allocate Environment handle and register version */
     ret = SQLAllocHandle(SQL_HANDLE_ENV,SQL_NULL_HANDLE, &ODenvi);
     if (( ret != SQL_SUCCESS) && ( ret != SQL_SUCCESS_WITH_INFO))
     {
	report_error("SQLAllocHandle()");
	return DB_FAILED;
     } 

     ret = SQLSetEnvAttr(ODenvi, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0);
     if ((ret != SQL_SUCCESS) && ( ret != SQL_SUCCESS_WITH_INFO))
     { 
    	report_error("SQLSetEnvAttr()");
	SQLFreeHandle(SQL_HANDLE_ENV, ODenvi);
	return DB_FAILED;
     } 

     /* Allocate connection handle */
     ret = SQLAllocHandle(SQL_HANDLE_DBC, ODenvi, &ODconn);
     if (( ret != SQL_SUCCESS) && ( ret != SQL_SUCCESS_WITH_INFO))
     {
	report_error("SQLAllocHandle()");
	SQLFreeHandle(SQL_HANDLE_ENV, ODenvi);
	return DB_FAILED;
     } 

     /* Set timeout */
     SQLSetConnectAttr( ODconn, SQL_LOGIN_TIMEOUT, (SQLPOINTER *)5, 0);

     return DB_OK;
}

int close_connection ()
{
     SQLFreeHandle(SQL_HANDLE_DBC, ODconn);
     SQLFreeHandle(SQL_HANDLE_ENV, ODenvi);    
     return DB_OK;
}



and this

....
cursor * alloc_cursor()
{
     cursor     *c;
     SQLHSTMT   stmt;   
     SQLRETURN  ret;
     char       msg[OD_MSG], emsg[DB_MSG];
     SQLINTEGER err;

     /* allocate the cursor */
     c = (cursor *) db_malloc(sizeof(cursor));
     if (c == NULL)
     {
         report_error("allocate cursor");
         return c;
     }
    
     ret=SQLAllocHandle(SQL_HANDLE_STMT, ODconn, &c->stmt);
     if ((ret != SQL_SUCCESS) && (ret != SQL_SUCCESS_WITH_INFO))
     {
         SQLGetDiagRec(SQL_HANDLE_DBC, ODconn, 1, NULL, &err, msg, 
sizeof(msg), NULL);
         snprintf(emsg, sizeof(emsg), "AllocStatement()\n%s (%d)\n",msg,err);
         report_error(emsg);
         return c;
     } 

     /* tokenize it */
     c->token = db_new_token(c);
     if (c->token < 0)      
     {
	free_cursor (c);
	c = NULL;
         report_error("db_new_token()");
     }

     return c;
}
....


Where are the exact changes?

Thanks


-- 
________________________________________________________________________
||      Lorenzo Moretti        e-mail: lorenzo.moretti at bologna.enea.it     
||/|/|  ENEA prot/idr          Web: http://wwwamb.bologna.enea.it/    
||   |  via Don Fiammelli, 2   FTP: ftp://ftpamb.bologna.enea.it/ (ris.)
~~~~~~  40128 BOLOGNA - ITALY  Ph: +39-0516098086  Fax: +39-0516098131
________________________________________________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.unixodbc.org/pipermail/unixodbc-support/attachments/20050407/771e788a/attachment.html>


More information about the unixODBC-support mailing list