示例#1
0
HRESULT CSRTables::Execute(LONG * /*pcRowsAffected*/,
				ULONG cRestrictions, const VARIANT *rgRestrictions)
{
	ATLTRACE2(atlTraceDBProvider, 2, "CSRTables::Execute\n");

	ClearError();

	int hConn = -1;
	HRESULT hr = CCUBRIDSession::GetSessionPtr(this)->GetConnectionHandle(&hConn);
	if(FAILED(hr)) return hr;

	char table_name[1024]; table_name[0] = 0;
	int table_type = TABLE_TYPE_TABLE | TABLE_TYPE_VIEW | TABLE_TYPE_SYSTEM;
	GetRestrictions(cRestrictions, rgRestrictions, table_name, &table_type);

	{
		T_CCI_ERROR err_buf;
		int hReq = cci_schema_info(hConn, CCI_SCH_CLASS, (table_name[0]?table_name: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), err_buf.err_msg);
		}

		int 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)
		{
			CTABLESRow trData;
			hr = FetchData(hReq, trData, table_type);
			if(FAILED(hr))
			{
				cci_close_req_handle(hReq);
				return hr;
			}

			if(hr==S_OK) // S_FALSE면 추가하지 않음
			{
				_ATLTRY
				{
					// TABLE_TYPE, TABLE_NAME 순으로 정렬해야 한다.
					size_t nPos;
					for( nPos=0 ; nPos<m_rgRowData.GetCount() ; nPos++ )
					{
						int res = CompareStringW(LOCALE_USER_DEFAULT, 
								NORM_IGNOREKANATYPE | NORM_IGNOREWIDTH | SORT_STRINGSORT,
								m_rgRowData[nPos].m_szType, -1,
								trData.m_szType, -1);
						if(res==CSTR_GREATER_THAN) break;
						if(res==CSTR_EQUAL)
						{
							res = CompareStringW(LOCALE_USER_DEFAULT, 
									NORM_IGNOREKANATYPE | NORM_IGNOREWIDTH | SORT_STRINGSORT,
									m_rgRowData[nPos].m_szTable, -1,
									trData.m_szTable, -1);
							if(res==CSTR_GREATER_THAN) break;
						}
					}
					m_rgRowData.InsertAt(nPos, trData);
				}
				_ATLCATCHALL()
				{
					ATLTRACE2("out of memory\n");
					cci_close_req_handle(hReq);
					return E_OUTOFMEMORY;
				}
			}

			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);
		return RaiseError(E_FAIL, 1, __uuidof(IDBSchemaRowset), err_buf.err_msg);
done:
		cci_close_req_handle(hReq);
	}
