📄 metakit for tcl.mht
字号:
From: =?gb2312?B?08kgV2luZG93cyBJbnRlcm5ldCBFeHBsb3JlciA3ILGjtOY=?=
Subject: Metakit for Tcl
Date: Thu, 28 Feb 2008 23:04:18 +0800
MIME-Version: 1.0
Content-Type: multipart/related;
type="text/html";
boundary="----=_NextPart_000_001B_01C87A5E.3F217190"
X-MimeOLE: Produced By Microsoft MimeOLE V6.0.6000.16545
这是 MIME 格式的多方邮件。
------=_NextPart_000_001B_01C87A5E.3F217190
Content-Type: text/html;
charset="gb2312"
Content-Transfer-Encoding: quoted-printable
Content-Location: http://www.equi4.com/metakit/tcl.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Metakit for Tcl</TITLE>
<META http-equiv=3DContent-Type content=3D"text/html; charset=3Dgb2312">
<META content=3D"MSHTML 6.00.6000.16609" name=3DGENERATOR></HEAD>
<BODY bgColor=3D#ffffff><A name=3Dtop></A><A =
href=3D"http://www.scriptics.com/"><IMG=20
height=3D75 src=3D"http://www.equi4.com/metakit/tcl.gif" width=3D51 =
align=3Dleft=20
border=3D0></A> <A href=3D"http://www.equi4.com/"><IMG height=3D35=20
src=3D"http://www.equi4.com/metakit/e4s.gif" width=3D97 align=3Dright =
vspace=3D3=20
border=3D0></A>=20
<CENTER>
<H2> Metakit for Tcl</H2><I>The structured database =
which=20
fits in the palm of your hand =
</I>
<P>[ <A =
href=3D"http://www.equi4.com/metakit/tcl.html#Overview">Overview</A> | =
<A=20
href=3D"http://www.equi4.com/metakit/tcl.html#Terminology">Terminology</A=
> | <A=20
href=3D"http://www.equi4.com/metakit/tcl.html#inst">Installation</A> | =
<A=20
href=3D"http://www.equi4.com/metakit/tcl.html#start">Getting started</A> =
| <A=20
href=3D"http://www.equi4.com/metakit/tcl.html#ref">Mk4tcl Reference</A> =
]=20
</CENTER>
<P><B>Buzzwords</B> - <A =
href=3D"http://www.equi4.com/metakit/">Metakit</A> is an=20
embeddable database which runs on Unix, Windows, Macintosh, and other =
platforms.=20
It lets you build applications which store their data efficiently, in a =
portable=20
way, and which will not need a complex runtime installation. In terms of =
the=20
data model, Metakit takes the middle ground between RDBMS, OODBMS, and =
flat-file=20
databases - yet it is quite different from each of them.=20
<P><B>Technology</B> - Everything is stored variable-sized yet with =
efficient=20
positional row access. Changing an existing datafile structure is as =
simple as=20
re-opening it with that new structure. All changes are transacted. You =
can mix=20
and match software written in C++, Python, and Tcl. Things can't get =
much more=20
flexible...=20
<P><B>Tcl/Tk</B> - The extension for <A =
href=3D"http://www.tcl.tk/">Tcl</A> is=20
called "Mk4tcl". It is being used in a number of commercial projects, =
for=20
in-house use as well as in commercially distributed products.=20
<P><B>Mk4tcl 2.4.9.6</B> - is a final/production release. The <A=20
href=3D"http://www.equi4.com/metakit.html">homepage</A> points to a =
download area=20
with pre-compiled shared libraries for Unix, Windows, and Macintosh. The =
Metakit=20
source distribution includes this documentation, the Mk4tcl C++ source =
code, a=20
small Tcl test suite, a "mkshow.tcl" utility which lets you examine data =
in any=20
Metakit datafile from the command line, and a few more goodies.=20
<P><B>License and support</B> - Metakit 2 and up are distributed under =
the=20
liberal X/MIT-style open source license. Commercial support is available =
through=20
an Enterprise License. See the <A=20
href=3D"http://www.equi4.com/mklicense.html">license</A> page for =
details.=20
<P><B>Credits</B> - Are due to Mark Roseman for providing the initial =
incentive=20
and feedback, and to Matt Newman for a range of suggestions and ideas.=20
Evidently, Mk4tcl could not exist without the Tcl/Tk scripting platform =
and its=20
superb extensibility.=20
<P><B>Updates</B> - The latest version of this document is at <A=20
href=3D"http://www.equi4.com/metakit/tcl.html">http://www.equi4.com/metak=
it/tcl.html</A>.=20
<A name=3DOverview>
<HR SIZE=3D1>
</A>
<H2>Overview</H2>Metakit is a machine- and language-independent toolkit =
for=20
storing and managing structured data. This is a description of the =
<I>Mk4tcl</I>=20
extension, which allows you to create, access, and manipulate Metakit =
datafiles=20
using Tcl. Here is a Tcl script which selects, sorts, and displays some=20
previously stored results: <PRE> mk::file open db phonebook.dat =
-readonly
foreach i [mk::select db.persons -glob name "Jon*" -sort date] {
puts "Found [mk::get db.persons!$i name phone date]"
}</PRE>This script illustrates how easy it is to access stored data =
from=20
Tcl. What it does not show, however, is that numeric data can be stored =
in=20
binary format (yet remain fully portable), that datafiles can contain =
complex=20
(nested) datastructures, that the structure of datafiles can be adjusted =
at any=20
time, and that all modifications use the commit / rollback transaction =
model.=20
<P>In actual use, Metakit resembles more an array manipulation package =
than a=20
database - with the main access mechanism being <I>'by position'</I>, =
not by=20
primary key. The Tcl interface does not yet cover all operations =
provided by the=20
complete C++ interface of Metakit, but as the <I>mk::select</I> command=20
illsutrates, it does include quite flexible forms of searching and =
sorting.=20
<P>
<P><A name=3DTerminology>
<HR SIZE=3D1>
</A>
<H2>Terminology</H2>There are several ways to say the same thing, =
depending on=20
where you're coming from. For example, the terms <I>table</I>, =
<I>list</I>,=20
<I>collection</I>, <I>array</I>, <I>sequence</I>, and <I>vector</I> all =
denote a=20
more or less similar concept. To help avoid confusion, Metakit uses a =
simple=20
(but hopefully precise) terminology.=20
<P>The terms adopted by Metakit can be summarized as follows:=20
<P>
<UL>
<LI>A <B>view</B> is an indexable collection of <B>rows</B> (a =
<I>table</I> of=20
<I>records</I>, an <I>array</I> of <I>elements</I>).=20
<LI>An <B>index</B> is a position in a <I>view</I>, used to specify a=20
<I>row</I> (the first row is at index zero).=20
<LI>Each view has an ordered set of <B>properties</B>, used to refer =
to the=20
data values of each row.=20
<LI>In Metakit, each (<I>view</I>, <I>index</I>, <I>property</I>) =
combination=20
denotes a single data value.=20
<LI>A different way to describe this combination would be: =
(<I>matrix</I>,=20
<I>row-index</I>, <I>column-id</I>).=20
<LI>Data values can be strings, numeric, untyped data, or a nested =
view,=20
called a <B>subview</B>.=20
<LI>A <B>cursor</B> is a reference to a specific row in a specific =
view, i.e.=20
a (<I>view</I>, <I>index</I>) tuple. </LI></UL>
<P>The <I>Mk4tcl</I> extension adds several notational conventions:=20
<P>
<UL>
<LI>A <B>tag</B> is an identifier used to refer to an open datafile.=20
<LI>Top-level views are specified as <B>tag.viewname</B>.=20
<LI>Row <B>N</B> in such a view can be specified as =
<B>tag.viewname!N</B>.=20
<LI>Subviews extend this notation, e.g. <B>tag.viewname!N.subview</B>. =
<LI>Sub-rows continue in the same way, e.g. =
<B>tag.viewname!N.subview!M</B>.=20
<LI>The specification of a view (either top-level or subview) is =
called a=20
<B>path</B>.=20
<LI>Thus, both <I>tag.viewname</I> and <I>tag.viewname!N.subview</I> =
are=20
paths.=20
<LI>In <I>Mk4tcl</I>, a cursor placed at the Nth row is equivalent to =
the=20
string "<B>path!N</B>".=20
<LI>A trailing row index is allowed and ignored wherever a path is =
expected.=20
<LI>As a result, cursors are allowed (and frequently used) as path =
arguments.=20
</LI></UL>
<P>A few more comments about the semantics of Metakit:=20
<P>
<UL>
<LI>Views are <I>homogenous</I>: each row in a view contains the same =
type of=20
information.=20
<LI>This also implies that all subviews within the same view always =
have the=20
same structure.=20
<LI>Rows are either part of a view on file, or <I>temporary</I> (gone =
when no=20
longer referenced).=20
<LI>A cursor need not point to an existing row (its current position =
may be=20
out of range). </LI></UL>
<P><A name=3Dinst>
<HR SIZE=3D1>
</A>
<H2>Installation</H2>
<OL>
<LI>Download the latest version from <A=20
href=3D"http://www.equi4.com/pub/mk/">http://www.equi4.com/pub/mk/</A> =
<LI>On Unix, rename the appropriate compiled extension to "Mk4tcl.so" =
(on=20
Win/Mac, use the corresponding file)=20
<LI>Do a small test, by running "demo.tcl". If all is well, you should =
get=20
some self-explanatory output=20
<LI>Place the extension somewhere on Tcl's package search path (or =
just leave=20
it in ".") </LI></OL>
<P><A name=3Dstart>
<HR SIZE=3D1>
</A>
<H2>Getting started</H2>Create a datafile:=20
<BLOCKQUOTE><PRE>package require Mk4tcl
mk::file open db datafile.mk</PRE></BLOCKQUOTE>Create a view (this is =
the=20
Metakit term for "table"):=20
<BLOCKQUOTE><PRE>set vw [mk::view layout db.people {first last =
shoesize:I}]</PRE></BLOCKQUOTE>Add=20
two rows (this is the Metakit term for "record"):=20
<BLOCKQUOTE><PRE>mk::row append $vw first "John" last "Lennon" shoesize =
44
mk::row append $vw first "Flash" last "Gordon" shoesize =
42</PRE></BLOCKQUOTE>Commit=20
the changes to file:=20
<BLOCKQUOTE><PRE>mk::file commit db</PRE></BLOCKQUOTE>Show a list of all =
people:=20
<BLOCKQUOTE><PRE>mk::loop c $vw {puts [mk::get $c first last =
shoesize]}</PRE></BLOCKQUOTE>Show=20
a list of all people, sorted by last name:=20
<BLOCKQUOTE><PRE>foreach r [mk::select $vw -sort last] {puts [mk::get =
$vw!$r]}</PRE></BLOCKQUOTE>Show=20
a list of all people with first name 'John':=20
<BLOCKQUOTE><PRE>foreach r [mk::select $vw first "John"] {puts [mk::get =
$vw!$r]}</PRE></BLOCKQUOTE>
<P><A name=3Dref>
<HR SIZE=3D1>
</A>
<DL>
<DT>
<H2>Mk4tcl Reference</H2>
<DD>
<TABLE cellSpacing=3D0 cellPadding=3D0 border=3D0>
<TBODY>
<TR>
<TD><A=20
=
href=3D"http://www.equi4.com/metakit/tcl.html#mk_file">mk::file</A></TD>
<TD width=3D20></TD>
<TD>Opening, closing, and saving datafiles</TD>
<TR>
<TD><A=20
=
href=3D"http://www.equi4.com/metakit/tcl.html#mk_view">mk::view</A></TD>
<TD width=3D20></TD>
<TD>View structure and size operations</TD>
<TR>
<TD><A=20
=
href=3D"http://www.equi4.com/metakit/tcl.html#mk_cursor">mk::cursor</A></=
TD>
<TD width=3D20></TD>
<TD>Cursor variables for positioning</TD>
<TR>
<TD><A=20
href=3D"http://www.equi4.com/metakit/tcl.html#mk_row">mk::row</A></TD>
<TD width=3D20></TD>
<TD>Create, insert, and delete rows</TD>
<TR>
<TD><A=20
href=3D"http://www.equi4.com/metakit/tcl.html#mk_get">mk::get</A></TD>
<TD width=3D20></TD>
<TD>Fetch values</TD>
<TR>
<TD><A=20
href=3D"http://www.equi4.com/metakit/tcl.html#mk_set">mk::set</A></TD>
<TD width=3D20></TD>
<TD>Store values</TD>
<TR>
<TD><A=20
=
href=3D"http://www.equi4.com/metakit/tcl.html#mk_loop">mk::loop</A></TD>
<TD width=3D20></TD>
<TD>Iterate over the rows of a view</TD>
<TR>
<TD><A=20
=
href=3D"http://www.equi4.com/metakit/tcl.html#mkselect">mk::select</A></T=
D>
<TD width=3D20></TD>
<TD>Selection and sorting</TD>
<TR>
<TD><A=20
=
href=3D"http://www.equi4.com/metakit/tcl.html#mk_channel">mk::channel</A>=
</TD>
<TD width=3D20></TD>
<TD>Channel interface (new in 1.2)</TD></TR></TBODY></TABLE><BR>
<P></P>
<DT><A name=3Dmk_file>
<HR SIZE=3D1>
</A>
<H2>mk::file</H2>
<DD>
<H3>Opening, closing, and saving datafiles</H3>
<P></P>
<DT>SYNOPSIS
<DD><B>mk::file</B> <B>open</B> <BR><B>mk::file</B> =
<B>open</B>=20
<I>tag</I> <BR><B>mk::file</B> <B>open</B> =
<I>tag</I>=20
<I>filename</I> ?-readonly? ?-nocommit? =
?-extend?=20
?-shared? <BR><B>mk::file</B> <B>views</B> =
<I>tag</I>=20
<BR><B>mk::file</B> <B>close</B> <I>tag</I>=20
<BR><B>mk::file</B> <B>commit</B> <I>tag</I> =
?-full?=20
<BR><B>mk::file</B> <B>rollback</B> <I>tag</I> =
?-full?=20
<BR><B>mk::file</B> <B>load</B> <I>tag</I>=20
<I>channel</I> <BR><B>mk::file</B> <B>save</B>=20
<I>tag</I> <I>channel</I> <BR><B>mk::file</B>=20
<B>aside</B> <I>tag</I> <I>tag2</I>=20
<BR><B>mk::file</B> <B>autocommit</B> <I>tag</I> =
<BR>
<P></P>
<DT>DESCRIPTION
<DD>The <I>mk::file</I> command is used to open and close Metakit =
datafiles.=20
It is also used to force pending changes to disk (<I>commit</I>), to =
cancel=20
the last changes (<I>rollback</I>), and to send/receive the entire =
contents of=20
a datafile over a Tcl <I>channel</I>, including sockets =
(<I>load/save</I>).=20
<P>Without arguments, '<B>mk::file open</B>' returns the list of tags =
and=20
filenames of all datasets which are currently open (of the form =
<I>tag1 name1=20
tag2 name2 ...</I>).=20
<P>The '<B>mk::file open</B>' command associates a datafile with a =
unique=20
symbolic <I>tag</I>. A tag must consist of alphanumeric characters, =
and is=20
used in the other commands to refer to a specfic open datafile. If=20
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -