From: <CAR...@te...> - 2003-12-01 17:49:42
|
Hello=3A I have made a little test ( at the end of this email ) with embedded server using PInvoke=2C it=27s a very simple test but it=27s working ( it= =27s not using ADO=2ENET yet =3B) )=2E Pierre Arnaud told to me some time ago that PInvoke has some performance penalties but i have decided to start the tests with PInvoke for 3 reason= s=3A 1=2E It can be used in mono=3A=3A=2C this will allow to use it in linux=2C= and i think this is a very interesting issue=2E = 2=2E As the embedded server works only in local i think that if the performance penalty is not great=2C we can assume it=2E 3=2E It=27s much more easy for me than write a wrapper in C++ =3AD I want to hear comments about this issue=2E What do you think about give the embedded support using PInvoke =3F=3F -- Best regards Carlos Guzm=E1n =C1lvarez Vigo-Spain Example using PInvoke=3A int=5B=5D isc=5Fstatus =3D new int=5B20=5D=3B int db=5Fhandle =3D 0=3B byte=5B=5D param =3D new byte=5B0=5D=3B string connString =3D =40=22c=3A=5Cbugtracker=2Efdb=22=3B FbDpbBuffer dpb =3D new FbDpbBuffer()=3B dpb=2EAppend(1)=3B dpb=2EAppend(58=2C new byte=5B=5D =7B120=2C 10=2C 0=2C 0=7D)=3B dpb=2EAppend(63=2C new byte=5B=5D =7B3=2C 0=2C 0=2C 0=7D)=3B dpb=2EAppend(48=2C =22NONE=22)=3B dpb=2EAppend(28=2C =22SYSDBA=22)=3B dpb=2EAppend(29=2C =22masterkey=22)=3B byte=5B=5D dpbArray =3D dpb=2EToArray()=3B // Attach to database int result =3D FbClient=2Eisc=5Fattach=5Fdatabase( isc=5Fstatus=2C (short)connString=2ELength=2C connString=2C ref db=5Fhandle=2C (short)dpbArray=2ELength=2C dpbArray)=3B Console=2EWriteLine(=22Database handle=3A =7B0=7D=22=2C db=5Fhandle)=3B // Start transaction int tr=5Fhandle =3D 0=3B isc=5Fstatus =3D new int=5B20=5D=3B result =3D FbClient=2Eisc=5Fstart=5Ftransaction( isc=5Fstatus=2C ref tr=5Fhandle=2C 1=2C ref db=5Fhandle=2C 0=2C new byte=5B0=5D)=3B Console=2EWriteLine(=22Transaction handle=3A =7B0=7D=22=2C tr=5Fhandle)=3B= // Allocate statement int stmt=5Fhandle =3D 0=3B isc=5Fstatus =3D new int=5B20=5D=3B result =3D FbClient=2Eisc=5Fdsql=5Fallocate=5Fstatement( isc=5Fstatus=2C ref db=5Fhandle=2C ref stmt=5Fhandle)=3B Console=2EWriteLine(=22Statement handle=3A =7B0=7D=22=2C stmt=5Fhandle)=3B= // Prepare statement string stmt =3D =22select * from USERS=22=3B = isc=5Fstatus =3D new int=5B20=5D=3B // XSQLDA sqlda =3D new XSQLDA()=3B sqlda=2Eversion =3D 1=3B sqlda=2Esqln =3D 1=3B sqlda=2Esqld =3D 0=3B sqlda=2Esqldaid =3D new String(new char=5B8=5D)=3B // int size =3D XSQLDA=2EComputeLength(sqlda=2Esqln)=3B IntPtr xsqlda =3D Marshal=2EAllocHGlobal(size)=3B Marshal=2EStructureToPtr(sqlda=2C xsqlda=2C true)=3B XSQLVAR var =3D new XSQLVAR()=3B var=2EsqlData =3D IntPtr=2EZero=3B var=2EsqlInd =3D IntPtr=2EZero=3B Marshal=2EStructureToPtr( var=2C = new IntPtr(xsqlda=2EToInt32() + XSQLDA=2EComputeLength(0))=2C = true)=3B result =3D FbClient=2Eisc=5Fdsql=5Fprepare( isc=5Fstatus=2C ref tr=5Fhandle=2C ref stmt=5Fhandle=2C (short)stmt=2ELength=2C stmt=2C 3=2C xsqlda)=3B sqlda =3D (XSQLDA)Marshal=2EPtrToStructure(xsqlda=2C typeof(XSQLDA))=3B sqlda=2Esqln =3D sqlda=2Esqld=3B // size =3D XSQLDA=2EComputeLength(sqlda=2Esqln)=3B Marshal=2EFreeHGlobal(xsqlda)=3B xsqlda =3D Marshal=2EAllocHGlobal(size)=3B Marshal=2EStructureToPtr(sqlda=2C xsqlda=2C true)=3B for (int i =3D 0=3B i =3C sqlda=2Esqln=3B i++) =7B XSQLVAR wvar =3D new XSQLVAR()=3B wvar=2EsqlData =3D IntPtr=2EZero=3B wvar=2EsqlInd =3D IntPtr=2EZero=3B Marshal=2EStructureToPtr( wvar=2C = new IntPtr(xsqlda=2EToInt32() + XSQLDA=2EComputeLength(i))=2C true)=3B =7D = // Describe isc=5Fstatus =3D new int=5B20=5D=3B result =3D FbClient=2Eisc=5Fdsql=5Fdescribe( isc=5Fstatus=2C ref stmt=5Fhandle=2C 1=2C xsqlda)=3B sqlda =3D (XSQLDA)Marshal=2EPtrToStructure(xsqlda=2C typeof(XSQLDA))=3B XSQLVAR=5B=5D sqlvars =3D new XSQLVAR=5Bsqlda=2Esqln=5D=3B for (int i =3D 0=3B i =3C sqlda=2Esqln=3B i++) =7B sqlvars=5Bi=5D =3D new XSQLVAR()=3B sqlvars=5Bi=5D =3D (XSQLVAR)Marshal=2EPtrToStructure( new IntPtr(xsqlda=2EToInt32() + XSQLDA=2EComputeLength(i))=2C typeof(XSQLVAR))=3B =7D // Execute statement isc=5Fstatus =3D new int=5B20=5D=3B result =3D FbClient=2Eisc=5Fdsql=5Fexecute( isc=5Fstatus=2C ref tr=5Fhandle=2C ref stmt=5Fhandle=2C 1=2C IntPtr=2EZero)=3B // Fetch data isc=5Fstatus =3D new int=5B20=5D=3B size =3D XSQLDA=2EComputeLength(sqlda=2Esqln)=3B Marshal=2EFreeHGlobal(xsqlda)=3B xsqlda =3D Marshal=2EAllocHGlobal(size)=3B Marshal=2EStructureToPtr(sqlda=2C xsqlda=2C true)=3B for (int i =3D 0=3B i =3C sqlda=2Esqln=3B i++) =7B sqlvars=5Bi=5D=2EsqlData =3D Marshal=2EAllocHGlobal(sqlvars=5Bi=5D=2Esql= Len)=3B sqlvars=5Bi=5D=2EsqlInd =3D Marshal=2EAllocHGlobal(2)=3B Marshal=2EStructureToPtr( sqlvars=5Bi=5D=2C = new IntPtr(xsqlda=2EToInt32() + XSQLDA=2EComputeLength(i))=2C true)=3B =7D result =3D FbClient=2Eisc=5Fdsql=5Ffetch( isc=5Fstatus=2C ref stmt=5Fhandle=2C 1=2C xsqlda)=3B if (result !=3D 0) =7B byte=5B=5D buffer =3D new byte=5B1024=5D=3B = int length =3D FbClient=2Eisc=5Finterprete( buffer=2C ref isc=5Fstatus)=3B Console=2EWriteLine( Encoding=2EDefault=2EGetString(buffer=2C 0=2C length))=3B =7D // Interprete result sqlda =3D (XSQLDA)Marshal=2EPtrToStructure(xsqlda=2C typeof(XSQLDA))=3B byte=5B=5D=5B=5D data =3D new byte=5Bsqlda=2Esqln=5D=5B=5D=3B for (int i =3D 0=3B i =3C sqlda=2Esqln=3B i++) =7B sqlvars=5Bi=5D =3D (XSQLVAR)Marshal=2EPtrToStructure( new IntPtr(xsqlda=2EToInt32() + XSQLDA=2EComputeLength(i))=2C typeof(XSQLVAR))=3B data=5Bi=5D =3D new byte=5Bsqlvars=5Bi=5D=2EsqlLen=5D=3B Marshal=2ECopy(sqlvars=5Bi=5D=2EsqlData=2C data=5Bi=5D=2C 0=2C sqlvars=5B= i=5D=2EsqlLen)=3B =7D // Free memory for (int i =3D 0=3B i =3C sqlda=2Esqln=3B i++) =7B Marshal=2EFreeHGlobal(sqlvars=5Bi=5D=2EsqlData)=3B Marshal=2EFreeHGlobal(sqlvars=5Bi=5D=2EsqlInd)=3B =7D Marshal=2EDestroyStructure(xsqlda=2C typeof(XSQLDA))=3B Marshal=2EFreeHGlobal(xsqlda)=3B xsqlda =3D IntPtr=2EZero=3B = // Drop statement isc=5Fstatus =3D new int=5B20=5D=3B result =3D FbClient=2Eisc=5Fdsql=5Ffree=5Fstatement( isc=5Fstatus=2C ref stmt=5Fhandle=2C 2)=3B // Commit transaction isc=5Fstatus =3D new int=5B20=5D=3B result =3D FbClient=2Eisc=5Fcommit=5Ftransaction( isc=5Fstatus=2C ref tr=5Fhandle)=3B // Detach from database isc=5Fstatus =3D new int=5B20=5D=3B result =3D FbClient=2Eisc=5Fdetach=5Fdatabase( isc=5Fstatus=2C ref db=5Fhandle)=3B |