Ejemplo n.º 1
0
// S_OK : 성공
// S_FALSE : 데이터는 가져왔지만 Consumer가 원하는 데이터가 아님
// E_FAIL : 실패
static HRESULT FetchData(int hReq, CTablesInfoRow &tirData, int table_type)
{
	char *value;
	int int_value;
	int ind, res;
	T_CCI_ERROR err_buf;
	
	res = cci_fetch(hReq, &err_buf);
	if(res<0) return RaiseError(E_FAIL, 1, __uuidof(IDBSchemaRowset), err_buf.err_msg);

	res = cci_get_data(hReq, 1, CCI_A_TYPE_STR, &value, &ind);
	if(res<0) return RaiseError(E_FAIL, 0, __uuidof(IDBSchemaRowset));
	wcscpy(tirData.m_szTableName, CA2W(value));
	
	res = cci_get_data(hReq, 2, CCI_A_TYPE_INT, &int_value, &ind);
	if(res<0) return RaiseError(E_FAIL, 0, __uuidof(IDBSchemaRowset));

	if (table_type >= 0 && table_type != int_value)
		return S_FALSE;

	if (int_value == 2)
		wcscpy(tirData.m_szTableType, L"TABLE");
	else if (int_value == 1)
		wcscpy(tirData.m_szTableType, L"VIEW");
	else if (int_value == 0)
		wcscpy(tirData.m_szTableType, L"SYSTEM TABLE");

	tirData.m_bBookmarks = ATL_VARIANT_TRUE;
	tirData.m_bBookmarkType = DBPROPVAL_BMK_NUMERIC;
	tirData.m_bBookmarkDatatype = DBTYPE_BYTES;
	tirData.m_bBookmarkMaximumLength = sizeof(DBROWCOUNT);

	return S_OK;
}
Ejemplo n.º 2
0
int DbGetString(int qid,int col,char **buf){
	int len, ret;
	ret = cci_get_data(qid, col, CCI_A_TYPE_STR, buf, &len);
	if(ret >= 0)
		return len;
	else return -1;
}
Ejemplo n.º 3
0
//수행도중 에러가 나도 S_OK  리턴
//에러시 cardinality는 0이 된다.
static HRESULT GetCardinality(int hConn, WCHAR* tableName, ULARGE_INTEGER* cardinality)
{
	CComBSTR query;
	T_CCI_ERROR error;
	int hReq, res, ind;

	query.Append("select count(*) from ");
	query.Append(tableName);

	hReq = cci_prepare(hConn, CW2A(query.m_str), 0, &error);
	if (hReq < 0)
		return S_OK;

	res = cci_execute(hReq, CCI_EXEC_QUERY_ALL, 0, &error);
	if (res < 0)
		return S_OK;

	res = cci_cursor(hReq, 1, CCI_CURSOR_FIRST, &error);
	if(res<0) return S_OK;

	res = cci_fetch(hReq, &error);
	if(res<0) return S_OK;

	res = cci_get_data(hReq, 1, CCI_A_TYPE_INT, &cardinality->QuadPart, &ind);
	if(res<0) return S_OK;

	cci_close_req_handle(hReq);

	return S_OK;
}
Ejemplo n.º 4
0
float DbGetFloat(int qid,int col){
	int len, ret;
	float num;
	ret = cci_get_data(qid, col, CCI_A_TYPE_FLOAT, &num, &len);
	if(ret >= 0)
		return num;
	else return -1;
}
Ejemplo n.º 5
0
int DbGetNumber(int qid,int col){
	int len, ret;
	int num;
	ret = cci_get_data(qid, col, CCI_A_TYPE_INT, &num, &len);
	if(ret >= 0)
		return num;
	else return -1;
}
Ejemplo n.º 6
0
// S_OK : 성공
// S_FALSE : 데이터는 가져왔지만 Consumer가 원하는 데이터가 아님
// E_FAIL : 실패
static HRESULT FetchData(int hReq, CTABLESRow &trData, int table_type)
{
	char *name;
	int type, ind, res;
	T_CCI_ERROR err_buf;

	res = cci_fetch(hReq, &err_buf);
	if(res<0) return RaiseError(E_FAIL, 1, __uuidof(IDBSchemaRowset), err_buf.err_msg);

	res = cci_get_data(hReq, 1, CCI_A_TYPE_STR, &name, &ind);
	if(res<0) return RaiseError(E_FAIL, 0, __uuidof(IDBSchemaRowset));
	CA2W nametmp(name);
	wcsncpy(trData.m_szTable, nametmp, 128);
	trData.m_szTable[128] = 0;
	_wcsupr(trData.m_szTable);

	res = cci_get_data(hReq, 2, CCI_A_TYPE_INT, &type, &ind);
	if(res<0) return RaiseError(E_FAIL, 0, __uuidof(IDBSchemaRowset));

	if((type==0 && (table_type & TABLE_TYPE_SYSTEM))
		|| (type==1 && (table_type & TABLE_TYPE_VIEW))
		|| (type==2 && (table_type & TABLE_TYPE_TABLE)))
	{
		switch(type)
		{
		case 0:
			wcscpy(trData.m_szType, L"SYSTEM TABLE");
			wcscpy(trData.m_szDesc, L"System Class");
			break;
		case 1:
			wcscpy(trData.m_szType, L"VIEW");
			wcscpy(trData.m_szDesc, L"Virtual Class");
			break;
		case 2:
			wcscpy(trData.m_szType, L"TABLE");
			wcscpy(trData.m_szDesc, L"Class");
			break;
		}
	}
	else
		return S_FALSE;

	return S_OK;
}
Ejemplo n.º 7
0
// S_OK : 성공
// S_FALSE : 데이터는 가져왔지만 Consumer가 원하는 데이터가 아님
// E_FAIL : 실패
static HRESULT FetchData(int hReq, CStatisticsRow &tprData)
{
	char *value;
	int ind, res;
	T_CCI_ERROR err_buf;
	
	res = cci_fetch(hReq, &err_buf);
	if(res<0) return RaiseError(E_FAIL, 1, __uuidof(IDBSchemaRowset), err_buf.err_msg);

	res = cci_get_data(hReq, 1, CCI_A_TYPE_STR, &value, &ind);
	if(res<0) return RaiseError(E_FAIL, 0, __uuidof(IDBSchemaRowset));
	wcscpy(tprData.m_szTableName, CA2W(value));
	
	return S_OK;
}
Ejemplo n.º 8
0
int CubTest(){
	 int nColCount = 0, nLen = 0;
    int i = 0, nDB = 0, nRet = 0, nReq = 0; 
    char *pszBuff = NULL;
    
    
    T_CCI_COL_INFO *pcciCol;
    T_CCI_SQLX_CMD cciCmdType;
    
    assert((nDB = cci_connect(DB_SERVER, DB_PORT, DB_NAME, DB_USER_ID, DB_USER_PW)) >= 0);
    assert((nReq = cci_prepare(nDB, "SELECT * FROM athlete", 0, &cciErr)) >= 0);
    assert((pcciCol = cci_get_result_info(nReq, &cciCmdType, &nColCount)) != NULL);
        
    for (i = 1; i <= nColCount; i++)
    {
        printf("%s\t", CCI_GET_RESULT_INFO_NAME(pcciCol, i));
    }

    printf("\n");

    assert(cci_execute(nReq, 0, 0, &cciErr) >= 0);

    while (1) 
    {
        if ( cci_cursor(nReq, 1, CCI_CURSOR_CURRENT, &cciErr) == CCI_ER_NO_MORE_DATA )
            break;
       
        assert(cci_fetch(nReq, &cciErr) >= 0);
       
        for (i = 1; i<= nColCount; i++)
        {
            assert(cci_get_data(nReq, i, CCI_A_TYPE_STR, &pszBuff, &nLen) >= 0);
            printf("%s\t", pszBuff);
        }
        printf("\n");
    }

    assert(cci_close_req_handle(nReq) >= 0);
    assert(cci_disconnect(nDB, &cciErr) >= 0);
    
    return 0;

   
}
Ejemplo n.º 9
0
//Row 객체에서 GetColumns시 호출된다.
//Row의 데이터를 채운다.
//by risensh1ne
HRESULT CCUBRIDRowsetRow::ReadData(int hReq, char* szOID)
{
	ATLTRACE(atlTraceDBProvider, 3, "CCUBRIDRowsetRow::ReadData(3)\n");
	int res, ind;
	T_CCI_SET* set;
	char* strVal;

	// 컬럼 배열 생성
	CCUBRIDRowsetRowColumn *pColumns; // = m_rgColumns
	{
		if(m_rgColumns)
		{	// refresh(undo) row
			pColumns = m_rgColumns;
		}
		else
		{	// create row
			pColumns = new CCUBRIDRowsetRowColumn[1];
			if(pColumns==NULL) return E_OUTOFMEMORY;
			m_rgColumns = pColumns;
		}
	}

	//OID Copy
	strcpy(m_szOID, szOID);

	res = cci_get_data(hReq, 1, CCI_A_TYPE_SET, &set, &ind);
	if(res<0) return RaiseError(E_FAIL, 0, __uuidof(IRow), "CCUBRIDRowsetRow::ReadData(3) cci_get_data failed");

	CCUBRIDRowsetRowColumn *pColCur = &pColumns[0];

	if (cci_set_get(set, 1, CCI_A_TYPE_STR, &strVal, &ind) < 0)
		return RaiseError(E_FAIL, 0, __uuidof(IRow), "CCUBRIDRowsetRow::ReadData(3) cci_set_data failed");

	pColCur->m_strData = _strdup(strVal);
	pColCur->m_dwStatus = DBSTATUS_S_OK;
	pColCur->m_cbDataLen = ind;

	return S_OK;
}
Ejemplo n.º 10
0
HRESULT CCUBRIDRowsetRowColumn::ReadData(int hReq, int iOrdinal, DBTYPE wType)
{
	ATLTRACE(atlTraceDBProvider, 2, "CCUBRIDRowsetRowColumn::ReadData(2)\n");

	if(m_strData) { free(m_strData); m_strData = 0; }

	if(iOrdinal==0)
	{	// Bookmark Column
		return S_OK;
	}

	// Non-Bookmark Columns
	char *value; int ind;

	// time 타입을 STR로 받으면 CCI는 '1:2:3'과 같이 반환한다.
	// LTM은 '01:02:03'과 같은 형태여야만 성공한다.
	// 그냥 쓰기에는 상관없을 듯 하지만, 일단은 따로 처리한다.
	if(wType==DBTYPE_DBTIME || wType==DBTYPE_DBTIMESTAMP)
	{
		T_CCI_DATE date;
		if(cci_get_data(hReq, iOrdinal, CCI_A_TYPE_DATE, &date, &ind) < 0)
		{
			m_dwStatus = DBSTATUS_E_UNAVAILABLE;
			return S_OK;
		}

		if(ind==-1)
		{	// null value
			m_dwStatus = DBSTATUS_S_ISNULL;
			return S_OK;
		}

		if(wType==DBTYPE_DBTIME)
		{
			m_strData = (char *)malloc(9);
			sprintf(m_strData, "%02d:%02d:%02d", date.hh, date.mm, date.ss);
			m_cbDataLen = 8;
		}
		else // DBTYPE_DBTIMESTAMP
		{
			m_strData = (char *)malloc(20);
			sprintf(m_strData, "%04d-%02d-%02d %02d:%02d:%02d.%03d",
					date.yr, date.mon, date.day, date.hh, date.mm, date.ss, date.ms);
			m_cbDataLen = 23;
		}
		m_dwStatus = DBSTATUS_S_OK;
		return S_OK;
	}

	if(cci_get_data(hReq, iOrdinal, CCI_A_TYPE_STR, &value, &ind) < 0)
	{
		m_dwStatus = DBSTATUS_E_UNAVAILABLE;
		return S_OK;
	}

	if(ind==-1)
	{	// null value
		m_dwStatus = DBSTATUS_S_ISNULL;
		return S_OK;
	}

	// 고정 크기 문자열의 경우 뒤에 필요없는 값이 붙어서 나온다.
	// 이때문에 NCHAR의 경우 문제가 생길 수 있다.
	// (NCHAR와 WSTR이 정확히 일치하는 타입이 아니기 때문에
	// 변환시 DBSTATUS_S_TRUNCATED가 나올 수 있다.)
	// 어짜피 OLE DB는 고정 크기 문자열 타입이 없기 때문에
	// 제거하는 쪽을 택했다.
	// TODO: 다음과 같이 제거하면 될까?

	// while(value[ind-1]==' ' || (unsigned char)value[ind-1]==0xA1)
	// 두번째 조건을 포함할 경우 한글이 잘릴수 있다. -- cgkang
	while(value[ind-1]==' ')
	{
		ind--;
		value[ind] = 0;
	}

	// TODO: BLOB일 경우도 괜찮을까?
	m_strData = _strdup(value);
	m_dwStatus = DBSTATUS_S_OK;
	m_cbDataLen = ind;

	return S_OK;
}
Ejemplo n.º 11
0
// S_OK : 성공
// E_FAIL : 실패
static HRESULT FetchData(int hReq, CCOLUMNSRow &crData)
{
	char *cvalue;
	int ivalue, ind, res;
	T_CCI_ERROR err_buf;
	int nCCIUType, nPrecision, nScale;
	bool bNullable;

	res = cci_fetch(hReq, &err_buf);
	if(res<0) return RaiseError(E_FAIL, 1, __uuidof(IDBSchemaRowset), err_buf.err_msg);

	res = cci_get_data(hReq, 11, CCI_A_TYPE_STR, &cvalue, &ind);
	if(res<0) return RaiseError(E_FAIL, 0, __uuidof(IDBSchemaRowset));

	wcsncpy(crData.m_szTableName, CA2W(cvalue), 128);
	crData.m_szTableName[128] = 0;
	_wcsupr(crData.m_szTableName);

	res = cci_get_data(hReq, 1, CCI_A_TYPE_STR, &cvalue, &ind);
	if(res<0) return RaiseError(E_FAIL, 0, __uuidof(IDBSchemaRowset));

	wcsncpy(crData.m_szColumnName, CA2W(cvalue), 128);
	crData.m_szColumnName[128] = 0;
	_wcsupr(crData.m_szColumnName);

	res = cci_get_data(hReq, 2, CCI_A_TYPE_INT, &ivalue, &ind);
	if(res<0) return RaiseError(E_FAIL, 0, __uuidof(IDBSchemaRowset));

	nCCIUType = ivalue;

	if(nCCIUType==-1)
		crData.m_nDataType = Type::GetStaticTypeInfo(CCI_U_TYPE_STRING).nOLEDBType;
	else
		crData.m_nDataType = Type::GetStaticTypeInfo(ivalue).nOLEDBType;

	res = cci_get_data(hReq, 3, CCI_A_TYPE_INT, &ivalue, &ind);
	if(res<0) return RaiseError(E_FAIL, 0, __uuidof(IDBSchemaRowset));
	nScale = ivalue;

	res = cci_get_data(hReq, 4, CCI_A_TYPE_INT, &ivalue, &ind);
	if(res<0) return RaiseError(E_FAIL, 0, __uuidof(IDBSchemaRowset));
	nPrecision = ivalue;

	res = cci_get_data(hReq, 6, CCI_A_TYPE_INT, &ivalue, &ind);
	if(res<0) return RaiseError(E_FAIL, 0, __uuidof(IDBSchemaRowset));
	crData.m_bIsNullable = ( ivalue==0 ? ATL_VARIANT_TRUE : ATL_VARIANT_FALSE );
	bNullable = (ivalue==0);

	res = cci_get_data(hReq, 10, CCI_A_TYPE_INT, &ivalue, &ind);
	if(res<0) return RaiseError(E_FAIL, 0, __uuidof(IDBSchemaRowset));
	crData.m_ulOrdinalPosition = ivalue;

	res = cci_get_data(hReq, 9, CCI_A_TYPE_STR, &cvalue, &ind);
	if(res<0) return RaiseError(E_FAIL, 0, __uuidof(IDBSchemaRowset));
	if(ind==-1)
	{
		crData.m_bColumnHasDefault = ATL_VARIANT_FALSE;
		crData.m_szColumnDefault[0] = L'';
	}
	else
	{
		crData.m_bColumnHasDefault = ATL_VARIANT_TRUE;
		wcsncpy(crData.m_szColumnDefault, CA2W(cvalue), 128);
		crData.m_szColumnDefault[128] = 0;
	}

	Type::DynamicTypeInfo dyn_info =
		( nCCIUType==-1 ? Type::GetDynamicTypeInfo(CCI_U_TYPE_STRING, 0, 0, true) :
						  Type::GetDynamicTypeInfo(nCCIUType, nPrecision, nScale, bNullable) );
	crData.m_ulColumnFlags = dyn_info.ulFlags;
	crData.m_nNumericPrecision = dyn_info.nNumericPrecision;
	crData.m_nNumericScale = dyn_info.nNumericScale;
	crData.m_ulDateTimePrecision = dyn_info.ulDateTimePrecision;

	// TODO: CCI_PARAM_MAX_STRING_LENGTH 적용?
	crData.m_ulCharMaxLength = dyn_info.ulCharMaxLength;
	crData.m_ulCharOctetLength = dyn_info.ulCharOctetLength;

	return S_OK;
}
Ejemplo n.º 12
0
HRESULT CSRViewColumnUsage::Execute(LONG* pcRowsAffected,
				ULONG cRestrictions, const VARIANT *rgRestrictions)
{
	ATLTRACE2(atlTraceDBProvider, 2, "CSRViewColumnUsage::Execute\n");

	ClearError();

	if (pcRowsAffected)
			*pcRowsAffected = 0;
	
	int hConn = CCUBRIDSession::GetSessionPtr(this)->GetConnection();
	UINT uCodepage = CCUBRIDSession::GetSessionPtr(this)->GetCodepage();
	WCHAR view_name[256]; view_name[0] = 0;
	
	GetRestrictions(cRestrictions, rgRestrictions, view_name);
	{
		T_CCI_ERROR err_buf;
		char current_view_name[256];
		char* buffer;
		int res, ind;
		int hReq, hReq2;
		CW2A _viewName(view_name, uCodepage);
		hReq = cci_schema_info(hConn, CCI_SCH_VCLASS, (view_name[0] ? (PSTR) _viewName : NULL),
			NULL, CCI_CLASS_NAME_PATTERN_MATCH, &err_buf);
		if(hReq<0)
		{
			ATLTRACE2("cci_schema_info fail\n");
			return RaiseError(E_FAIL, 1, __uuidof(IDBSchemaRowset), CA2W(err_buf.err_msg, uCodepage));
		}

		res = cci_cursor(hReq, 1, CCI_CURSOR_FIRST, &err_buf);
        if(res==CCI_ER_NO_MORE_DATA) goto done;
		if(res<0) goto error;

		while(1)
		{
			res = cci_fetch(hReq, &err_buf);
			if(res<0) goto error;

			res = cci_get_data(hReq, 1, CCI_A_TYPE_STR, &buffer, &ind);
			if(res<0) goto error;
			strcpy(current_view_name, buffer);
		
			hReq2 = cci_schema_info(hConn, CCI_SCH_ATTRIBUTE, current_view_name,
					NULL, CCI_ATTR_NAME_PATTERN_MATCH, &err_buf);
			if(hReq2<0)
			{
				ATLTRACE2("cci_schema_info fail\n");
				goto error;
			}

			res = cci_cursor(hReq2, 1, CCI_CURSOR_FIRST, &err_buf);
			if(res==CCI_ER_NO_MORE_DATA)
				goto next_view;

			if(res<0) goto error;

			while(1)
			{
				CViewColumnUsageRow tprData;
				wcscpy(tprData.m_szViewName, CA2W(current_view_name, uCodepage));

				res = cci_fetch(hReq2, &err_buf);
				if(res<0) goto error;

				res = cci_get_data(hReq2, 1, CCI_A_TYPE_STR, &buffer, &ind);
				if(res<0) goto error;
				wcscpy(tprData.m_szColumnName, CA2W(buffer, uCodepage));
				
				res = cci_get_data(hReq2, 11, CCI_A_TYPE_STR, &buffer, &ind);
				if(res<0) goto error;
				wcscpy(tprData.m_szTableName, CA2W(buffer, uCodepage));
				
				_ATLTRY
				{
					// VIEW_NAME, TABLE_NAME, COLUMN_NAME 순으로 정렬해야 한다.
					size_t nPos;
					for( nPos=0 ; nPos<m_rgRowData.GetCount() ; nPos++ )
					{
						int res = wcscmp(m_rgRowData[nPos].m_szViewName, tprData.m_szViewName);
						if(res>0) break;
						if (res == 0)
						{
							res = wcscmp(m_rgRowData[nPos].m_szTableName, tprData.m_szTableName);
							if (res>0) break;
							if (res == 0)
							{
								res = wcscmp(m_rgRowData[nPos].m_szColumnName, tprData.m_szColumnName);
								if (res>0) break;
							}
						}
					}
					m_rgRowData.InsertAt(nPos, tprData);
				}
				_ATLCATCHALL()
				{
					ATLTRACE2("out of memory\n");
					cci_close_req_handle(hReq);
					return E_OUTOFMEMORY;
				}
				if (pcRowsAffected) (*pcRowsAffected)++;

				res = cci_cursor(hReq2, 1, CCI_CURSOR_CURRENT, &err_buf);
				if(res==CCI_ER_NO_MORE_DATA) break;
				if(res<0) goto error;
			}
next_view:
			cci_close_req_handle(hReq2);

			res = cci_cursor(hReq, 1, CCI_CURSOR_CURRENT, &err_buf);
			if(res==CCI_ER_NO_MORE_DATA) goto done;
			if(res<0) goto error;
		}

error:
		ATLTRACE2("fail to fetch data\n");
		cci_close_req_handle(hReq);
		cci_close_req_handle(hReq2);
		return RaiseError(E_FAIL, 1, __uuidof(IDBSchemaRowset), CA2W(err_buf.err_msg, uCodepage));
done:
		cci_close_req_handle(hReq);
	}

	return S_OK;
}