sqldata/sqlsncapi.cpp
// Write LOB data using BCP API
Write LOB data using BCP API
Write LOB data using BCP API
int SqlSncApi::WriteLob(SqlCol *s_cols, size_t row, size_t *lob_bytes)
{
	if(s_cols == NULL || _bcp_lob_exists == false || _source_api_provider == NULL)
		return -1;
	int rc = 0;
	size_t len = 0;
	size_t row_len = 0;
	char *data = NULL;
	for(size_t k = 0; k < _bcp_cols_count; k++)
	{
		if(s_cols[k]._lob == false && _bcp_cols[k]._lob == false)
			continue;
		if(_source_api_type == SQLDATA_ORACLE)
		{
			if(s_cols[k]._ind2[row] == -1)
			{
				rc = _bcp_moretext(_hdbc, SQL_NULL_DATA, NULL);
				continue;
			}
			rc = _source_api_provider->GetLobLength(row, k, (size_t*)&len);
			if(rc == -1)
				break;
			if(len == 0)
			{
				rc = _bcp_moretext(_hdbc, 0, (LPCBYTE)"");
				continue;
			}
			data = new char[(size_t)len];
			rc = _source_api_provider->GetLobContent(row, k, data, (size_t)len, NULL);
			if(rc != -1)
			{
				rc = _bcp_moretext(_hdbc, (DBINT)len, (LPCBYTE)data);
				row_len += len;
			}
		}
		else
		if(_source_api_type == SQLDATA_SYBASE)
		{
			if(s_cols[k]._ind2[row] == -1)
			{
				rc = _bcp_moretext(_hdbc, SQL_NULL_DATA, NULL);
				continue;
			}
			len = (size_t)s_cols[k]._len_ind4[row];
			if(len == 0)
			{
				rc = _bcp_moretext(_hdbc, 0, (LPCBYTE)"");
				continue;
			}
			rc = _bcp_moretext(_hdbc, (DBINT)len, (LPCBYTE)s_cols[k]._data + s_cols[k]._fetch_len * row);
			row_len += len;
		}
		else
		if(_source_api_type == SQLDATA_SQL_SERVER || _source_api_type == SQLDATA_DB2 || _source_api_type == SQLDATA_INFORMIX || 
			_source_api_type == SQLDATA_ASA || _source_api_type == SQLDATA_ODBC)
		{
			if(s_cols[k].ind != NULL)
			{
				len = s_cols[k].ind[row];
#if defined(WIN64)
				if(_source_api_type == SQLDATA_DB2 && s_cols[k].ind[0] & 0xFFFFFFFF00000000)
					len = (size_t)((SQLINTEGER*)(s_cols[k].ind))[row];
#endif
			}
			if(len == -1)
			{
				rc = _bcp_moretext(_hdbc, SQL_NULL_DATA, NULL);
				continue;
			}
			else
			if(len == 0)
			{
				rc = _bcp_moretext(_hdbc, 0, (LPCBYTE)"");
				if(rc == FAIL)
					SetError(SQL_HANDLE_DBC, _hdbc);
				continue;
			}
			bool more = true;
			while(more)
			{
				rc = _bcp_moretext(_hdbc, (DBINT)len, (LPCBYTE)(s_cols[k]._data + s_cols[k]._fetch_len * row));
				if(rc == FAIL)
					SetError(SQL_HANDLE_DBC, _hdbc);
				row_len += len;
				if(s_cols[k]._lob_fetch_status != SQL_SUCCESS_WITH_INFO)
				{
					more = false;
					break;
				}
				int read_rc = _source_api_provider->GetLobPart(0, k, NULL, 0, NULL);
				if(read_rc == -1)
					break;
				len = s_cols[k].ind[row];
			}
		}
		else
		if(_source_api_type == SQLDATA_MYSQL)
		{
			if(s_cols[k].ind != NULL)
				len = s_cols[k].ind[row];
			if(len == -1)
			{
				rc = _bcp_moretext(_hdbc, SQL_NULL_DATA, NULL);
				continue;
			}
			else
			if(len == 0)
			{
				rc = _bcp_moretext(_hdbc, 0, (LPCBYTE)"");
				if(rc == FAIL)
					SetError(SQL_HANDLE_DBC, _hdbc);
				continue;
			}
			rc = _bcp_moretext(_hdbc, (DBINT)len, (LPCBYTE)s_cols[k]._data);
			row_len += len;
		}
		rc = _bcp_moretext(_hdbc, 0, NULL);
		if(rc == FAIL)
			SetError(SQL_HANDLE_DBC, _hdbc);
		delete data;
		data = NULL;
	}
	if(rc != FAIL && lob_bytes != NULL)
		*lob_bytes = row_len;
	return rc;
}
int SqlSncApi :: WriteLob ( SqlCol * s_cols , size_t row , size_t * lob_bytes ) { if ( s_cols == NULL || _bcp_lob_exists == false || _source_api_provider == NULL ) return -1 ; int rc = 0 ; size_t len = 0 ; size_t row_len = 0 ; char * data = NULL ; for ( size_t k = 0 ; k < _bcp_cols_count ; k ++ ) { if ( s_cols [ k ] . _lob == false && _bcp_cols [ k ] . _lob == false ) continue ; if ( _source_api_type == SQLDATA_ORACLE ) { if ( s_cols [ k ] . _ind2 [ row ] == -1 ) { rc = _bcp_moretext ( _hdbc , SQL_NULL_DATA , NULL ) ; continue ; } rc = _source_api_provider -> GetLobLength ( row , k , ( size_t * ) & len ) ; if ( rc == -1 ) break ; if ( len == 0 ) { rc = _bcp_moretext ( _hdbc , 0 , ( LPCBYTE ) " " ) ; continue ; } data = new char [ ( size_t ) len ] ; rc = _source_api_provider -> GetLobContent ( row , k , data , ( size_t ) len , NULL ) ; if ( rc != -1 ) { rc = _bcp_moretext ( _hdbc , ( DBINT ) len , ( LPCBYTE ) data ) ; row_len += len ; } } else if ( _source_api_type == SQLDATA_SYBASE ) { if ( s_cols [ k ] . _ind2 [ row ] == -1 ) { rc = _bcp_moretext ( _hdbc , SQL_NULL_DATA , NULL ) ; continue ; } len = ( size_t ) s_cols [ k ] . _len_ind4 [ row ] ; if ( len == 0 ) { rc = _bcp_moretext ( _hdbc , 0 , ( LPCBYTE ) " " ) ; continue ; } rc = _bcp_moretext ( _hdbc , ( DBINT ) len , ( LPCBYTE ) s_cols [ k ] . _data + s_cols [ k ] . _fetch_len * row ) ; row_len += len ; } else if ( _source_api_type == SQLDATA_SQL_SERVER || _source_api_type == SQLDATA_DB2 || _source_api_type == SQLDATA_INFORMIX || _source_api_type == SQLDATA_ASA || _source_api_type == SQLDATA_ODBC ) { if ( s_cols [ k ] . ind != NULL ) { len = s_cols [ k ] . ind [ row ] ; #if defined ( WIN64 ) if ( _source_api_type == SQLDATA_DB2 && s_cols [ k ] . ind [ 0 ] & 0xFFFFFFFF00000000 ) len = ( size_t ) ( ( SQLINTEGER * ) ( s_cols [ k ] . ind ) ) [ row ] ; #endif } if ( len == -1 ) { rc = _bcp_moretext ( _hdbc , SQL_NULL_DATA , NULL ) ; continue ; } else if ( len == 0 ) { rc = _bcp_moretext ( _hdbc , 0 , ( LPCBYTE ) " " ) ; if ( rc == FAIL ) SetError ( SQL_HANDLE_DBC , _hdbc ) ; continue ; } bool more = true ; while ( more ) { rc = _bcp_moretext ( _hdbc , ( DBINT ) len , ( LPCBYTE ) ( s_cols [ k ] . _data + s_cols [ k ] . _fetch_len * row ) ) ; if ( rc == FAIL ) SetError ( SQL_HANDLE_DBC , _hdbc ) ; row_len += len ; if ( s_cols [ k ] . _lob_fetch_status != SQL_SUCCESS_WITH_INFO ) { more = false ; break ; } int read_rc = _source_api_provider -> GetLobPart ( 0 , k , NULL , 0 , NULL ) ; if ( read_rc == -1 ) break ; len = s_cols [ k ] . ind [ row ] ; } } else if ( _source_api_type == SQLDATA_MYSQL ) { if ( s_cols [ k ] . ind != NULL ) len = s_cols [ k ] . ind [ row ] ; if ( len == -1 ) { rc = _bcp_moretext ( _hdbc , SQL_NULL_DATA , NULL ) ; continue ; } else if ( len == 0 ) { rc = _bcp_moretext ( _hdbc , 0 , ( LPCBYTE ) " " ) ; if ( rc == FAIL ) SetError ( SQL_HANDLE_DBC , _hdbc ) ; continue ; } rc = _bcp_moretext ( _hdbc , ( DBINT ) len , ( LPCBYTE ) s_cols [ k ] . _data ) ; row_len += len ; } rc = _bcp_moretext ( _hdbc , 0 , NULL ) ; if ( rc == FAIL ) SetError ( SQL_HANDLE_DBC , _hdbc ) ; delete data ; data = NULL ; } if ( rc != FAIL && lob_bytes != NULL ) * lob_bytes = row_len ; return rc ; }
Write LOB data using BCP API
Write LOB data using BCP API
// LOB is NULL // LOB contains data // LOB is empty // Get LOB content // Write LOB // Sybase ASE // LOB is NULL // LOB is empty // Write the full LOB value // First chunk already read, BCP indicator is 4-byte on both 32-bit and 64-bit platforms // DB2 11 64-bit CLI driver still writes indicators to 4-byte array // LOB is NULL // LOB is empty // Get LOB in chunks // Write the current chunk // No more chunks // Read next chunk // Full value already read // LOB is NULL // LOB is empty // Write the full LOB value // End the current LOB