Ejemplo n.º 1
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.º 2
0
void CMultipleResult::TxnCallback(const ITxnCallback *pOwner)
{
	if(pOwner!=this)
	{
		cci_close_req_handle(m_hReq);
		m_hReq = 0;
		m_bInvalidated = true;
	}
}
Ejemplo n.º 3
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.º 4
0
void DbCloseQuery(int qid){
	cci_close_req_handle(qid);
}
Ejemplo n.º 5
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);
	}
Ejemplo n.º 6
0
// NOTICE: 가능하면 이 함수에서 에러가 발생하면 안 된다.
// query 중 에러가 발생할 만한 여지가 있는 것은 ReadData 시에
// 모두 찾아내야 한다.
// 그렇지 않으면 deferred update 모드에서 SetData()는 성공했는데
// Update()가 실패하게 된다.
HRESULT CCUBRIDRowsetRow::WriteData(int hConn, int hReq, CComBSTR &strTableName)
{
	ATLTRACE(atlTraceDBProvider, 3, "CCUBRIDRowsetRow::WriteData(1)\n");

	HRESULT hr = S_OK;

	// query 생성
	CComBSTR query;
	{
		switch(m_status)
		{
		case DBPENDINGSTATUS_DELETED:
			// delete from <table> where <table>=?
			query.Append("delete from ");
			query.Append("[");
			query.Append(strTableName);
			query.Append("]");
			query.Append(" where ");
			query.Append("[");
			query.Append(strTableName);
			query.Append("]");
			query.Append("=?");
			break;
		case DBPENDINGSTATUS_NEW:
			// insert into <table>(<column>,<column>) values(<value>,<value>)
			{
				CComBSTR column;
				CComBSTR value;
				for(DBORDINAL i=0;i<m_cColumns;i++)
				{
					ATLCOLUMNINFO *m_pInfoCur = &m_pInfo[i];
					if(m_pInfoCur->iOrdinal==0) continue; // skip bookmark column
					column.Append("[");
					column.Append(m_pInfoCur->pwszName);
					column.Append("]");
					value.Append(BuildColumnValue(m_pInfoCur, m_rgColumns+i));
					if(i!=m_cColumns-1) { column.Append(","); value.Append(","); }
				}

				query.Append("insert into ");
				query.Append("[");
				query.Append(strTableName);
				query.Append("]");
				query.Append("(");
				query.Append(column);
				query.Append(") values(");
				query.Append(value);
				query.Append(")");
			}
			break;
		case DBPENDINGSTATUS_CHANGED:
			{
				// TODO: 중간에 실패하면 되돌리지를 못한다.
				for(DBORDINAL i=0;i<m_cColumns;i++)
				{
					ATLCOLUMNINFO *pInfoCur = &m_pInfo[i];
					if(pInfoCur->iOrdinal==0) continue; // skip bookmark column

					CCUBRIDRowsetRowColumn *pCol = m_rgColumns+i;
					HRESULT hr = pCol->WriteData(hReq, (int) m_iRowset, pInfoCur);
					if(FAILED(hr))
						return hr;
				}
				return S_OK;
			}
			/* Query Base: view에 적용불가
			// update <table> set <column>=<value>, <column>=<value> where <table>=?
			{
				CComBSTR set;
				for(DBORDINAL i=0;i<m_cColumns;i++)
				{
					ATLCOLUMNINFO *m_pInfoCur = &m_pInfo[i];
					if(m_pInfoCur->iOrdinal==0) continue; // skip bookmark column
					set.Append(m_pInfoCur->pwszName);
					set.Append("=");
					set.Append(BuildColumnValue(m_pInfoCur, m_rgColumns+i));
					if(i!=m_cColumns-1) set.Append(",");
				}

				query.Append("update ");
				query.Append("[");
				query.Append(strTableName);
				query.Append("]");
				query.Append(" set ");
				query.Append(set);
				query.Append(" where ");
				query.Append("[");
				query.Append(strTableName);
				query.Append("]");
				query.Append("=?");
			}
			*/
			break;
		default:
			return DB_E_ERRORSOCCURRED;
		}
	}

//#ifdef _DEBUG
//	{
//		// ATLTRACE는 한번에 1024문자까지 밖에 출력하지 못한다.
//		// 그래서 이렇게 출력한다.
//		ATLTRACE(atlTraceDBProvider, 2, "Execute Query = ");
//		CW2A local(query);
//		for(size_t i=0;i<strlen(local);)
//		{
//			char buf[513]; memcpy(buf, local+i, 512); buf[512] = 0;
//			ATLTRACE(atlTraceDBProvider, 2, "%s", buf);
//			i += 512;
//		}
//		ATLTRACE(atlTraceDBProvider, 2, "\n");
//	}
//#endif

	// prepare query
	int hLocalReq;
	{
		T_CCI_ERROR err_buf;
		hLocalReq = cci_prepare(hConn, CW2A(query), 0, &err_buf);
		if (hLocalReq<0) return RaiseError(DB_E_ERRORSOCCURRED, 1, __uuidof(IRowset), err_buf.err_msg);
	}

	// execute query
	{
		if(m_status==DBPENDINGSTATUS_DELETED || m_status==DBPENDINGSTATUS_CHANGED)
			cci_bind_param(hLocalReq, 1, CCI_A_TYPE_STR, m_szOID, CCI_U_TYPE_OBJECT, 0);

		T_CCI_ERROR err_buf;
		int rc = cci_execute(hLocalReq, 0, 0, &err_buf);
		if(rc<0)
		{
			cci_close_req_handle(hLocalReq);
			if(err_buf.err_code==-670) // constraint violation code 맞나?
				return RaiseError(DB_E_INTEGRITYVIOLATION, 0, __uuidof(IRowset));
			else
				return RaiseError(DB_E_ERRORSOCCURRED, 1, __uuidof(IRowset), err_buf.err_msg);
		}
		else if(rc==0)
		{
			if(m_status==DBPENDINGSTATUS_DELETED)
				hr = DB_E_DELETEDROW;
		}
		else
		{
			ATLASSERT(rc==1);
		}
	}

	cci_close_req_handle(hLocalReq);

	return hr;
}
Ejemplo n.º 7
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;
}
Ejemplo n.º 8
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));
			}
		}
	}
Ejemplo n.º 9
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;
}