⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tcl.html

📁 TCL的数据库处理支撑库及一些示例
💻 HTML
📖 第 1 页 / 共 3 页
字号:
    The '<b>mk::file close</b>' command closes the datafile and releases
    all associated resources.  If not opened with <i>-readonly</i> or <i>-nocommit</i>,
    all pending changes will be saved to file before closing it.  A <i>tag</i>
    loses its special meaning after the corresponding datafile has been closed.
</p><p>
    The '<b>mk::file commit</b>' command flushes all pending changes to disk.
    It should not be used on a file opened with the <i>-readonly</i> option.
    The optional <i>-full</i> argument is only useful when a <i>commit-aside</i>
    is active (see below).  In that case, changes are merged back into the main
    datafile instead of being saved separately.  The aside dataset is cleared.
</p><p>
    The '<b>mk::file rollback</b>' command cancels all pending changes
    and reverts the situation to match what was last stored on file.
    When commit-aside is active, a full rollback cause the state to be
    rollback to what it was without the aside changes.  The aside dataset 
    will be ignored from now on.
</p><p>
    The '<b>mk::file load</b>' command replaces all views with
    data read from any Tcl <i>channel</i>.  This data must have been
    generated using '<b>mk::file save</b>'.  Changes are made permanent when
    <i>commit</i> is called (explicitly or implicitly, when a datafile is closed),
    or they can be reverted by calling <i>rollback</i>.
</p><p>
    The '<b>mk::file aside</b>' command starts a special "commit-aside" mode,
    whereby changes are saved to a second database file.  This can be much
    faster that standard commits, because only changes are saved.  In commit-
    aside mode, the main datafile will not be modified it all, in fact it can
    be opened in read-only mode.
</p><p>
    The '<b>mk::file autocommit</b>' command sets up a database file to
    automatically issue a commit when the file is closed later.  This is
    useful if the file was initially opened in <i>-nocommit</i> mode, but
    you now want to change this setting (there is no way to return to
    <i>-nocommit</i>, although a rollback has a similar effect).
</p><p>
</p><p></p></dd><dt>EXAMPLES</dt><dd>
    Open a datafile (create it if necessary), for read-write access:
    <pre>    mk::file open db test.dat</pre>

    Display the structure of every view in the datafile:
    <pre>    foreach v [mk::file views db] {
        puts [mk::view layout db.$v]
    }</pre>

    Send all data across a TCP/IP socket connection:
    <pre>    set chan [socket 127.0.0.1 12345]
    mk::file save db $chan
    close $chan</pre>

    The trick to open a datafile stored inside another MK file (e.g. in VFS)
    is to load/save data via an in-memory database - replace this:
    <pre>    mk::file open db test.dat -readonly</pre>
    by this:
    <pre>    mk::file open db
    set fd [open test.dat]
    mk::file load db $fd
    close $fd</pre>
<p>
</p><p></p></dd><dt><a name="mk_view"><hr size="1"></a></dt><h2>mk::view</h2><dd><h3>View structure and size operations</h3>
<p></p></dd><dt>SYNOPSIS</dt><dd><b>mk::view</b> &nbsp;<b>layout</b> &nbsp;<i>tag.view</i> &nbsp;<br>
<b>mk::view</b> &nbsp;<b>layout</b> &nbsp;<i>tag.view</i> &nbsp;<i>{structure}</i> &nbsp;<br>
<b>mk::view</b> &nbsp;<b>delete</b> &nbsp;<i>tag.view</i> &nbsp;<br>
<b>mk::view</b> &nbsp;<b>size</b> &nbsp;<i>path</i> &nbsp;<br>
<b>mk::view</b> &nbsp;<b>size</b> &nbsp;<i>path</i> &nbsp;<i>size</i> &nbsp;<br>
<b>mk::view</b> &nbsp;<b>info</b> &nbsp;<i>path</i> &nbsp;<br>
<p></p></dd><dt>DESCRIPTION</dt><dd>
    The <i>mk::view</i> command is used to query or alter the structure of
    a <i>view</i> in a datafile (<i>layout</i>, <i>delete</i>),
    as well as the number of rows it contains (<i>size</i>).
    The last command (<i>info</i>) returns the list of properties
    currently defined for a view.
<p>
    The '<b>mk::view layout</b>' command returns a description of the current
    datastructure of <i>tag.view</i>.  If a structure is specified, the
    current data is restructured to match that, by adding new properties
    with a default value, deleting obsolete ones, and reordering them.
</p><p>
    Structure definitions consist of a list of properties.
    Subviews are specified as a sublist of two entries: the name and the
    list of properties in that subview.  Note that subviews add <i>two</i>
    levels of nesting (see <i>phones</i> in the phonebook example below).
    The type of a property is specified 
    by appending a suffix to the property name (the default type is string):
</p><p>
    </p><ul><dl compact="compact">
        <dt> <b>:S</b> </dt><dd>
            A <b>string</b> property for storing strings of any size, but no null bytes.
        </dd><dt> <b>:I</b>  </dt><dd>
            An <b>integer</b> property for efficiently storing values as integers (1..32 bits).
        </dd><dt> <b>:L</b>  </dt><dd>
            An <b>long</b> property for storing values as 64-bit integers.
        </dd><dt> <b>:F</b>  </dt><dd>
            A <b>float</b> property for storing single-precision floating point values (32 bits).
        </dd><dt> <b>:D</b>  </dt><dd>
            A <b>double</b> property for storing double-precision floating point values (64 bits).
        </dd><dt> <b>:B</b>  </dt><dd>
            A <b>binary</b> property for untyped binary data (including null bytes).
        </dd><dt> <b>:M</b>  </dt><dd>
            Obsolete (now treated as <b>:B</b>).
    </dd></dl></ul>
<p>
    Properties which are not listed int the layout will only remain set while
    the datafile is open, but not be stored.  To make properties persist,
    you must list them in the layout definition, and do so <i>before</i> setting them.
</p><p>
    The '<b>mk::view delete</b>' command completely removes a view and all
    the data it contains from a datafile.
</p><p>
    The '<b>mk::view size</b>' command returns the number of rows contained
    in the view identified as <i>tag.view</i>.  If an argument is specified,
    the size of the view is adjusted accordingly, dropping the highest
    rows if the size is decreased or adding new empty ones if the size is
    increased.  The command <i>'mk::view size 0'</i> deletes all rows from a
    view, but keeps the view in the datafile so rows can be added again later
    (unlike <i>'mk::view delete'</i>.
</p><p>
    The '<b>mk::view info</b>' returns the list of properties which are currently
    defined for <i>path</i>.<br>
</p><p>
    Note that the <i>layout</i> and <i>delete</i> sub-commands operate only on top-level
    views (of the form <i>tag.view</i>), whereas <i>size</i> and
    <i>info</i> take a <i>path</i> as arguments, which is either a top-level
    view or a nested subview
    (of the form 'tag.view!index.subview!subindex...<i>etc</i>...subview').
</p><p>
</p><p></p></dd><dt>EXAMPLES</dt><dd>
    Define a phonebook view which can store more than one
    phone number for each person:
    <pre>    mk::view layout db.book {name address {phones {category phone}}}</pre>
    Add a new phonebook entry:
    <pre>    mk::row append db.book name "Steve" address "Down-under"</pre>
    Add two phone numbers to phone book entry zero, i.e. "Steve":
    <pre>    mk::row append db.book!0.phones category "home" phone "1234567"
    mk::row append db.book!0.phones category "mobile" phone "2345678"</pre>
    Restructure the view in the datafile, adding an integer date field:
    <pre>    mk::view layout db.book {name address {phones {category phone}} date:I}</pre>
    
    Delete all phonebook entries as well as its definition from the datafile:
    <pre>    mk::view delete db.book</pre>
<p>
</p><p></p></dd><dt><a name="mk_cursor"><hr size="1"></a></dt><h2>mk::cursor</h2><dd><h3>Cursor variables for positioning</h3>
<p></p></dd><dt>SYNOPSIS</dt><dd><b>mk::cursor</b> &nbsp;<b>create</b> &nbsp;<i>cursorName</i> &nbsp;<i>?path?</i> &nbsp;<i>?index?</i> &nbsp;<br>
<b>mk::cursor</b> &nbsp;<b>position</b> &nbsp;<i>cursorName</i> &nbsp;<br>
<b>mk::cursor</b> &nbsp;<b>position</b> &nbsp;<i>cursorName</i> &nbsp;<i>0</i> &nbsp;<br>
<b>mk::cursor</b> &nbsp;<b>position</b> &nbsp;<i>cursorName</i> &nbsp;<i>end</i> &nbsp;<br>
<b>mk::cursor</b> &nbsp;<b>position</b> &nbsp;<i>cursorName</i> &nbsp;<i>index</i> &nbsp;<br>
<b>mk::cursor</b> &nbsp;<b>incr</b> &nbsp;<i>cursorName</i> &nbsp;<i>?step?</i> &nbsp;<br>
<p></p></dd><dt>DESCRIPTION</dt><dd>
    The <i>mk::cursor</i> command is used to manipulate <i>'cursor variables'</i>,
    which offer an efficient means of iterating and repositioning a 
    <i>'reference to a row in a view'</i>.
    Though cursors are equivalent to strings of the
    form <i>somepath!N</i>, it is much more efficient to keep a cursor around
    in a variable and to adjust it (using the <i>position</i> subcommand),
    than evaluating a 'somepath!$index' expression every time a cursor is expected.
<p>
    The '<b>mk::cursor create</b>' command defines (or redefines) a cursor variable.
    The <i>index</i> argument defaults to zero.  This is a convenience function, since
    <i>'mk::cursor create X somePath N'</i> is equivalent to <i>'set X somePath!N'</i>.
</p><p>
    When both <i>path</i> and <i>index</i> arguments are omitted from
    the <i>'mk::cursor create'</i> command,
    a cursor pointing to an empty temporary view is created, 
    which can be used as buffer for data not stored on file.
</p><p>
    The '<b>mk::cursor position</b>' command returns the current position of a cursor,
    i.e. the 0-based index of the row it is pointing to.  If an extra argument is
    specified, the cursor position will be adjusted accordingly.
    The '<i>end</i>' pseudo-position
    is the index of the last row (or -1 if the view is currently empty).
    Note that if '<i>X</i>' is a cursor equivalent to <i>somePath!N</i>, then
    <i>'mk::cursor position X M'</i> is equivalent to the far less efficient
    <i>'set X somePath!M'</i>.
</p><p>
    The '<b>mk::cursor incr</b>' command adjusts the current position of a cursor
    with a specified relative <i>step</i>, which can be positive as well as negative.
    If <i>step</i> is zero, then this command does nothing.
    The command <i>'mk::cursor incr X N'</i> is equivalent to
    <i>'mk::cursor position X [expr {[mk::cursor position X] + N}]'</i>.
</p><p>
</p><p></p></dd><dt><a name="mk_row"><hr size="1"></a></dt><h2>mk::row</h2><dd><h3>Create, insert, and delete rows</h3>
<p></p></dd><dt>SYNOPSIS</dt><dd><b>mk::row</b> &nbsp;<b>create</b> &nbsp;<i>?prop</i> &nbsp;<i>value</i> &nbsp;<i>...?</i> &nbsp;<br>
<b>mk::row</b> &nbsp;<b>append</b> &nbsp;<i>path</i> &nbsp;<i>?prop</i> &nbsp;<i>value</i> &nbsp;<i>...?</i> &nbsp;<br>
<b>mk::row</b> &nbsp;<b>insert</b> &nbsp;<i>cursor</i> &nbsp;<i>count</i> &nbsp;<i>?cursor2?</i> &nbsp;<br>
<b>mk::row</b> &nbsp;<b>delete</b> &nbsp;<i>cursor</i> &nbsp;<i>?count?</i> &nbsp;<br>
<b>mk::row</b> &nbsp;<b>replace</b> &nbsp;<i>cursor</i> &nbsp;<i>?cursor2?</i> &nbsp;<br>
<p></p></dd><dt>DESCRIPTION</dt><dd>
    The <i>mk::row</i> command deals with one or more rows of information.
    There is a command to allocate a temporary row which is not part of any
    datafile (<i>create</i>), and the usual set of container operations:
    appending, inserting, deleting, and replacing rows.
<p>
    The '<b>mk::row create</b>' command creates an empty temporary row, which
    is not stored in any datafile.
    Each temporary rows starts out without any properties.
    Setting a property in a row will implicitly add that
    property if necessary.
    The return value is a unique <i>cursor</i>, pointing to
    this temporary row.  The row (and all data stored in it)
    will cease to exist when no cursor references to it remain.
</p><p>
    The '<b>mk::row append</b>' command extends the view with a new row,
    optionally setting some properties in it to the specified values.
</p><p>
    The '<b>mk::row insert</b>' command is similar to the <i>append</i> sub-command,
    inserting the new row in a specified position instead of at the end.
    The <b>count</b> argument can be used to efficiently insert
    multiple copies of a row.
</p><p>
    The '<b>mk::row delete</b>' command deletes one or more rows from a view, starting
    at the row pointed to by <i>cursor</i>.
</p><p>
    The '<b>mk::row replace</b>' command replaces one row with a copy of another one,
    or clears its contents if <i>cursor2</i> is not specified.
</p><p>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -