Ejemplo n.º 1
0
RETCODE SQL_API SQLParamData(
									 HSTMT hstmt,
									 PTR*  prgbValue)
{
	stmt_t*  pstmt = hstmt;
	int      ipar;
	param_t* ppar;
	fptr_t      cvt;
	char*    data;
	date_t      dt;

	UNSET_ERROR( pstmt->herr );

	ipar = pstmt->putipar;
	ppar = pstmt->ppar + ipar - 1;

	if ( ipar )
	{
		ppar->need = 0;
		pstmt->ndelay --;

		if ( ppar->ctype == SQL_C_CHAR )
		{
			if ( ! ppar->putdtbuf && ! ppar->putdtlen )
				data = 0;
			else
			{
				cvt = ppar->cvt;
				data= cvt(ppar->putdtbuf, ppar->putdtlen, &dt);
			}

			MEM_FREE( ppar->putdtbuf );
			ppar->putdtbuf = 0;
			ppar->putdtlen = 0;

			if ( data == (char*)(-1) )
			{
				PUSHSQLERR( pstmt->herr, en_S1000 );

				return SQL_ERROR;
			}

			sqlputdata( pstmt, ipar, data );
		}
	}

	if ( pstmt->ndelay )
	{
		for (ipar++, ppar++;;)
		{
			if ( ppar->need )
			{
				*prgbValue = (PTR)(ppar->userbuf);
				pstmt->putipar = ipar;

				return SQL_NEED_DATA;
			}
		}
	}

	if ( nnsql_execute(pstmt->yystmt) )
	{
		int   code;

		code = nnsql_errcode( pstmt->yystmt );

		if ( code == -1 )
			code = errno;

		PUSHSYSERR( pstmt->herr, code, nnsql_errmsg(pstmt->yystmt));

		return SQL_ERROR;
	}

	if ( ! nnsql_getcolnum(pstmt->yystmt)
		  && nnsql_getrowcount(pstmt->yystmt) > 1 )
	{
		PUSHSQLERR( pstmt->herr, en_01S04);

		return SQL_SUCCESS_WITH_INFO;
	}

	return SQL_SUCCESS;
}
Ejemplo n.º 2
0
Archivo: connect.c Proyecto: EdgarTx/wx
/* - Load driver share library( or increase its reference count 
 *   if it has already been loaded by another active connection)
 * - Call driver's SQLAllocEnv() (for the first reference only)
 * - Call driver's SQLAllocConnect()
 * - Call driver's SQLSetConnectOption() (set login time out)
 * - Increase the bookkeeping reference count
 */
