VError VPictureData_MacPicture::SaveToFile(VFile& inFile)const
{
	VError result = VE_OK;
	if (fDataProvider && fDataProvider->GetDataSize())
	{
		VPtr p = fDataProvider->BeginDirectAccess();
		if (p)
		{
			result = inFile.Create();
			if (result == VE_OK)
			{
				VFileDesc* inFileDesc;
				result = inFile.Open(FA_READ_WRITE, &inFileDesc);
				if (result == VE_OK)
				{
					char buff[0x200];
					memset(buff, 0, 0x200);
					result = inFileDesc->PutData(buff, 0x200, 0);
					if (result == VE_OK)
					{
						result = inFileDesc->PutData(p, fDataProvider->GetDataSize(), 0x200);
					}
					delete inFileDesc;
				}
			}
			fDataProvider->EndDirectAccess();
		}
		else
			fDataProvider->ThrowLastError();

	}
	else
	{
		VBlobWithPtr blob;
		VSize outsize;
		result = Save(&blob, 0, outsize);
		if (result == VE_OK)
		{
			result = inFile.Create();
			if (result == VE_OK)
			{
				VFileDesc* inFileDesc;
				result = inFile.Open(FA_READ_WRITE, &inFileDesc);
				if (result == VE_OK)
				{
					char buff[0x200];
					memset(buff, 0, 0x200);
					result = inFileDesc->PutData(buff, 0x200, 0);
					if (result == VE_OK)
					{
						result = inFileDesc->PutData(blob.GetDataPtr(), blob.GetSize(), 0x200);
					}
					delete inFileDesc;
				}
			}
		}
	}
	return result;
}
VError VPictureData_GDIPlus::Save(VBlob* inData,VIndex inOffset,VSize& outSize,_VPictureAccumulator* /*inRecorder*/)const
{
	VError result=VE_UNKNOWN_ERROR;
	if(fDataProvider)
	{
		return inherited::Save(inData,inOffset,outSize);
	}
	else
	{
		if(fBitmap)
		{
			VBlobWithPtr blob;
				
			bool savedone=false;
			const VPictureCodec* deco=RetainDecoder();
			if(deco)
			{
				if(!deco->IsEncoder())
				{
					ReleaseRefCountable(&deco);
				}
			}
			if(!deco)
			{
				VPictureCodecFactoryRef fact;
				deco=fact->RetainDecoderByIdentifier(".png");
			}
			if(deco)
			{
					
				result = deco->Encode(this,NULL,blob); 
					
				if(result==VE_OK)
				{
					outSize=blob.GetSize();
					result=inData->PutData(blob.GetDataPtr(),outSize,inOffset);
				}
			}
		}

		/*
		if(fBitmap)
		{
			DWORD err;
			IStream* stream=NULL; 
			err= ::CreateStreamOnHGlobal(NULL,true,&stream);
			if(err == S_OK)
			{
				VPictureCodecFactoryRef fact;
				const xGDIPlusDecoderList& encoderlist=fact->xGetGDIPlus_Decoder();
				
				Gdiplus::Status stat = Gdiplus::GenericError;

				CLSID encoder;
				
				
				if(encoderlist.FindClassID(*fBitmap,encoder))
				{
					stat = fBitmap->Save(stream,&encoder,NULL);
				
					HGLOBAL glob;
					GetHGlobalFromStream(stream,&glob);
					char* c=(char*)GlobalLock(glob);
					outSize=GlobalSize(glob);
					result = inData->PutData(c,outSize,inOffset);
					GlobalUnlock(glob);
					stream->Release();
				}
				else
				{
					assert(false);
				}
			}
		}
		*/
	}
	return result;
}
Ejemplo n.º 3
0
void testMySQLConnectorPreparedStatementWithTypeBlob()
{
    CSQLConnector* connector = (CSQLConnector*) ( VComponentManager::RetainComponent ( 'MYSQ', 'SQL ' ) );

    VJSONObject* params = new VJSONObject();

    params->SetProperty ( "hostname",	MYSQL_HOST );

    params->SetProperty ( "user",		MYSQL_USER );

    params->SetProperty ( "password",	MYSQL_CORRECT_PASSWORD );

    params->SetProperty ( "database",	MYSQL_DATABASE );

    params->SetProperty ( "port",		MYSQL_PORT );

    params->SetProperty ( "ssl",			MYSQL_SSL_FALSE );

    ISQLSession* session = connector->CreateSession ( params );

    ReleaseRefCountable ( &params );

    if ( session != NULL )
    {
        ISQLStatement* statement = session->CreateStatement ( "SELECT * FROM test_blob" );

        VError error = VE_OK;

        ISQLPreparedStatement* pStmt = statement->CreatePreparedStatement ( error );

        ISQLResultSet* res = pStmt->Execute ( error );

        if ( error == VE_OK )
        {
            if ( res->IsError() )
            {
                printf ( "an error occured in the execution of the prepared statement!\n" );
            }
            else
            {
                uBYTE expected[3][16] =
                {
                    {0x0f, 0xC9, 0xCB, 0xBB, 0xCC, 0xCE, 0xB9, 0xC8, 0xCA, 0xBC, 0xCC, 0xCE, 0xB9, 0xC9, 0xCB, 0xBB},
                    {0x03, 0xAB, 0xCD, 0xEF},
                    {0x00}
                };

                sLONG i = 0;

                bool ok = true;

                while ( !res->IsEOF() )
                {
                    ISQLRow* row = res->RetainNextRow();

                    VValue* value = row->GetNthValue ( 2 );

                    VBlobWithPtr* blobValue = static_cast<VBlobWithPtr*> ( value );

                    sLONG8 len = blobValue->GetSize();



                    if ( len != expected[i][0] )
                    {
                        ok = false;
                    }
                    else if ( len == 0 )
                    {

                    }
                    else
                    {
                        uBYTE* buffer = ( uBYTE* ) ::malloc ( len );

                        xbox::VSize copied;

                        blobValue->GetData ( buffer, len, 0, &copied );

                        for ( sLONG n = 0; n < len; ++n )
                        {
                            if ( expected[i][n + 1] != buffer[n] )
                            {
                                ok = false;

                                break;
                            }
                        }
                    }


                    ReleaseRefCountable ( &row );

                    ++i;
                }

                if ( ok )
                {
                    printf ( "testMySQLConnectorPreparedStatementWithTypeBlob is OK\n" );
                }
                else
                {
                    printf ( "testMySQLConnectorPreparedStatementWithTypeBlob is KO\n" );
                }
            }

            ReleaseRefCountable ( &res );
        }
        else
        {
            printf ( "an error occured in the execution of the prepared statement!\n" );
        }

        ReleaseRefCountable ( &session );
    }
    else
    {
        printf ( "connection to mysql server failed ..\n" );
    }

    ReleaseRefCountable ( &connector );
}