General information
Category:
Databases,Tables, Views, Indexing and SQL syntax
Sergey
Here's the main code snippet that performs the SQL and update:
lnParam1 = 1000000001
=SQLExec(lnConnection, "execute ApplicationUserSelect1 ?lnParam1", 'myTable')
=SQL_Update_Table1('myTable', 'ApplicationUser', '*', 5)
replace myTable.Locked_By with 'Derek Chapman' in ltSQLRecordLock1
lnReturn=tableupdate(2, .T., 'myTable')
Here's the procedure that prepares the table for updates, the main 'code' simply builds the field list dynamically, rather than hardcoding it for each table:
Procedure SQL_Update_Table1
lparameters lcParam1, lcParam2, lcParam3, lnParam4
private all like l*
lcLocalTableFields = ''
lcRemoteTableFields = ''
for lnCount = 1 to fcount(lcParam1)
localTableFields = lcLocalTableFields + alltrim(field(lnCount)) + ', '
lcRemoteTableFields = lcRemoteTableFields + alltrim(field(lnCount)) + ' ' + lcParam2 + '.' + alltrim(field(lnCount)) + ', '
endfor
lcLocalTableFields = substr(lcLocalTableFields, 1, len(alltrim(lcLocalTableFields)) - 1)
lcRemoteTableFields = substr(lcRemoteTableFields, 1, len(alltrim(lcRemoteTableFields)) - 1)
lcLocalTableFields = iif(lcParam3 = '*', lcLocalTableFields, lcParam3)
sele &lcParam1
=CursorSetProp('KeyFieldList', lcLocalTableFields, lcParam1)
=CursorSetProp('WhereType', 3, lcParam1)
=CursorSetProp('Tables', lcParam2, lcParam1)
=CursorSetProp('UpdateNameList', lcRemoteTableFields, lcParam1)
=CursorSetProp('UpdatableFieldList', lcLocalTableFields, lcParam1)
=CursorSetProp('SendUpdates', .T., lcParam1)
=CursorSetProp('Buffering', lnParam4, lcParam1)
Return
Any ideas?
Regards
Derek
Previous
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only