Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

796 lines
27 KiB

  1. ///////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Microsoft WMIOLE DB Provider
  4. // (C) Copyright 1999 Microsoft Corporation. All Rights Reserved.
  5. //
  6. // cRowColumnInfoMemMgr object implementation - implements column information
  7. //
  8. //
  9. ///////////////////////////////////////////////////////////////////////////////////
  10. #include "headers.h"
  11. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  12. // cRowColumnInfoMemMgr class implementation
  13. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  14. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  15. // Constructor
  16. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  17. cRowColumnInfoMemMgr::cRowColumnInfoMemMgr(cRowColumnInfoMemMgr *pSrcRsColInfo)
  18. {
  19. m_DBColInfoList = NULL;
  20. m_rgdwDataOffsets = NULL;
  21. m_rgCIMType = NULL;
  22. m_dwOffset = 0;
  23. m_cbTotalCols = 0L;
  24. m_cbCurrentIndex = 0L;
  25. m_lpCurrentName = NULL;
  26. m_pbColumnNames = NULL;
  27. m_cbColumnInfoBytesUsed = 0L;
  28. m_nFirstIndex = 0L;
  29. m_pSrcRsColInfo = pSrcRsColInfo;
  30. if(m_pSrcRsColInfo != NULL)
  31. {
  32. m_nFirstIndex = m_pSrcRsColInfo->m_cbTotalCols;
  33. m_cbCurrentIndex = 0;
  34. }
  35. }
  36. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  37. // Destructor
  38. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  39. cRowColumnInfoMemMgr::~cRowColumnInfoMemMgr()
  40. {
  41. FreeColumnNameList();
  42. FreeColumnInfoList();
  43. }
  44. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  45. // Reallocate the column list
  46. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  47. HRESULT cRowColumnInfoMemMgr::ReAllocColumnInfoList()
  48. {
  49. HRESULT hr = S_OK;
  50. DBCOUNTITEM cNewCols = m_cbTotalCols + DEFAULT_COLUMNS_TO_ADD;
  51. DBCOUNTITEM cOldCols = m_cbTotalCols;
  52. DBCOUNTITEM cbColumnInfoBytesUsed = m_cbColumnInfoBytesUsed;
  53. // If there is a source rowset info then adjuct the column numbers and bytes
  54. if(m_pSrcRsColInfo != NULL)
  55. {
  56. cOldCols = cOldCols - m_pSrcRsColInfo->m_cbTotalCols;
  57. cbColumnInfoBytesUsed = cbColumnInfoBytesUsed - m_pSrcRsColInfo->m_cbColumnInfoBytesUsed;
  58. }
  59. //==================================================
  60. // save the old buffer ptrs
  61. //==================================================
  62. DBCOLUMNINFO* OldCol = m_DBColInfoList;
  63. DBBYTEOFFSET* OldOffset = m_rgdwDataOffsets;
  64. DWORD* OldCIMTypes = m_rgCIMType;
  65. hr = AllocColumnInfoList(cNewCols);
  66. if( S_OK == hr ){
  67. //==============================================
  68. // copy what we have so far
  69. //==============================================
  70. memcpy(m_DBColInfoList,OldCol,cbColumnInfoBytesUsed);
  71. memcpy(m_rgdwDataOffsets,OldOffset,cOldCols*sizeof(DBBYTEOFFSET));
  72. memcpy(m_rgCIMType,OldCIMTypes,cOldCols*(sizeof(ULONG)));
  73. SAFE_DELETE_ARRAY(OldCol);
  74. SAFE_DELETE_ARRAY(OldOffset);
  75. SAFE_DELETE_ARRAY(OldCIMTypes);
  76. }
  77. return hr;
  78. }
  79. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  80. // Get the current column information
  81. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  82. DBCOLUMNINFO ** cRowColumnInfoMemMgr::CurrentColInfo()
  83. {
  84. return &m_pCurrentColInfo;
  85. }
  86. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  87. // Get the column information of a particular column
  88. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  89. DBCOLUMNINFO * cRowColumnInfoMemMgr::GetColInfo(DBORDINAL icol)
  90. {
  91. if(m_pSrcRsColInfo != NULL && icol < m_nFirstIndex)
  92. {
  93. return &(m_pSrcRsColInfo->m_DBColInfoList[icol]);
  94. }
  95. else
  96. {
  97. return &(m_DBColInfoList[icol-m_nFirstIndex]);
  98. }
  99. return NULL;
  100. }
  101. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  102. // Initialize the indexes and pointer to point to the first column
  103. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  104. HRESULT cRowColumnInfoMemMgr::ResetColumns()
  105. {
  106. //=================================================================
  107. // Initialize ptr to beginning of DBCOLUMNINFO struct list,
  108. // beginning with 1 ( 0 is a bookmark )
  109. //=================================================================
  110. m_dwOffset = offsetof( ROWBUFF, pdData );
  111. m_cbCurrentIndex = 1;
  112. // m_cbColumnInfoBytesUsed = 1;
  113. m_cbColumnInfoBytesUsed = sizeof(DBCOLUMNINFO);
  114. // if the columninfo has a parent rowset then there is no need of BOOKMARK column
  115. // as the current col info is just a extenstion of the source rowset and source rowset
  116. // will have the bookmark column
  117. if(m_pSrcRsColInfo != NULL)
  118. {
  119. m_nFirstIndex = m_pSrcRsColInfo->m_cbTotalCols;
  120. m_cbCurrentIndex = 0;
  121. }
  122. else
  123. {
  124. InitializeBookMarkColumn();
  125. }
  126. m_pCurrentColInfo = &m_DBColInfoList[m_cbCurrentIndex];
  127. return S_OK;
  128. }
  129. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  130. // Allocate memory for th columnlist for the given number of columns
  131. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  132. HRESULT cRowColumnInfoMemMgr::AllocColumnInfoList(DBCOUNTITEM cCols)
  133. {
  134. HRESULT hr = S_OK;
  135. DBCOUNTITEM nTotalColsToAlloc = 0;
  136. //====================================================================
  137. // Add an extra index, so we can be 1 based
  138. //====================================================================
  139. if(m_pSrcRsColInfo != NULL)
  140. {
  141. nTotalColsToAlloc = cCols - m_pSrcRsColInfo->m_cbTotalCols;
  142. }
  143. else
  144. {
  145. nTotalColsToAlloc = cCols;
  146. }
  147. m_cbTotalCols = cCols ;
  148. m_DBColInfoList = new DBCOLUMNINFO[nTotalColsToAlloc];
  149. m_rgdwDataOffsets = new DBBYTEOFFSET[nTotalColsToAlloc];
  150. m_rgCIMType = new ULONG[nTotalColsToAlloc];
  151. //NTRaid:111761
  152. // 06/07/00
  153. if ( m_DBColInfoList == NULL || m_rgdwDataOffsets == NULL || m_rgCIMType == NULL ){
  154. hr = E_OUTOFMEMORY;
  155. }
  156. else
  157. {
  158. memset(m_DBColInfoList,0,nTotalColsToAlloc * sizeof(DBCOLUMNINFO));
  159. memset(m_rgdwDataOffsets,0,nTotalColsToAlloc * sizeof(DBBYTEOFFSET));
  160. memset(m_rgCIMType,0,nTotalColsToAlloc * sizeof(ULONG));
  161. //====================================================================
  162. // Set all ptrs to the beginning
  163. //====================================================================
  164. ResetColumns();
  165. }
  166. return hr;
  167. }
  168. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  169. // Function to initialize the column info for the bookmark column
  170. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  171. HRESULT cRowColumnInfoMemMgr::InitializeBookMarkColumn()
  172. {
  173. HRESULT hr = S_OK;
  174. memset(&m_DBColInfoList[0],0,sizeof(DBCOLUMNINFO));
  175. m_DBColInfoList[0].iOrdinal = 0;
  176. m_DBColInfoList[0].dwFlags = DBCOLUMNFLAGS_ISBOOKMARK || DBCOLUMNFLAGS_MAYBENULL;
  177. m_DBColInfoList[0].ulColumnSize = BOOKMARKSIZE;
  178. m_DBColInfoList[0].wType = DBTYPE_I4;
  179. m_DBColInfoList[0].columnid.eKind = DBKIND_GUID_PROPID ;
  180. m_DBColInfoList[0].columnid.uGuid.guid = DBCOL_SPECIALCOL;
  181. m_DBColInfoList[0].columnid.uName.ulPropid = 3; // This should be more than 2 for bookmarks that are not self bookmark
  182. m_dwOffset = ROUND_UP( m_dwOffset, COLUMN_ALIGNVAL );
  183. m_rgdwDataOffsets[0] = m_dwOffset;
  184. m_dwOffset += offsetof( COLUMNDATA, pbData );
  185. return hr;
  186. }
  187. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  188. // Commit the column information and move to the next column
  189. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  190. HRESULT cRowColumnInfoMemMgr::CommitColumnInfo()
  191. {
  192. HRESULT hr = S_OK;
  193. //==============================================================
  194. // Set the offset from the start of the row, for this column,
  195. // then advance past.
  196. //==============================================================
  197. if( m_cbCurrentIndex > m_cbTotalCols ){
  198. hr = ReAllocColumnInfoList();
  199. }
  200. // NTRaid:111762
  201. // 06/13/00
  202. if(SUCCEEDED(hr))
  203. {
  204. m_dwOffset = ROUND_UP( m_dwOffset, COLUMN_ALIGNVAL );
  205. m_rgdwDataOffsets[m_cbCurrentIndex] = m_dwOffset;
  206. m_dwOffset += offsetof( COLUMNDATA, pbData );
  207. m_pCurrentColInfo->columnid.eKind = DBKIND_NAME;
  208. m_pCurrentColInfo->columnid.uName.pwszName = m_pCurrentColInfo->pwszName;
  209. m_cbCurrentIndex++;
  210. m_cbColumnInfoBytesUsed += sizeof(*m_pCurrentColInfo);
  211. m_pCurrentColInfo = &m_DBColInfoList[m_cbCurrentIndex];
  212. }
  213. return hr;
  214. }
  215. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  216. // Allocate memory for the Column Name list
  217. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  218. HRESULT cRowColumnInfoMemMgr::AllocColumnNameList(DBCOUNTITEM nCols)
  219. {
  220. HRESULT hr = E_UNEXPECTED;
  221. DBCOUNTITEM nTotalColsToAlloc = 0;
  222. // Adjust the number of colinfo to allocate , if there is a source rowset ( which is in case of row object
  223. // created from rowset)
  224. if(m_pSrcRsColInfo != NULL)
  225. {
  226. nTotalColsToAlloc = nCols - m_pSrcRsColInfo->m_cbTotalCols;
  227. }
  228. else
  229. {
  230. nTotalColsToAlloc = nCols;
  231. }
  232. if( !m_pbColumnNames || m_pSrcRsColInfo != NULL){
  233. if( nCols > 0 ){
  234. //===================================================================================
  235. // Allocate memory for the columns names.Commit it all, then de-commit and release
  236. // once we know size.
  237. //===================================================================================
  238. DBCOUNTITEM nSize = nTotalColsToAlloc * COLUMNINFO_SIZE;
  239. m_pbColumnNames = (WCHAR *) VirtualAlloc( NULL, nSize, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE );
  240. if (NULL == m_pbColumnNames){
  241. hr = E_OUTOFMEMORY;
  242. }
  243. else{
  244. //=================================================================
  245. // Initialize ptrs to the beginning of the column name buffer
  246. //=================================================================
  247. m_lpCurrentName = m_pbColumnNames;
  248. m_cbFreeColumnNameBytes = nSize;
  249. hr = S_OK;
  250. }
  251. }
  252. }
  253. return hr;
  254. }
  255. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  256. // Add a column name to the list of columns
  257. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  258. HRESULT cRowColumnInfoMemMgr::AddColumnNameToList(WCHAR * pColumnName, DBCOLUMNINFO ** pCol)
  259. {
  260. HRESULT hr = E_UNEXPECTED;
  261. //=================================================================
  262. // initialize stuff
  263. //=================================================================
  264. int nLen = wcslen(pColumnName) * sizeof(WCHAR);
  265. (*pCol)->pwszName = NULL;
  266. if( nLen > 0 ){
  267. //=============================================================
  268. // Store the Column Name in the Heap, providing there is one
  269. //=============================================================
  270. if (!( (!m_cbFreeColumnNameBytes) || ( ((ULONG) nLen + 2 ) <= m_cbFreeColumnNameBytes ))){
  271. //=========================================================
  272. // Reallocate and copy what was there to new buffer
  273. //=========================================================
  274. }
  275. else{
  276. //=====================================================
  277. // we have enough space, so
  278. // Copy the name of the column to the memory and set
  279. // a ptr to it in the DBCOLINFO struct
  280. //=====================================================
  281. memcpy( m_lpCurrentName, pColumnName, nLen);
  282. (*pCol)->pwszName = m_lpCurrentName;
  283. //=====================================================
  284. // Increment the current ptr, add a NULL,and decrement
  285. // free bytes
  286. //=====================================================
  287. m_lpCurrentName += wcslen(pColumnName);//nLen;
  288. m_cbFreeColumnNameBytes -= nLen;
  289. *m_lpCurrentName++ = NULL;
  290. m_cbFreeColumnNameBytes--;
  291. hr = S_OK;
  292. }
  293. }
  294. return hr;
  295. }
  296. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  297. // Set the rows size
  298. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  299. ULONG_PTR cRowColumnInfoMemMgr::SetRowSize()
  300. {
  301. ULONG_PTR lRowSize = 0;
  302. // Adjust the rowsize , if there is a source rowset ( which is in case of row object
  303. // created from rowset)
  304. if (NULL != m_pSrcRsColInfo)
  305. {
  306. lRowSize = ROUND_UP( m_pSrcRsColInfo->m_dwOffset, COLUMN_ALIGNVAL );
  307. }
  308. lRowSize += ROUND_UP( m_dwOffset, COLUMN_ALIGNVAL );
  309. //=================================================================
  310. // Set the row size
  311. //=================================================================
  312. // return ( ROUND_UP( m_dwOffset, COLUMN_ALIGNVAL ));
  313. return lRowSize;
  314. }
  315. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  316. // Free unused memory
  317. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  318. HRESULT cRowColumnInfoMemMgr::FreeUnusedMemory()
  319. {
  320. //==================================================================================
  321. // Decommit unused memory in our column-name buffer. We know it will never grow
  322. // beyond what it is now. Decommit all pages past where we currently are.
  323. //==================================================================================
  324. LPVOID pDiscardPage;
  325. DBLENGTH ulSize;
  326. pDiscardPage = (LPVOID)ROUND_UP( m_lpCurrentName, g_dwPageSize );
  327. ulSize = (ULONG)(MAX_HEAP_SIZE - ((BYTE *)pDiscardPage - (BYTE*) m_pbColumnNames));
  328. if (ulSize > 0){
  329. VirtualFree( pDiscardPage, ulSize, MEM_DECOMMIT );
  330. }
  331. //==================================================================================
  332. // We shouldn't generate a mem fault.
  333. //==================================================================================
  334. assert( '\0' == (*m_lpCurrentName = '\0'));
  335. return S_OK;
  336. }
  337. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  338. // Free the columninfo list
  339. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  340. HRESULT cRowColumnInfoMemMgr::FreeColumnInfoList()
  341. {
  342. //===============================================================
  343. // Release buffer for column names
  344. //===============================================================
  345. SAFE_DELETE_ARRAY( m_DBColInfoList );
  346. SAFE_DELETE_ARRAY( m_rgdwDataOffsets );
  347. SAFE_DELETE_ARRAY(m_rgCIMType);
  348. return S_OK;
  349. }
  350. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  351. // free the column name list
  352. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  353. HRESULT cRowColumnInfoMemMgr::FreeColumnNameList()
  354. {
  355. //===============================================================
  356. // Release buffer for column names
  357. //===============================================================
  358. if (NULL != m_pbColumnNames){
  359. VirtualFree((VOID *) m_pbColumnNames, 0, MEM_RELEASE );
  360. m_pbColumnNames = NULL;
  361. }
  362. return S_OK;
  363. }
  364. /////////////////////////////////////////////////////////////////////////////////////////////////
  365. // allocate a new colinfo and Copy column information
  366. /////////////////////////////////////////////////////////////////////////////////////////////////
  367. HRESULT cRowColumnInfoMemMgr::CopyColumnInfoList(DBCOLUMNINFO *& pNew,BOOL bBookMark)
  368. {
  369. HRESULT hr = E_OUTOFMEMORY;
  370. ULONG_PTR nBytesToAlloc = m_cbColumnInfoBytesUsed;
  371. DBCOLUMNINFO * pTemp = NULL;
  372. ULONG_PTR cSourceBytesToBeCopied = 0;
  373. //===================================================================================================================
  374. // Adjust the bytes to be allocated for column info , if there is a source rowset ( which is in case of row object
  375. // created from rowset)
  376. //===================================================================================================================
  377. if(m_pSrcRsColInfo != NULL)
  378. {
  379. pTemp = m_pSrcRsColInfo->m_DBColInfoList;
  380. cSourceBytesToBeCopied = m_pSrcRsColInfo->m_cbColumnInfoBytesUsed;
  381. nBytesToAlloc += cSourceBytesToBeCopied;
  382. //==============================================================
  383. // If there is no bookmarks required , then calculate
  384. // the bytes to be copied accordingly
  385. //==============================================================
  386. if( bBookMark == FALSE)
  387. {
  388. pTemp = pTemp++;
  389. cSourceBytesToBeCopied -= sizeof(DBCOLUMNINFO);
  390. }
  391. }
  392. if( bBookMark == FALSE)
  393. {
  394. nBytesToAlloc -= sizeof(DBCOLUMNINFO);
  395. }
  396. try
  397. {
  398. pNew = (DBCOLUMNINFO *)g_pIMalloc->Alloc( nBytesToAlloc );
  399. }
  400. catch(...)
  401. {
  402. if(pNew)
  403. {
  404. g_pIMalloc->Free(pNew);
  405. }
  406. throw;
  407. }
  408. if( pNew ){
  409. //===================================================================================================================
  410. // if there is a source rowset then copy the col info of the source rowset and then col info of the remaining
  411. // columns
  412. //===================================================================================================================
  413. if(m_pSrcRsColInfo != NULL)
  414. {
  415. memcpy(pNew,pTemp,cSourceBytesToBeCopied);
  416. memcpy(((BYTE *)pNew) + cSourceBytesToBeCopied,m_DBColInfoList,m_cbColumnInfoBytesUsed);
  417. }
  418. else
  419. {
  420. if(bBookMark == TRUE)
  421. {
  422. memcpy(pNew,m_DBColInfoList,m_cbColumnInfoBytesUsed);
  423. }
  424. else
  425. {
  426. memcpy(pNew,&m_DBColInfoList[1],m_cbColumnInfoBytesUsed-sizeof(DBCOLUMNINFO));
  427. }
  428. }
  429. hr = S_OK;
  430. }
  431. else
  432. {
  433. hr = E_OUTOFMEMORY;
  434. }
  435. return hr;
  436. }
  437. /////////////////////////////////////////////////////////////////////////////////////////////////
  438. // Copy column names to the buffer
  439. /////////////////////////////////////////////////////////////////////////////////////////////////
  440. HRESULT cRowColumnInfoMemMgr::CopyColumnNamesList(WCHAR *& pNew)
  441. {
  442. HRESULT hr = E_OUTOFMEMORY;
  443. DBLENGTH nBytesUsed = (ULONG)((m_lpCurrentName - m_pbColumnNames) * sizeof(WCHAR));
  444. DBLENGTH nBytesUsedBySrcRs = 0;
  445. WCHAR *pTemp = NULL;
  446. pTemp = m_pSrcRsColInfo != NULL ? m_pSrcRsColInfo->m_pbColumnNames : m_pbColumnNames;
  447. //===================================================================================================================
  448. // Adjust the bytes to be allocated for column names , if there is a source rowset ( which is in case of row object
  449. // created from rowset)
  450. //===================================================================================================================
  451. if(m_pSrcRsColInfo != NULL)
  452. {
  453. nBytesUsedBySrcRs = (m_pSrcRsColInfo->m_lpCurrentName - m_pSrcRsColInfo->m_pbColumnNames) * sizeof(WCHAR);
  454. }
  455. try
  456. {
  457. pNew = (WCHAR *)g_pIMalloc->Alloc( nBytesUsed + nBytesUsedBySrcRs);
  458. } // try
  459. catch(...)
  460. {
  461. if(pNew)
  462. {
  463. g_pIMalloc->Free(pNew);
  464. }
  465. throw;
  466. }
  467. if( pNew )
  468. {
  469. //===================================================================================================================
  470. // if there is a source rowset then copy the names of the source rowset and then the names of the remaining
  471. // columns
  472. //===================================================================================================================
  473. if(m_pSrcRsColInfo != NULL)
  474. {
  475. memcpy( pNew, pTemp, nBytesUsedBySrcRs);
  476. memcpy( ((BYTE *)pNew) + nBytesUsedBySrcRs, m_pbColumnNames, nBytesUsed);
  477. }
  478. else
  479. {
  480. memcpy( pNew, pTemp, nBytesUsed);
  481. }
  482. hr = S_OK;
  483. }
  484. else
  485. {
  486. hr = E_OUTOFMEMORY;
  487. }
  488. return hr;
  489. }
  490. /////////////////////////////////////////////////////////////////////////////////////////////////
  491. // Gives the ordinal of the column given the name of the column
  492. /////////////////////////////////////////////////////////////////////////////////////////////////
  493. DBORDINAL cRowColumnInfoMemMgr::GetColOrdinal(WCHAR *pColName)
  494. {
  495. DBORDINAL lOrdinal = -1;
  496. DBCOUNTITEM cCols = m_cbTotalCols;
  497. //===================================================================================================================
  498. // Adjust the ordinal fo the column , if there is a source rowset ( which is in case of row object
  499. // created from rowset)
  500. if(m_pSrcRsColInfo != NULL)
  501. {
  502. lOrdinal = m_pSrcRsColInfo->GetColOrdinal(pColName);
  503. cCols = m_cbTotalCols - m_pSrcRsColInfo->m_cbTotalCols;
  504. }
  505. // If ordinal is not found in the source rowset then search in the current col info
  506. if( (DB_LORDINAL)lOrdinal == -1)
  507. {
  508. for(DBORDINAL lIndex = 0 ; lIndex < cCols ; lIndex++)
  509. {
  510. if(m_DBColInfoList[lIndex].pwszName != NULL)
  511. if(0 == _wcsicmp(m_DBColInfoList[lIndex].pwszName,pColName))
  512. {
  513. lOrdinal = m_DBColInfoList[lIndex].iOrdinal;
  514. break;
  515. }
  516. }
  517. }
  518. return lOrdinal;
  519. }
  520. /////////////////////////////////////////////////////////////////////////////////////////////////
  521. // Gives the column type of the column
  522. /////////////////////////////////////////////////////////////////////////////////////////////////
  523. DBTYPE cRowColumnInfoMemMgr::ColumnType(DBORDINAL icol)
  524. {
  525. if(m_pSrcRsColInfo != NULL && icol < m_nFirstIndex)
  526. {
  527. return m_pSrcRsColInfo->m_DBColInfoList[icol].wType;
  528. }
  529. else
  530. {
  531. return m_DBColInfoList[icol-m_nFirstIndex].wType;
  532. }
  533. }
  534. /////////////////////////////////////////////////////////////////////////////////////////////////
  535. // Gives the name of the columns
  536. /////////////////////////////////////////////////////////////////////////////////////////////////
  537. WCHAR * cRowColumnInfoMemMgr::ColumnName(DBORDINAL icol)
  538. {
  539. if(m_pSrcRsColInfo != NULL && icol < m_nFirstIndex)
  540. {
  541. return m_pSrcRsColInfo->m_DBColInfoList[icol].pwszName;
  542. }
  543. else
  544. {
  545. return m_DBColInfoList[icol-m_nFirstIndex].pwszName;
  546. }
  547. }
  548. /////////////////////////////////////////////////////////////////////////////////////////////////
  549. // Gives the column flags of a particular column
  550. /////////////////////////////////////////////////////////////////////////////////////////////////
  551. DBCOLUMNFLAGS cRowColumnInfoMemMgr::ColumnFlags(DBORDINAL icol)
  552. {
  553. if(m_pSrcRsColInfo != NULL && icol < m_nFirstIndex)
  554. {
  555. return m_pSrcRsColInfo->m_DBColInfoList[icol].dwFlags;
  556. }
  557. else
  558. {
  559. return m_DBColInfoList[icol-m_nFirstIndex].dwFlags;
  560. }
  561. }
  562. /////////////////////////////////////////////////////////////////////////////////////////////////
  563. // Get the offset of a particular columns
  564. /////////////////////////////////////////////////////////////////////////////////////////////////
  565. DBBYTEOFFSET cRowColumnInfoMemMgr::GetDataOffset(DBORDINAL icol)
  566. {
  567. if(m_pSrcRsColInfo != NULL && icol < m_nFirstIndex)
  568. {
  569. return m_pSrcRsColInfo->m_rgdwDataOffsets[icol];
  570. }
  571. else
  572. {
  573. return m_rgdwDataOffsets[icol-m_nFirstIndex];
  574. }
  575. }
  576. /////////////////////////////////////////////////////////////////////////////////////////////////
  577. // Get the total number of columns in the col info manager for a particula row/rowset
  578. /////////////////////////////////////////////////////////////////////////////////////////////////
  579. DBCOUNTITEM cRowColumnInfoMemMgr::GetTotalNumberOfColumns()
  580. {
  581. DBCOUNTITEM cColumns = m_cbTotalCols;
  582. if(m_pSrcRsColInfo != NULL)
  583. {
  584. cColumns += m_pSrcRsColInfo->m_cbTotalCols;
  585. }
  586. return m_cbTotalCols;
  587. }
  588. /////////////////////////////////////////////////////////////////////////////////////////////////
  589. // Get the number of columns in the sources rowset
  590. /////////////////////////////////////////////////////////////////////////////////////////////////
  591. DBCOUNTITEM cRowColumnInfoMemMgr::GetNumberOfColumnsInSourceRowset()
  592. {
  593. DBCOUNTITEM cColumns = 0;
  594. if(m_pSrcRsColInfo != NULL)
  595. {
  596. cColumns = m_pSrcRsColInfo->m_cbTotalCols;
  597. }
  598. return cColumns;
  599. }
  600. /////////////////////////////////////////////////////////////////////////////////////////////////
  601. // Set the CIMTYPE of the column
  602. // IF index is -1 then set the CIMTYPE of the current col
  603. /////////////////////////////////////////////////////////////////////////////////////////////////
  604. void cRowColumnInfoMemMgr::SetCIMType(ULONG dwCIMType,DBORDINAL lIndex)
  605. {
  606. if((DB_LORDINAL)lIndex == -1)
  607. {
  608. lIndex = m_cbCurrentIndex;
  609. }
  610. if(m_pSrcRsColInfo != NULL && lIndex < m_nFirstIndex)
  611. {
  612. m_rgCIMType[lIndex] = dwCIMType;
  613. }
  614. else
  615. {
  616. m_rgCIMType[lIndex-m_nFirstIndex] = dwCIMType;
  617. }
  618. }
  619. /////////////////////////////////////////////////////////////////////////////////////////////////
  620. // Get the CIMTYPE of the column
  621. /////////////////////////////////////////////////////////////////////////////////////////////////
  622. LONG cRowColumnInfoMemMgr::GetCIMType(DBORDINAL icol)
  623. {
  624. LONG lRet = -1;
  625. if(m_pSrcRsColInfo != NULL && icol < m_nFirstIndex)
  626. {
  627. lRet = m_rgCIMType[icol];
  628. }
  629. else
  630. {
  631. lRet = m_rgCIMType[icol-m_nFirstIndex];
  632. }
  633. return lRet;
  634. }
  635. /////////////////////////////////////////////////////////////////////////////////////////////////
  636. // get the number of bytes copied for source rowset
  637. /////////////////////////////////////////////////////////////////////////////////////////////////
  638. DBLENGTH cRowColumnInfoMemMgr::GetCountOfBytesCopiedForSrcRs()
  639. {
  640. DBLENGTH nBytesUsedBySrcRs = 0;
  641. //===================================================================================================================
  642. // Adjust the bytes to be allocated for column names , if there is a source rowset ( which is in case of row object
  643. // created from rowset)
  644. //===================================================================================================================
  645. if(m_pSrcRsColInfo != NULL)
  646. {
  647. nBytesUsedBySrcRs = (m_pSrcRsColInfo->m_lpCurrentName - m_pSrcRsColInfo->m_pbColumnNames) * sizeof(WCHAR);
  648. }
  649. else
  650. {
  651. nBytesUsedBySrcRs = 0;
  652. }
  653. return nBytesUsedBySrcRs;
  654. }
  655. /////////////////////////////////////////////////////////////////////////////////////////////////
  656. // get the pointer to starting point of the column names
  657. /////////////////////////////////////////////////////////////////////////////////////////////////
  658. WCHAR * cRowColumnInfoMemMgr::ColumnNameListStartingPoint()
  659. {
  660. return m_pbColumnNames;
  661. }
  662. /////////////////////////////////////////////////////////////////////////////////////////////////
  663. // get the current index
  664. /////////////////////////////////////////////////////////////////////////////////////////////////
  665. DBORDINAL cRowColumnInfoMemMgr::GetCurrentIndex()
  666. {
  667. return (m_cbCurrentIndex + m_nFirstIndex);
  668. }
  669. /////////////////////////////////////////////////////////////////////////////////////////////////
  670. // get the pointer to starting point of the column names for the source rowset
  671. /////////////////////////////////////////////////////////////////////////////////////////////////
  672. WCHAR * cRowColumnInfoMemMgr::ColumnNameListStartingPointOfSrcRs()
  673. {
  674. WCHAR *pwszRet = NULL;
  675. if(m_pSrcRsColInfo != NULL)
  676. {
  677. pwszRet = m_pSrcRsColInfo->m_pbColumnNames;
  678. }
  679. return pwszRet;
  680. }