Thread: FoxPro Some General Questions/MS SQL Server GUID in VFP

MS SQL Server GUID in VFP
Source
Declare Integer UuidCreate In 'RPCRT4.dll' String @pguid
Declare Integer StringFromGUID2 In 'Ole32.dll' ;
  string rguid, String @lpsz, Integer cchMax

Select MyUniqueID() as PKID, * ;
   from customer ;
   into table c:\temp\test
Close Databases all

* Upsize
local lnHandle
lnHandle=SQLStringConnect('DRIVER=SQL Server;SERVER=cetin;Trusted_connection=Yes')
SQLExec(m.lnHandle,'Create database [VFPUIDTest]')
SQLExec(m.lnHandle,'use [VFPUIDTest]')
Text to m.lcUpsize textmerge noshow

Create Table FromVFPCustomer (
   pkid uniqueidentifier not null,
   customerID varchar(6) not null,
   company varchar(200) not null,
   contact varchar(100) not null )
Insert into FromVFPCustomer (pkid, customerID,company,contact)
   select PkID,cust_id,company, contact
   from OPENROWSET('VFPOLEDB',
         'c:\Temp\';'';'',
         'select * from "c:\Temp\Test"')
endtext   

SQLExec(m.lnHandle,m.lcUpsize)
SQLDisconnect(m.lnHandle)

Function MyUniqueID
Local pGUID,rGUID,cGUID
pGUID=Replicate(Chr(0),16)
rGUID=Replicate(Chr(0),80)

cGUID = Iif(Inlist(UuidCreate(@pGUID),0,1824),;
  Iif(StringFromGUID2(m.pGUID,@rGUID,40) # 0, ;
  Strconv(Left(m.rGUID,76),6), ""),"")
Return Chrtran(m.cGUID,'{}','')