Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Understanding CursorAdapter methods
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Versions des environnements
Visual FoxPro:
VFP 9 SP1
Divers
Thread ID:
01475311
Message ID:
01475349
Vues:
34
This works for me:
nAutoRefreshConn=SQLSTRINGCONNECT("DRIVER=SQL Server;SERVER=(local);Trusted_Connection=Yes;DataBase=TestDB")

IF nAutoRefreshConn > 0
   oCA=CREATEOBJECT("CA_SCOPE_IDENTITY")    
   oCA.DataSource = nAutoRefreshConn
   IF oCA.CursorFill(.t.)
      BROWSE NORMAL
      IF TABLEUPDATE(1, .t.)
          BROWSE NORMAL
      ELSE
         AERROR(aaa)
         MessageBox(aaa[2])
      ENDIF
   ELSE
      AERROR(aaa)
      MessageBox(aaa[2])
   ENDIF
ENDIF


DEFINE CLASS CA_SCOPE_IDENTITY AS CursorAdapter 
     DataSourceType = [ODBC]
     Alias = "cTest"
     BufferModeOverride = 5
     SelectCmd = "select * from TestTable"
     CursorSchema="Id I, name Varchar(20)"
     UseCursorSchema= .T.    
     Tables = "TestTable"
     UpdatableFieldList="name"
     UpdateNameList="Id TestTable.Id, name TestTable.Name"
     KeyFieldList="Id"  
     AutoUpdate = "Id"
 
 
    PROCEDURE BeforeInsert(cFldState, lForce, cInsertCmd)

            IF LEN(ALLTRIM(this.AutoUpdate))>0  
                cInsertCmd = cInsertCmd + ;  
                    "; DECLARE @id int; SELECT @id = SCOPE_IDENTITY()" + ;  
                    "; EXEC Get_ValHelper @id, ?@" + ;  
                    this.Alias + "." + ALLTRIM(this.AutoUpdate)  
            ENDIF  
            ?    
            ? PROGRAM()    
            ? "cInsertCmd=",cInsertCmd    
    ENDPROC     
ENDDEFINE
In SQL Server:
CREATE DATABASE TestDB
GO
USE TestDB
GO
CREATE TABLE TestTable (Id int IDENTITY(1,1), Name varchar(20))
GO
create procedure Get_ValHelper 
(
@in Int,
@out int OUTPUT
)
AS 
 BEGIN
    SET NOCOUNT ON
    SET @out = @in
 END
GO
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform