Beispiel #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;
}
Beispiel #2
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;
}