Esempio n. 1
0
bool CClientDB::InsertInventoryData( const char* pszName, S_InventoryData Data )
{
	ICommandText*       pICommandText           = NULL;
	HRESULT             hr;
	LONG                cNumRows = 0;

	WCHAR wCmdString[1024];

	wsprintfW(wCmdString, L"INSERT INTO INVENTORY ( name, realindex, virtualindex ) VALUES ( '%S', %d, %d )", pszName, Data.lRealIndex, Data.lVirtualIndex );

	pICommandText = CreateCommand ( m_pIDBInitialize ,wCmdString 	);

	if( pICommandText == NULL )
		return false;

    if(FAILED(hr = pICommandText->Execute(
                                    NULL, 
                                    IID_NULL, 
                                    NULL, 
                                    &cNumRows, 
                                    NULL)))
    {
		LogString( LOG_NORMAL,"Fail CreateInventoryTable\n" );
	}
	pICommandText->Release();
	return true;
}
Esempio n. 2
0
bool CClientDB::UpdateInventoryData( const char* pszName, S_InventoryData Data )
{
	ICommandText*       pICommandText           = NULL;
	HRESULT             hr;
	LONG                cNumRows = 0;

	WCHAR wCmdString[1024];

	wsprintfW(wCmdString, L"UPDATE INVENTORY SET virtualindex = %d WHERE name = '%S' AND realindex = %d",Data.lVirtualIndex , pszName ,Data.lRealIndex );

	pICommandText = CreateCommand ( m_pIDBInitialize ,wCmdString 	);

	if( pICommandText == NULL )
		return false;

    if(FAILED(hr = pICommandText->Execute(
                                    NULL, 
                                    IID_NULL, 
                                    NULL, 
                                    &cNumRows, 
                                    NULL)))
    {
		LogString( LOG_NORMAL,"Fail CreateInventoryTable\n" );
		pICommandText->Release();
		return false;
	}

	pICommandText->Release();
	
	if( cNumRows == 0 )
		return false;

	return true;
}
Esempio n. 3
0
//*----------------------------------------------------------------------------
/// 매번 새로 만들려고 시도한다.. 이미 만들어져 있다면 Fail
//*----------------------------------------------------------------------------
bool CClientDB::CreateInventoryTable()
{
	ICommandText*       pICommandText           = NULL;
	HRESULT             hr;
	LONG                cNumRows = 0;

	WCHAR wCmdString[] = L"CREATE TABLE INVENTORY ( name TEXT(30), realindex long , virtualindex long )";
	
	pICommandText = CreateCommand ( m_pIDBInitialize ,wCmdString 	);

	if( pICommandText == NULL )
		return false;

    if(FAILED(hr = pICommandText->Execute(
                                    NULL, 
                                    IID_NULL, 
                                    NULL, 
                                    &cNumRows, 
                                    NULL)))
    {
		LogString( LOG_NORMAL,"Fail CreateInventoryTable\n" );
	}
	pICommandText->Release();
	return true;
}
Esempio n. 4
0
void CClientDB::GetInventoryData( const char* pszName, std::list<S_InventoryData>& Inventory)
{
	ICommandText*       pICommandText           = NULL;
	IRowset*            pIRowset                = NULL;
	HRESULT             hr;

	ULONG               cbColOffset = 0;
	LONG                cNumRows = 0;
	LONG				cRowsAffected = 0;
	int					iCount = 0;

	unsigned long		cRowsObtained;
	unsigned long		cCount;
	HACCESSOR			hAccessor;
	IAccessor *			pIAccessor = NULL;

	WCHAR wCmdString[1024];
	wsprintfW(wCmdString, L"SELECT realindex,virtualindex FROM INVENTORY WHERE name = '%S'", pszName );

	pICommandText = CreateCommand( m_pIDBInitialize ,wCmdString );
	if( pICommandText == NULL )
	{
		assert( 0 && "Fail GetInventoryData");
		return;
	}

   
    if(FAILED(hr = pICommandText->Execute(
                                    NULL, 
                                    IID_IRowset, 
                                    NULL, 
                                    &cNumRows, 
                                    (IUnknown **) &pIRowset)))
    {
		assert( 0 && "Fail GetInventoryData : ICommandText->Execute");
	    pICommandText->Release();
		return;
    }

	if( FAILED( pIRowset->QueryInterface( IID_IAccessor, (void **) &pIAccessor)))
    {
		assert( 0 && "Fail IRowset->QueryInterface"	);
		pIRowset->Release();
		pICommandText->Release();
		return;
    }
	
	const int       nParams = 2;
	S_InventoryData Data;
	memset( &Data, 0, sizeof( S_InventoryData ));
	
	static DBBINDING ExactBindings [nParams] = {
      {
         1,                          // iOrdinal
         offsetof (S_InventoryData, lRealIndex), // obValue
         0,                          // No length binding
         0,                          // No Status binding
         NULL,                       // No TypeInfo
         NULL,                       // No Object
         NULL,                       // No Extensions
         DBPART_VALUE,
         DBMEMOWNER_CLIENTOWNED,   // Ignored
         DBPARAMIO_NOTPARAM,
         sizeof (long),
         0,
         DBTYPE_I4,
         0,                          // No Precision
         0                           // No Scale
      },
      {
         2,                          // iOrdinal
         offsetof (S_InventoryData, lVirtualIndex ),   // obValue
         0,                          // No length binding
         0,                          // No Status binding
         NULL,                       // No TypeInfo
         NULL,                       // No Object
         NULL,                       // No Extensions
         DBPART_VALUE,
         DBMEMOWNER_CLIENTOWNED,    // Ignored
         DBPARAMIO_NOTPARAM,
		 sizeof(long),
         0,
         DBTYPE_I4,
         0,                          // No Precision
         0                           // No Scale
      },
	};

    if( FAILED( hr = pIAccessor->CreateAccessor( 
				DBACCESSOR_ROWDATA, 
                                nParams, 
                                ExactBindings, 
                                0, 
                                &hAccessor, 
                                NULL)))
    {
		pIAccessor->Release();
		pIRowset->Release();
		pICommandText->Release();
		assert( 0 && "Fail CreateAccessor");
		return;
        // Handle errors here.
    }

    HROW*	pRows = new HROW[256];
    while( TRUE )
    {
        if( FAILED( hr = pIRowset->GetNextRows( NULL, 0, 256, &cRowsObtained, &pRows ) ) )
        {
			CheckErrorGetNextRows( hr );
            break;
			// Handle errors here.
        }

        // Make sure some rows were obtained.
        if( cRowsObtained == 0 )
        {
			LogString(LOG_NORMAL,"ROW IS 0");
            break;
        }

        // Get the data for the each of the rows.
        for( cCount = 0; cCount < cRowsObtained; cCount++ )
        {
            // Get the row data needed.
			ZeroMemory( &Data, sizeof( Data ));
            if( FAILED( hr = pIRowset->GetData( pRows[cCount], hAccessor,  (void*)&Data )))
                CheckErrorGetData( hr );
			else
				Inventory.push_back( Data );

	    }
        // Release the rows.
        if( FAILED( hr = pIRowset->ReleaseRows( 
                                    cRowsObtained, 
                                    pRows, 
                                    NULL, 
                                    NULL, 
                                    NULL )))
        {
            // Handle errors here.
        }
		memset( &Data, 0 , sizeof( S_InventoryData ));
    }

    if( FAILED( hr = pIAccessor->ReleaseAccessor( hAccessor, NULL )))
    {
        // Handle errors here.
    }

    // Release the IAccessor object.
	if( pRows )
		delete []pRows;

    pIAccessor->Release();
	pIRowset->Release();
	pICommandText->Release();
}