static RETCODE 
_iodbcdm_driverload (
    char FAR * path,
    HDBC hdbc)
{
  DBC_t FAR *pdbc = (DBC_t FAR *) hdbc;
  GENV_t FAR *genv;
  ENV_t FAR *penv = NULL;
  HDLL hdll;
  HPROC hproc;
  RETCODE retcode = SQL_SUCCESS;
  int sqlstat = en_00000;

  if (path == NULL || path[0] == '\0')
    {
      PUSHSQLERR (pdbc->herr, en_IM002);

      return SQL_ERROR;
    }

  if (hdbc == SQL_NULL_HDBC || pdbc->genv == SQL_NULL_HENV)
    {
      return SQL_INVALID_HANDLE;
    }

  genv = (GENV_t FAR *) pdbc->genv;

  /* This will either load the driver dll or increase its reference count */
  hdll = _iodbcdm_dllopen ((char FAR *) path);

  if (hdll == SQL_NULL_HDLL)
    {
      PUSHSYSERR (pdbc->herr, _iodbcdm_dllerror ());
      PUSHSQLERR (pdbc->herr, en_IM003);
      return SQL_ERROR;
    }

  penv = (ENV_t FAR *) (pdbc->henv);

  if (penv != NULL)
    {
      if (penv->hdll != hdll)
	{
	  _iodbcdm_driverunload (hdbc);
	}
      else
	{
	  /* 
  	   * this will not unload the driver but only decrease its internal
	   * reference count 
	   */
	  _iodbcdm_dllclose (hdll);
	}
    }

  if (penv == NULL)
    {
      /* 
       * find out whether this dll has already been loaded on another 
       * connection 
       */
      for (penv = (ENV_t FAR *) genv->henv; 
	  penv != NULL;
	  penv = (ENV_t FAR *) penv->next)
	{
	  if (penv->hdll == hdll)
	    {
	      /* 
  	       * this will not unload the driver but only decrease its internal
	       * reference count 
	       */
	      _iodbcdm_dllclose (hdll);
	      break;
	    }
	}

      if (penv == NULL)
	/* no connection attaching with this dll */
	{
	  int i;

	  /* create a new dll env instance */
	  penv = (ENV_t FAR *) MEM_ALLOC (sizeof (ENV_t));

	  if (penv == NULL)
	    {
	      _iodbcdm_dllclose (hdll);

	      PUSHSQLERR (pdbc->herr, en_S1001);

	      return SQL_ERROR;
	    }

	  for (i = 0; i < SQL_EXT_API_LAST + 1; i++)
	    {
	      (penv->dllproc_tab)[i] = SQL_NULL_HPROC;
	    }

	  pdbc->henv = penv;
	  penv->hdll = hdll;

	  /* call driver's SQLAllocHandle() or SQLAllocEnv() */

#if (ODBCVER >= 0x0300)
	  hproc = _iodbcdm_getproc (hdbc, en_AllocHandle);

	  if (hproc)
	    {
	      CALL_DRIVER (hdbc, retcode, hproc, en_AllocHandle,
		  (SQL_HANDLE_ENV, SQL_NULL_HANDLE, &(penv->dhenv)))
	    }
	  else			/* try driver's SQLAllocEnv() */
#endif
	    {
	      hproc = _iodbcdm_getproc (hdbc, en_AllocEnv);

	      if (hproc == SQL_NULL_HPROC)
		{
		  sqlstat = en_IM004;
		}
	      else
		{
		  CALL_DRIVER (hdbc, retcode, hproc,
		      en_AllocEnv, (&(penv->dhenv)))
		}
	    }

	  if (retcode == SQL_ERROR)
	    {
	      sqlstat = en_IM004;
	    }

	  if (sqlstat != en_00000)
	    {
	      _iodbcdm_dllclose (hdll);
	      MEM_FREE (penv);
	      PUSHSQLERR (pdbc->herr, en_IM004);

	      return SQL_ERROR;
	    }

	  /* insert into dll env list */
	  penv->next = (ENV_t FAR *) genv->henv;
	  genv->henv = penv;

	  /* initiate this new env entry */
	  penv->refcount = 0;	/* we will increase it after
				 * driver's SQLAllocConnect()
				 * success
				 */
	}
Ejemplo n.º 3
0
void	nnodbc_pushdbcerr( void* hdbc, int code, char* msg )
{
	PUSHSYSERR( ((dbc_t*)hdbc)->herr, code, msg );
}
Ejemplo n.º 4
0
RETCODE SQL_API SQLFetch( HSTMT hstmt )
{
	stmt_t*  pstmt = hstmt;
	column_t*   pcol = pstmt->pcol;
	int      ncol, i;
	long     len, clen;
	char*    ptr;
	int      sqltype, sqlstat, dft_ctype, flag = 0, err;
	fptr_t      cvt;
	char*    ret;

	UNSET_ERROR( pstmt->herr );

	ncol = nnsql_getcolnum(pstmt->yystmt);

	if ( !pstmt->refetch && (err = nnsql_fetch(pstmt->yystmt)) )
	{
		int   code;

		if ( err == 100 )
			return SQL_NO_DATA_FOUND;

		code = nnsql_errcode(pstmt->yystmt);

		if ( code == -1 )
			code = errno;

		PUSHSYSERR( pstmt->herr, code, nnsql_errmsg(pstmt->yystmt));

		return SQL_ERROR;
	}

	if ( !pcol )
	{
		int   max;

		max = nnsql_max_column();

		pcol = pstmt->pcol = (column_t*)MEM_ALLOC( sizeof(column_t)*(max+1) );

		if ( ! pcol )
		{
			PUSHSQLERR( pstmt->herr, en_S1001 );

			return SQL_ERROR;
		}

		MEM_SET(pcol, 0, sizeof(column_t)*(max+1) );

		return SQL_SUCCESS;
	}

	for (i=0;i<ncol;i++, pcol++)
	{
		len = clen = 0L;
		pcol->offset = 0;

		if ( ! pcol->userbuf )
			continue;

		if ( nnsql_isnullcol(pstmt->yystmt, i) )
		{
			if ( pcol->pdatalen )
				*(pcol->pdatalen) = SQL_NULL_DATA;
			continue;
		}

		if ( pcol->pdatalen )
			*(pcol->pdatalen ) = 0L;

		if ( nnsql_isstrcol(pstmt->yystmt, i) )
		{
			ptr = nnsql_getstr(pstmt->yystmt, i);
			len = STRLEN(ptr) + 1;
			sqltype = SQL_CHAR;
			dft_ctype = SQL_C_CHAR;
		}
		else if ( nnsql_isnumcol(pstmt->yystmt, i) )
		{
			ptr = (char*)nnsql_getnum(pstmt->yystmt, i);
			sqltype = SQL_INTEGER;
			dft_ctype = SQL_C_LONG;
		}
		else if ( nnsql_isdatecol(pstmt->yystmt, i) )
		{
			ptr = (char*)nnsql_getdate(pstmt->yystmt, i);
			sqltype = SQL_DATE;
			dft_ctype = SQL_C_DATE;
		}
		else
			abort();

		if ( pcol->ctype == SQL_C_DEFAULT )
			pcol->ctype = dft_ctype;

		cvt = nnodbc_get_sql2c_cvt(sqltype, pcol->ctype);

		if ( ! cvt )
		{
			pstmt->refetch = 1;

			PUSHSQLERR(pstmt->herr, en_07006);

			return SQL_ERROR;
		}

		ret = cvt(  ptr, pcol->userbuf, pcol->userbufsize, &clen);

		if ( ret )
		{
			pstmt->refetch = 1;

			if ( clen )
				sqlstat = en_22003;
			else
				sqlstat = en_22005;

			PUSHSQLERR( pstmt->herr, sqlstat );

			return SQL_ERROR;
		}

		if ( len && clen == len )
			flag = 1;

		if ( len && pcol->pdatalen )
			*(pcol->pdatalen) = clen;	/* not 'len' but 'clen' */
	}

	if ( flag )
	{
		PUSHSQLERR( pstmt->herr, en_01004 );

		return SQL_SUCCESS_WITH_INFO;
	}

	return SQL_SUCCESS;
}