* convert SQL Path Through cursor or remote view cursot to updatable and * fetchable cursor. * parameters: cursor name (required) * ID field name(s) (required) * source table name(s) on SQL server (required * comma-separated list of non-updatable OR non-fetchable fields, * expression fields (optional) * logical .T. if ID fields should be updatable too. (optional) * NOTE - to use this routine properly, all fields in cursor should match * fields on server. * NOTE2 - you may manually specify "UpdateNameList" to match cursor field * with server fields. * This list must be in following format: * {cursor field} {server table}.{server field}[, ...] * note spaces after ','. lparameters pcCursorName, pcIDFieldName, pcSourceTables, pcNONUpdatableFields,; plUpdateIDField if cursorgetprop('SourceType', m.pcCursorName)#2 * cursor not compartible return .F. endif if !empty(cursorgetprop("Tables",m.pcCursorName)) * already updatable return .T. endif m.pcSourceTables = chrtran(m.pcSourceTables, ' ', '') local llResult, lnFCount, lcFieldsList, lcField, lcKeyField, m.lcUPDFieldsList, lcNewList m.llResult = CursorSetProp("Tables", ; iif("." $ m.pcSourceTables, m.pcSourceTables, ; substr( STRTRAN( ',' + m.pcSourceTables, ',', ',dbo.'), 2) ), m.pcCursorName) if m.llResult && prepare strings for exact substring search if !(vartype(m.pcNONUpdatableFields) == "C") m.pcNONUpdatableFields = "" endif if !empty(m.pcNONUpdatableFields) m.pcNONUpdatableFields = ',' + upper(chrtran(m.pcNONUpdatableFields,' ','')) + ',' endif m.pcIDFieldName = chrtran(m.pcIDFieldName,' ','') m.lcKeyField = ',' + upper(m.pcIDFieldName) + ',' if ',' $ m.pcSourceTables m.pcSourceTables = left(m.pcSourceTables,at(',',m.pcSourceTables)-1) endif if '.' $ m.pcSourceTables m.pcSourceTables = substr(m.pcSourceTables, at('.',m.pcSourceTables)+1) endif m.lcFieldsList = '' && fields for UPDATENAMELIST m.lcUPDFieldsList = '' && fields for UPDATABLEFIELDLIST for m.lnFCount = 1 to FCOUNT(m.pcCursorName) m.lcField = FIELD(m.lnFCount, m.pcCursorName) if !(',' + m.lcField + ',' $ m.pcNONUpdatableFields) m.lcFieldsList = m.lcFieldsList + ',' + m.lcField + ' dbo.' +; m.pcSourceTables + '.' + m.lcField if !(',' + m.lcField + ',' $ m.lcKeyField) m.lcUPDFieldsList = m.lcUPDFieldsList + ',' + m.lcField endif endif endfor m.lcNewList = cursorgetprop("UpdateNameList", m.pcCursorName) if !empty(m.lcNewList) and '.' $ m.lcNewList m.lcNewList = STRTRAN(m.lcNewList, ', ', ',') m.lcNewList = STRTRAN(m.lcNewList, ' ', ' dbo.') m.llResult = CursorSetProp("UpdateNameList", ; STRTRAN(m.lcNewList, ',', ', '), ; m.pcCursorName) else m.llResult = CursorSetProp("UpdateNameList", substr(m.lcFieldsList, 2),; m.pcCursorName) endif if m.llResult m.llResult = CursorSetProp("KeyFieldList", m.pcIDFieldName, m.pcCursorName) if m.llResult m.llResult = CursorSetProp("UpdatableFieldList",; substr(m.lcUPDFieldsList,2), m.pcCursorName) if m.llResult m.llResult = CursorSetProp("SendUpdates", .T., m.pcCursorName) endif endif endif endif return m.llResult