Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can this be done in a view??
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00854846
Message ID:
00855986
Views:
23
Yes I've seen this before. I have 2 problems with doing this though. 1)I don't like the idea of having a DBC on every client machine. We're talking about a LOT of machines and it'd be a major undertaking to try to keep them all in sync, and 2)Even though you CAN do this I think it's risky. The dbc wasn't made to be toyed with at runtime - and as eaisly as views get corrupted anyway this is really asking for trouble. Plus if you are constantly changing a view you're going to end up with a bloated dbc with a zillion deleted records in it.

>Hi,
>
>there's another way to change the sql statement from a view completly at runtime, one requirement is that the dbc resides on each client machine
>(most of the code is from Doug Hennings "fixdbc" program - Thanks to Doug from here)
>
>with the following class you can do ..
>
>loChanger = createobject('oViewChanger')
>loChanger.AlterViewSQLStatement('yourView','SELECT * FROM someTable WHERE somecondition')
>USE yourView
>do something with the view ..
>USE IN yourView
>loChanger.AlterViewSQLStatement('yourView','SELECT * FROM someTable WHERE someothercondtion')
>USE yourView
>
>here's the viewchanger class ..
>
>Regards
>
>Christian
>
>DEFINE CLASS oViewChanger AS Custom
> cDBName = "viewtest" && change this to your databasename
>
> FUNCTION AlterViewSQLStatement
> LPARAMETERS lcView, lcNewSQL
>
> USE (THIS.cDBName+".dbc") IN 0 AGAIN ALIAS tmpDB
>
> SELECT tmpDB
> LOCATE FOR ALLTRIM(Objecttype) == "View" AND ALLTRIM(ObjectName) == lcView
> IF !FOUND()
> USE IN tmpDB
> RETURN .F.
> ENDIF
>
> LOCAL lbDone, lnPos, lcLength, lnLength, lnIDLength, lnIDCode, lcCurrValue, lnSQLLen
>
> lbDone = .F.
> lnPos = 1
> lnSQLLen = LEN(lcNewSQL)
>
> DO WHILE NOT lbDone
>
> * Get the length of this property.
> lcLength = SUBSTR(PROPERTY, lnPos, 4)
> lnLength = THIS.Hex2Decimal(lcLength)
>
> * Get the length of the property ID.
> lcLength = SUBSTR(PROPERTY, lnPos + 4, 2)
> lnIDLength = THIS.Hex2Decimal(lcLength)
>
> * Get the property ID.
> lcLength = SUBSTR(PROPERTY, lnPos + 6, lnIDLength)
> lnIDCode = THIS.Hex2Decimal(lcLength)
>
> IF lnIDCode = 42 && SQL Statement
> lcCurrValue = substr(PROPERTY, lnPos + lnIDLength + 6)
> lcCurrValue = left(lcCurrValue, at(chr(0), lcCurrValue) - 1)
> lnLength = LEN(lcCurrValue) + lnIDLength + 6 + 1
> REPLACE PROPERTY WITH STUFF(PROPERTY, lnPos, lnLength, ;
> THIS.Decimal2Hex(lnSQLLen + lnIDLength + 6 + 1,4) + ;
> THIS.Decimal2Hex(lnIDLength, 2) + ;
> THIS.Decimal2Hex(42, lnIDLength) + lcNewSQL + CHR(0))
> lbDone = .T.
> ELSE
> * Move the pointer to the next property. If we're out of properties, we're
> * done checking.
> lnPos = lnPos + lnLength
> IF lnPos > LEN(PROPERTY)
> lbDone = .T.
> ENDIF
> ENDIF
>
> ENDDO
>
> USE IN tmpDB
>
> RETURN .T.
>
> ENDFUNC
>
> FUNCTION Hex2Decimal
> LPARAMETERS lcValue, lbSigned
>
> LOCAL lnDecimal, lnLen, lnI, lnMSB, lnMax
> lnDecimal = 0
> lnLen = LEN(lcValue)
>
> FOR xj = 1 TO lnLen
> lnDecimal = lnDecimal + ASC(SUBSTR(lcValue, xj, 1)) * 256 ^ (xj - 1)
> ENDFOR
>
> IF lbSigned
> lnMSB = (lnLen * 8) - 1
> IF BITTEST(lnDecimal, lnMSB)
> lnMax = 2 ^ (lnMSB + 1)
> lnDecimal = lnDecimal - lnMax
> ENDIF
> ENDIF
>
> RETURN lnDecimal
> ENDFUNC
>
> FUNCTION Decimal2Hex
> lparameters tnValue, tnPlaces
> local lnPlaces,lcHex, lcOut, lnI
> lnPlaces = iif(pcount() = 1, 4, tnPlaces)
> lcHex = This.ReverseDecimal2Hex(tnValue, lnPlaces)
> lcOut = ''
> for lnI = 1 to lnPlaces
> lcOut = lcOut + substr(lcHex, lnPlaces - lnI + 1, 1)
> next lnI
> return lcOut
> ENDFUNC
>
> FUNCTION ReverseDecimal2Hex
> lparameters tnValue, tnPlaces
> local lnDecimal, lcHex, lnCurrDecimals, lnPlaces, lnI, lnExponent, lnTemp
> lnDecimal = tnValue
> lcHex = ''
> lnCurrDecimals = set('DECIMALS')
> lnPlaces = iif(pcount() = 1, 4, tnPlaces)
> set decimals to 17
> for lnI = lnPlaces to 1 step -1
> lnExponent = 256 ^ (lnI - 1)
> lnTemp = int(lnDecimal/lnExponent)
> lcHex = lcHex + chr(lnTemp)
> lnDecimal = lnDecimal - lnTemp * lnExponent
> next lnI
> set decimals to lnCurrDecimals
> return lcHex
> ENDFUNC
>
>ENDDEFINE
ICQ 10556 (ya), 254117
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform