Leaked source code of windows server 2003
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.

107 lines
2.6 KiB

  1. /******************************************************************************
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. Index.cpp
  5. Abstract:
  6. This file contains the implementation of the JetBlue::Index class.
  7. Revision History:
  8. Davide Massarenti (Dmassare) 05/19/2000
  9. created
  10. ******************************************************************************/
  11. #include <stdafx.h>
  12. ////////////////////////////////////////////////////////////////////////////////
  13. JetBlue::Index::Index()
  14. {
  15. m_sesid = JET_sesidNil; // JET_SESID m_sesid;
  16. m_tableid = JET_tableidNil; // JET_TABLEID m_tableid;
  17. // MPC::string m_strName;
  18. m_grbitIndex = 0; // JET_GRBIT m_grbitIndex;
  19. m_cKey = 0; // LONG m_cKey;
  20. m_cEntry = 0; // LONG m_cEntry;
  21. m_cPage = 0; // LONG m_cPage;
  22. // ColumnVector m_vecColumns;
  23. // Column m_fake;
  24. }
  25. JetBlue::Index::~Index()
  26. {
  27. }
  28. ////////////////////////////////////////
  29. HRESULT JetBlue::Index::GenerateKey( /*[out]*/ LPSTR& szKey ,
  30. /*[out]*/ unsigned long& cKey )
  31. {
  32. __HCP_FUNC_ENTRY( "JetBlue::Index::Get" );
  33. HRESULT hr;
  34. LPSTR szPtr;
  35. int iLen = m_vecColumns.size();
  36. int iPos;
  37. szKey = NULL;
  38. cKey = 1;
  39. for(iPos=0; iPos<iLen; iPos++)
  40. {
  41. cKey += (unsigned long) m_vecColumns[iPos].m_strName.length() + 2;
  42. }
  43. __MPC_EXIT_IF_ALLOC_FAILS(hr, szKey, new CHAR[cKey]);
  44. for(szPtr=szKey,iPos=0; iPos<iLen; iPos++)
  45. {
  46. Column& col = m_vecColumns[iPos];
  47. *szPtr++ = (col.m_coldef.grbit & JET_bitKeyDescending) ? '-' : '+';
  48. strcpy( szPtr, col.m_strName.c_str() ); szPtr += col.m_strName.length() + 1;
  49. }
  50. *szPtr = 0;
  51. hr = S_OK;
  52. __HCP_FUNC_CLEANUP;
  53. __HCP_FUNC_EXIT(hr);
  54. }
  55. ////////////////////////////////////////
  56. int JetBlue::Index::GetColPosition( LPCSTR szCol )
  57. {
  58. int iLen = m_vecColumns.size();
  59. int iPos;
  60. for(iPos=0; iPos<iLen; iPos++)
  61. {
  62. Column& col = m_vecColumns[iPos];
  63. if(col.m_strName.compare( SAFEASTR( szCol ) ) == 0) return iPos;
  64. }
  65. return -1;
  66. }
  67. JetBlue::Column& JetBlue::Index::GetCol( LPCSTR szCol )
  68. {
  69. return GetCol( GetColPosition( szCol ) );
  70. }
  71. JetBlue::Column& JetBlue::Index::GetCol( /*[in]*/ int iPos )
  72. {
  73. if(0 <= iPos && iPos < m_vecColumns.size()) return m_vecColumns[iPos];
  74. return m_fake;
  75. }