Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Please review this procedure to open a table...
Message
De
15/06/2009 11:36:54
 
 
À
15/06/2009 11:24:20
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 9 SP2
Database:
Visual FoxPro
Divers
Thread ID:
01406084
Message ID:
01406102
Vues:
57
>Hi Matt,
>
>I agree with Naomi on the name.
>In addition, your procedure assumes that table file name and alias name must be the same?, so it cannot open a table twice.

You can pass in an Alias to use a different name, and open as many times as you want, but if you don't, it will use the table name


>And it would fail if the table is already open with a different alias name (missing Again clause).

Good catch. I added that. Thanks.


>And it changes the currently selected work-area which might not be desirable.

Agreed. In my app, this is desired behavior, but maybe not to someone else.

>And it probably assumes Set Exclusive Off and might fail otherwise - instead I'd use the Shared clause inside the procedure (or add another parameter).

Agreed. Again, in my app, Set Exclusive is set OFF in the bootstrap, so I do not have to deal with that.

>
>(As for SetBuffermode(): I'd pass two parameters, tcAlias and tnBuffermode, and use VarType() instead of Type() tehre, too.)

Good point on 2 params, to make it the most flexible.




>
>
>hth
>-Stefan
>
>>I've tried to make s simple procedure that will open a table, set the order, set the alias, and set the buffermode, and handle the NoUpdate clause.
>>
>>Will you all please review it and see if you can suggest any enhancements or better architecture:
>>
>>
>>*=============================================================================  
>>*== OpenTable - Generic Procedure to open a table, set the order, the alias, and the BefferMode
>>*== 1. Only the first two params are required, other are optional
>>*== 2. Pass in tnBufferMode=0 to open with NOUPDATE
>>*==   (Although this a not valid VFP BufferMode value, I can catch it and use it to set NOUPDATE)
>>*== 3. tcAlias and NoUpdate feature will only be implemented if Alias is not already in use
>>*=============================================================================  
>>Procedure OpenTable
>>
>>Lparameters tcTableName, tcIndex, tcAlias, tnBufferMode
>>
>>Local lcAgainClause, lcSelectAlias, lcUpdate, llUsedTest
>>
>> lcAgainClause=''
>> llUsedTest=Used(tcTableName)
>> lcSelectAlias=tcTableName
>> lcUpdate=''
>>
>> If Pcount()>=3 And !Empty(tcAlias)
>>  lcAgainClause=' Again Alias ' + alltrim(tcAlias)
>>  llUsedTest=Used(tcAlias)
>>  lcSelectAlias=tcAlias
>> Endif
>>	
>> If Vartype(tnBufferMode)='N' and tnBufferMode=0
>>  lcUpdate='NoUpdate'
>> Endif
>>  	
>> If !llUsedTest
>>  Select 0
>>  Use (tcTableName) &lcAgainClause &lcUpdate
>> Else
>>  Select(lcSelectAlias)
>> EndIf
>>
>> If !Empty(tcIndex)
>>  Set Order to (tcIndex)
>> EndIf
>> 
>> If Vartype(tnBufferMode)='N' and tnBufferMode>0
>>  SetBuffermode(tnBufferMode)
>> Endif
>>
>> Return (Upper(Alias())==Upper(tcTableName))
>>
>> Endproc
>>
>>
>>And the supporting SetBuffermode function:
>>
>>*-----------------------------------------------------------------------
>>*--  Set buffermode of current table to passed value
>>*----------------------------------------------------------------------
>>Function SetBuffermode
>>
>>Lparameters tnBufferMode
>>
>>*!*	1 – Sets row and table buffering off. Record locking and data writing are identical to earlier FoxPro versions. (the default).
>>*!*	2 – Sets pessimistic row buffering on.
>>*!*	3 – Sets optimistic row buffering on.
>>*!*	4 – Sets pessimistic table buffering on.
>>*!*	5 – Sets optimistic table buffering on.
>>
>>*!*	SET MULTILOCKS must be ON for all Buffering modes except 1 (off).
>>Set Multilocks On
>>
>> If Type('tnBufferMode')='N'
>>   If CursorSetProp('Buffering', tnBufferMode)=.F.
>>     =Messagebox('Error Setting Buffering Property of ' + Alias(), 0)
>>   Endif
>> Endif
>>
>>EndFunc
>>
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform