Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Recreate views using SELECT * due to changed structure
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Recreate views using SELECT * due to changed structure
Environment versions
Visual FoxPro:
VFP 9 SP1
Database:
Firebird
Miscellaneous
Thread ID:
01411088
Message ID:
01411088
Views:
81
Hi all

I have a few tables that will have it's structure updated by the user. For that reason the RVs to the tables are created using SELECT * as I don't know what fields will be in there. I have some old code which is working in this direction but I don't know if this is the most efficient or safe way to do this.

Any suggestions are welcome.
		WAIT WINDOW "Recreating View with updated fieldnames" NOWAIT

		vp_iPID    = 0
		vp_AllRecs = 0
		lcViewName = IIF(goApp.UseLocalData(), "l", "r") + THIS.aCursors[1]
		llRetVal   = .T.
		lcViewCode = DBGETPROP(lcViewName, "VIEW", "SQL")


		THIS.SetDefaultDatabase()

		&lcViewCode


		* View Properties
		DBSETPROP(lcViewName, 'View', 'UpdateType'      , 1)
		DBSETPROP(lcViewName, 'View', 'WhereType'       , 1)
		DBSETPROP(lcViewName, 'View', 'FetchMemo'       , .T.)
		DBSETPROP(lcViewName, 'View', 'SendUpdates'     , .T.)
		DBSETPROP(lcViewName, 'View', 'UseMemoSize'     , 255)
		DBSETPROP(lcViewName, 'View', 'FetchSize'       , 100)
		DBSETPROP(lcViewName, 'View', 'MaxRecords'      , -1)
		DBSETPROP(lcViewName, 'View', 'Tables'          , SUBSTR(lcViewName, 4))
		DBSETPROP(lcViewName, 'View', 'Comment'         , [])
		DBSETPROP(lcViewName, 'View', 'BatchUpdateCount', 1)
		DBSETPROP(lcViewName, 'View', 'ShareConnection' , .F.)
		DBSETPROP(lcViewName, 'View', 'Prepared'        , .F.)
		DBSETPROP(lcViewName, 'View', 'CompareMemo'     , .T.)
		DBSETPROP(lcViewName, 'View', 'FetchAsNeeded'   , .F.)
		DBSETPROP(lcViewName, 'View', 'RuleExpression'  , [])
		DBSETPROP(lcViewName, 'View', 'RuleText'        , [])
		DBSETPROP(lcViewName, 'View', 'ParameterList'   , [vp_ipid, 'N'])


		lnOldArea       = SELECT(0)
		lcConnectName   = DBGETPROP(lcViewName, 'View', 'ConnectName')


		* View Field Properties
		SELECT 0
		USE (lcViewName)

		lnFields = AFIELDS(laFields)

		FOR lnCnt = 1 TO lnFields
			SELECT (lcViewName)

			lcField = lcViewName + "." + laFields[lnCnt, 1]

			DBSETPROP(lcField, 'Field', 'KeyField'           , UPPER(laFields[lnCnt, 1]) = "IID")
			DBSETPROP(lcField, 'Field', 'Updatable'          , .T.)
			DBSETPROP(lcField, 'Field', 'UpdateName'         , SUBSTR(lcViewName, 4) + "." + laFields[lnCnt, 1])
		ENDFOR

		USE IN (lcViewName)

		SELECT (lnOldArea)

		WAIT WINDOW "Finished Recreating View with updated fieldnames" NOWAIT
Regards
Bhavbhuti
___________________________________________
Softwares for Indian Businesses at:
http://venussoftop.tripod.com
___________________________________________
venussoftop@gmail.com
___________________________________________
Next
Reply
Map
View

Click here to load this message in the networking platform