Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to update sql with timestamp?
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Client/serveur
Divers
Thread ID:
00787368
Message ID:
00787516
Vues:
65
Hi Aleksey !
1. Thanks for the example
2. My problem:

As I can see you use such line if using cursoradaper
oCA.KeyFieldList="f1, t"

When I would use cursoradapter builder (wheretype=4) it would generate only
oCA.KeyFieldList="f1"
Cursoradapter builder will include timestamp column in UpdateNameList and UpdatableFieldList properties. Builder did not include Timestamp column in KeyFieldList.

Question: what realy triggers using of timestamp column in generation of update statment ?. It is not quite clear for me because I had cursoradapter with wheretype = 4, timestamp column was not included in KeyFieldList and was included in UpdateNameList and UpdatableFieldList properties and finally generated update statment did not use Timestamp column. When I included timestamp column in KeyFieldList like in your example it started to work properly (seen in profiler).



>>1. Can I redefine timestamp column, since I recreating anther cursor?
>No, you can not, but there is an easy workaround - include timestamp column into KeyFieldList.
>I suggest you to use original cursor to send updates back to SQL Server, this way VFP will use correct conversion for timestamp column. See example below.
>
>>2. With the same cursor that I am using sqlexec, vfp kind of convert the timestamp different with remote view, can create sqlexec generate the same sql statement as the remove view?
>
>Yes, I was wrong, SQL Pass-Thru cursor as opposed to remote view cursor doesn't preserve information about timestamp column. That is why the behavior is different. The same workaround (include timestamp column into KeyFieldList) can be used.
>
>How to send changes using original SQL Pass-Thru or remote view cursor:
>
>CLOSE DATABASES all
>CLEAR
>SET MULTILOCKS ON
>
>fUseView=.F.
>
>con=SQLCONNECT("LocalServer")
>
>IF fUseView
>	? "---------------- Using remote view ---------------"
>	DELETE FILE testtimestamp.*
>	CREATE DATABASE testtimestamp
>	CREATE CONNECTION testcon CONNSTRING (SQLGETPROP(con,"ConnectString"))
>	SQLDISCONNECT(con)
>	con=SQLCONNECT("testcon",.T.)
>ENDIF	
>
>SQLEXEC(con,"DROP table testtimestamp1")
>SQLEXEC(con,"CREATE table testtimestamp1 (f1 int, f2 char(10), t timestamp)")
>SQLEXEC(con,"INSERT into testtimestamp1 (f1,f2) values (1,'1111')")
>SQLEXEC(con,"INSERT into testtimestamp1 (f1,f2) values (2,'2222')")
>SQLEXEC(con,"INSERT into testtimestamp1 (f1,f2) values (3,'3333')")
>
>IF fUseView
>	CREATE SQL VIEW test REMOTE CONNECTION testcon SHARE AS select * from testtimestamp1
>ENDIF	
>
>LOCAL oCA as CursorAdapter
>
>oCA=CREATEOBJECT("TimeStampCa")
>oCA.Alias="test"
>oCA.DataSourceType="ODBC"
>oCA.DataSource=con
>oCA.SelectCmd="select * from testtimestamp1"
>oCA.BufferModeOverride=5
>oCA.Tables="testtimestamp1"
>
>IF fUseView
>	oCA.KeyFieldList="f1"
>ELSE
>	oCA.KeyFieldList="f1, t"
>ENDIF	
>
>oCA.UpdatableFieldList="f2"
>oCA.UpdateNameList="f1 testtimestamp1.f1, f2 testtimestamp1.f2, t testtimestamp1.t"
>oCA.WhereType= 4
>
>
>* get data from SQL Server
>IF fUseView
>	USE test
>	oCA.CursorAttach("test")
>ELSE	
>	oCA.CursorFill()
>ENDIF
>
>SELECT (oCA.Alias)
>? "Original data."
>LIST
>
>* convert cursor into XML
>LOCAL oXA as XMLAdapter
>oXA=CREATEOBJECT("XMLAdapter")
>
>oXA.AddTableSchema(oCA.Alias)
>oXA.IsDiffgram= .T.
>oXA.ToXML("cXML")
>
>* send XML to another client
>* load XML into cursor and make changes (assume it is done on another client)
>oXA.LoadXML(cXML)
>oXA.Tables(1).Alias="cursor2update"
>oXA.Tables(1).ToCursor()
>*SELECT cursor2update
>*LIST
>
>* modify data
>CURSORSETPROP("Buffering",5,"cursor2update")
>UPDATE cursor2update SET f2=RTRIM(f2)+"_New"
>
>* Create diffgram with changes
>oXA.ReleaseXML(.F.)
>oXA.ToXML("cXML",,,.T.,.T.)
>
>* send diffgarm back
>* now we back to the first client
>oXA.LoadXML(cXML)
>
>* we want to apply changes into our remote cursor instead of getting them into new cursor
>oXA.Tables(1).ApplyDiffgram(oCA.Alias)
>
>SELECT (oCA.Alias)
>? "Changed data."
>LIST
>
>* Now send changes to SQL Server
>*?oCA.WhereType
>IF !TABLEUPDATE(.T.)
>	AERROR(aerrors)
>	DISPLAY MEMORY LIKE aerrors
>ENDIF
>
>?
>* Get current data from  SQL Server
>oCA.CursorRefresh()
>SELECT (oCA.Alias)
>? "Updated data."
>LIST
>
>CLOSE DATABASES all
>SQLDISCONNECT(0)
>return
>
>DEFINE CLASS TimeStampCa AS CursorAdapter
>
>FUNCTION BeforeUpdate(cFldState, lForce, nUpdateType, cUpdateInsertCmd, cDeleteCmd)
>	? cUpdateInsertCmd
>ENDFUNC
>
>ENDDEFINE
>
>
>Thanks,
>Aleksey.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform