// 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; }
bool DbFetch(int qid){ int ret = cci_fetch(qid, &cciErr); if(ret >= 0) return true; return false; }
//수행도중 에러가 나도 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; }
// 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; }
HRESULT CCUBRIDRowsetRow::ReadData(int hReq, bool bOIDOnly, bool bSensitive) { ATLTRACE(atlTraceDBProvider, 3, "CCUBRIDRowsetRow::ReadData(1)\n"); // 컬럼 배열 생성 CCUBRIDRowsetRowColumn *pColumns; // = m_rgColumns { if(m_rgColumns) { // refresh(undo) row pColumns = m_rgColumns; } else { // create row pColumns = new CCUBRIDRowsetRowColumn[m_cColumns]; if(pColumns==NULL) return E_OUTOFMEMORY; m_rgColumns = pColumns; } } // cursor를 이동하고 fetch { // deferred delete는 메모리에 남아 있으므로 // iRowset이 storage상의 위치와 같다. T_CCI_ERROR err_buf; int res = cci_cursor(hReq, (int) m_iRowset+1, CCI_CURSOR_FIRST, &err_buf); if(res==CCI_ER_NO_MORE_DATA) return DB_S_ENDOFROWSET; if(res<0) return E_FAIL; if(bSensitive) res = cci_fetch_sensitive(hReq, &err_buf); else res = cci_fetch(hReq, &err_buf); if(res==CCI_ER_DELETED_TUPLE) return DB_E_DELETEDROW; if(res==CCI_ER_NO_MORE_DATA) return DB_S_ENDOFROWSET; if(res<0) return E_FAIL; } cci_get_cur_oid(hReq, m_szOID); if(bOIDOnly) return S_OK; for(DBORDINAL i=0;i<m_cColumns;i++) { CCUBRIDRowsetRowColumn *pColCur = &pColumns[i]; pColCur->ReadData(hReq, (int) m_pInfo[i].iOrdinal, m_pInfo[i].wType); } return S_OK; }
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; }
// 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; }
// 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; }
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; }