I have tried two ways of opening the table:
<mvdo file="{g.lib:db}" name="l.indexes"
value="{order_by(l.table,'ORDER')}">
<mvassign name="g.tables:dbTemplateItems:open" value="1">
<mvopen name="dbTemplateItems" database="{g.strDataRoot $
'tempitem.dbf'}" indexes="{l.indexes}">
(The order_by() function goes away and builds a string with the
correct paths given the table alias, and the fields that are indexed.)
The second (preferred) method also works without errors::
<mvdo file="{g.lib:db}" name="l.ok"
value="{open_table(l.table,'ORDER')}">
(which corresponds to the following function. Note: the order_by()
function called in this function is exactly the same as in the first
example, but doesn't have to mvdo, as it's in the same file.)
<mvfunction name="open_table" parameters="alias, order"
standardoutputlevel="">
<MvCOMMENT>
# Function to check whether a table is open, and if not, open it
# This looks like a long winded way to open a table, but provides
# some error checking, and simple indexing.
# Alias is the alias of the table in the Tables db
# order is a comma delimited list of index fields used to
sort the table
#
</MvCOMMENT>
<mvopen name="dbTables" database="{g.strDataRoot $ 'tables.dbf'}"
indexes="{g.strDataRoot $ 'Xtab2.mvx'}">
<mvfind name="dbTables" value="{l.alias}" exact="EXACT">
<mvassign name="g.tables:dbTables:open" value="1">
<MvIF EXPR="{dbTables.d.alias EQ l.alias}">
<MvCOMMENT>
# Don't want to open table if it is already open, however might want
to change index.
</MvCOMMENT>
<MvIF EXPR="{NOT miva_variable_value('g.tables:' $ l.alias $
':open')}">
<mvassign name="l.strPath" value="{get_path(l.alias)}">
<mvassign name="l.strIndexes" value="{order_by(l.alias,
l.order)}">
<MvCOMMENT>
# Check to see if the selected field is indexed. If not, open
table unindexed
</MvCOMMENT>
<MvIF EXPR="{l.strIndexes}">
<mvopen name="{l.alias}" database="{l.strPath $ dbTables.d.file}"
indexes="{l.strIndexes}">
<mvelse>
<mvopen name="{l.alias}" database="{l.strPath $
dbTables.d.file}">
</MvIF>
<MvCOMMENT>
# Now that the table is open, set a flag to prevent it being
opened again
</MvCOMMENT>
<mvassign name="{'g.tables:' $ l.alias $ ':open'}" value="1">
<mvassign name="g.tables:dbTables:open" value="">
<MvCLOSE NAME="dbTables">
<mvfuncreturn value="1">
<mvelse>
<MvCOMMENT>
# If the table is already open, then just want to change the
indexes
</MvCOMMENT>
<MvEVAL EXPR="{'Table open'}">
<MvSETINDEX NAME="{l.alias}" INDEXES="{order_by(l.alias,
l.order)}">
</MvIF>
<mvelse>
<MvEVAL EXPR="{'Table not found'}"><mvexit>
</mvif>
<mvassign name="g.tables:dbTables:open" value="">
<MvCLOSE NAME="dbTables">
<mvfuncreturn value="1">
</mvfunction>
But:
When I try to run the following code immediately after the table
opening code, the mvwhile loop does not return anything in the second
case, but works fine in the first case.
<mvfilter name="{l.table}" filter="{dbTemplateItems.d.template EQ
l.strTemplate}">
<mvskip name="{l.table}">
<MvWHILE EXPR="{NOT dbTemplateItems.d.eof}">
<mvassign name="l.form:content" index="{l.intCount}"
value="{dbTemplateItems.d.content}">
<mvassign name="l.form:type" index="{l.intCount}"
value="{dbTemplateItems.d.type}">
<mvassign name="l.intCount" value="{l.intCount + 1}">
<mvskip name="{l.table}">
</MvWHILE>
The table is open, ie I can mvskip and mvgo without error, and I can
prove that the table is open by trying to to a manual mvopen of the
same file which will spit out an error saying the database is already
open.
Any idea what is going on here?
On a general note, if you can design around using Filters on indexed
databases, do so and you will get considerable efficiency gains.
--
Richard Grevers, New Plymouth, New Zealand
Hat 1: Development Engineer, Webfarm Ltd.
Hat 2: Dramatic Design www.dramatic.co.nz
Lost yet? http://www.lost.eu/3d33f