示例#2
0
HRESULT CSRKeyColumnUsage::Execute(LONG *pcRowsAffected, ULONG cRestrictions, const VARIANT *rgRestrictions)
{
	ATLTRACE2(atlTraceDBProvider, 2, "CSRKeyColumnUsage::Execute()\n");
	////
	int cci_connection_handle = -999;

	WCHAR tableName[128] = {'\0', };

	HRESULT hr = E_FAIL;
	////

	cci_connection_handle = CCUBRIDSession::GetSessionPtr(this)->GetConnection();
	UINT uCodepage = CCUBRIDSession::GetSessionPtr(this)->GetCodepage();
	GetRestrictions(cRestrictions, rgRestrictions, tableName);

	////
	int cci_return_code = -999;
	int cci_request_handle = 0;
	T_CCI_ERROR cci_error_buffer;
	////
#if 1
	CW2A _tableName(tableName, uCodepage);
	cci_return_code = cci_schema_info
		(
		cci_connection_handle, 
		CCI_SCH_PRIMARY_KEY, 
		(tableName[0]? (PSTR) _tableName : NULL), 
		NULL,							// no attribute name is specified.
		CCI_CLASS_NAME_PATTERN_MATCH, 
		&cci_error_buffer
		);
#endif
	if (cci_return_code < 0)
	{
		ATLTRACE2(atlTraceDBProvider, 2, "CSRPrimaryKeys::cci_schema_info() FAILED! \n");
		return RaiseError(E_FAIL, 1, __uuidof(IDBSchemaRowset), CA2W(cci_error_buffer.err_msg, uCodepage));
	}

	cci_request_handle = cci_return_code;

	cci_return_code = cci_cursor(cci_request_handle, 1, CCI_CURSOR_FIRST, &cci_error_buffer);
	if (cci_return_code < 0)
	{
		if (cci_return_code == CCI_ER_NO_MORE_DATA)
		{
			cci_close_req_handle(cci_request_handle);
			return S_OK;
		}
		else
		{
			cci_close_req_handle(cci_request_handle);
			return RaiseError(E_FAIL, 1, __uuidof(IDBSchemaRowset), CA2W(cci_error_buffer.err_msg, uCodepage));
		}
	}

	while (1)
	{
		CKeyColumnUsageRow row;

		hr = FetchData(cci_request_handle, uCodepage, row);
		if (FAILED(hr))
			return hr;

		if (hr == S_OK)
		{
			_ATLTRY
			{
				size_t position = 0;
				for (position = 0; position < m_rgRowData.GetCount() ; position++)
				{
					int result = CompareStringW(LOCALE_USER_DEFAULT, NORM_IGNOREKANATYPE | NORM_IGNOREWIDTH | SORT_STRINGSORT, m_rgRowData[position].GetConstraintName(), -1, row.GetConstraintName(), -1);
					if ( result == CSTR_GREATER_THAN ) 
					{
							break;
					}
					else if (result == CSTR_EQUAL)
					{
						result = CompareStringW(LOCALE_USER_DEFAULT, NORM_IGNOREKANATYPE | NORM_IGNOREWIDTH | SORT_STRINGSORT, m_rgRowData[position].GetTableName(), -1, row.GetTableName(), -1);
						if (result == CSTR_GREATER_THAN)
							break;
						else if (result == CSTR_EQUAL)
						{
							if (m_rgRowData[position].GetOrdinalPosition() >= row.GetOrdinalPosition())
								break;
						}
					}
				}
				m_rgRowData.InsertAt(position, row);
			}
			_ATLCATCHALL()
			{
				cci_close_req_handle(cci_request_handle);
				return E_OUTOFMEMORY;
			}

		}
		cci_return_code = cci_cursor(cci_request_handle, 1, CCI_CURSOR_CURRENT, &cci_error_buffer);
		if (cci_return_code < 0)
		{
			if (cci_return_code == CCI_ER_NO_MORE_DATA)
			{
				cci_close_req_handle(cci_request_handle);
				return S_OK;
			}
			else
			{
				cci_close_req_handle(cci_request_handle);
				return RaiseError(E_FAIL, 1, __uuidof(IDBSchemaRowset), CA2W(cci_error_buffer.err_msg, uCodepage));
			}
		}
	}
示例#3
0
HRESULT CSRColumns::Execute(LONG * /*pcRowsAffected*/,
				ULONG cRestrictions, const VARIANT *rgRestrictions)
{
	ATLTRACE2(atlTraceDBProvider, 2, "CSRColumns::Execute\n");

	ClearError();

	int hConn = -1;
	HRESULT hr = CCUBRIDSession::GetSessionPtr(this)->GetConnectionHandle(&hConn);
	if(FAILED(hr)) return hr;

	ULONG ulMaxLen = CCUBRIDSession::GetSessionPtr(this)->GetDataSourcePtr()->PARAM_MAX_STRING_LENGTH;

	char table_name[1024]; table_name[0] = 0;
	char column_name[1024]; column_name[0] = 0;
	GetRestrictions(cRestrictions, rgRestrictions, table_name, column_name);

	{
		T_CCI_ERROR err_buf;
		int hReq = cci_schema_info(hConn, CCI_SCH_ATTRIBUTE,
							(table_name[0]?table_name:NULL),
							(column_name[0]?column_name:NULL),
							CCI_CLASS_NAME_PATTERN_MATCH | CCI_ATTR_NAME_PATTERN_MATCH,
							&err_buf);
		if(hReq<0)
		{
			ATLTRACE2("cci_schema_info fail\n");
			return E_FAIL;
		}

		int 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)
		{
			CCOLUMNSRow crData;
			hr = FetchData(hReq, crData);
			if(FAILED(hr)) goto error;

			//MAX STRING LENGTH 반영
			if (crData.m_ulCharMaxLength != (ULONG)~0 && crData.m_ulCharMaxLength > ulMaxLen)
				crData.m_ulCharMaxLength = ulMaxLen;
			if (crData.m_ulCharMaxLength != (ULONG)~0 && crData.m_ulCharOctetLength > ulMaxLen)
				crData.m_ulCharOctetLength = ulMaxLen;

			_ATLTRY
			{
				// TABLE_NAME 순으로 정렬한다.
				size_t nPos;
				for( nPos=0 ; nPos<m_rgRowData.GetCount() ; nPos++ )
				{
					int res = CompareStringW(LOCALE_USER_DEFAULT, 
							NORM_IGNOREKANATYPE | NORM_IGNOREWIDTH | SORT_STRINGSORT,
							m_rgRowData[nPos].m_szTableName, -1,
							crData.m_szTableName, -1);
					if(res==CSTR_GREATER_THAN) break;
				}
				m_rgRowData.InsertAt(nPos, crData);
			}
			_ATLCATCHALL()
			{
				ATLTRACE2("out of memory\n");
				cci_close_req_handle(hReq);
				return E_OUTOFMEMORY;
			}

			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);
		return RaiseError(E_FAIL, 1, __uuidof(IDBSchemaRowset), err_buf.err_msg);
done:
		cci_close_req_handle(hReq);
	}

	return S_OK;
}
示例#4
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;
}