Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SPT updatable cursor - what am I missing?
Message
From
04/10/2001 11:42:20
 
 
To
04/10/2001 11:29:34
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
General information
Forum:
Visual FoxPro
Category:
Client/server
Miscellaneous
Thread ID:
00563752
Message ID:
00564207
Views:
17
Hi!

I did updating of memo fields through SPT some time ago, but I do not remember a single problem. Check what is "SQL WHERE" option in your SPT cursor - send only key fields in SQL Where. If you cannot solve the problem, simple SQLEXEC(nn,"UPDATE MyTable Set MyMemo=?MyVFPCursor.MyMemo WHERE ID=?MyVFPCursor.ID") is not that complex.

Below is that routine:
* 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
>>Sorry, maybe its too late, but if you still need, I can post here a generic routine for making SPT cursor updatable (works for SQL Server).
>
>I got it to work, and now I'm facing some quirks. It won't return a .t. from tableupdate() if a memo was changed. If the old value of the memo was empty, it works; if I update any other fields, it works; if I change the value of any memos, it doesn't, and Aerror() returns a "not implemented" error. I suppose SPT updateable cursors are of limited use then... and building an SQL update string is going to be another chore.
Vlad Grynchyshyn, Project Manager, MCP
vgryn@yahoo.com
ICQ #10709245
The professional level of programmer could be determined by level of stupidity of his/her bugs

It is not appropriate to say that question is "foolish". There could be only foolish answers. Everybody passed period of time when knows nothing about something.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform