📄 sqlitetablelist.mht
字号:
append column_insert_command "$name\} \\\" \\\"\$\{"
} else {
append column_insert_command "$name\}\\\" \\\"\$\{"
}
incr key_counter
}
append column_insert_command "\} \\\""
regsub {\$\{\}} $column_insert_command {} column_insert_command
foreach $column_names $data {
set command "$tbl insert end \"$column_insert_command\""
#puts $command
eval $command
#update idletasks
}
}</PRE>
<HR>
<P><A href=3D"http://wiki.tcl.tk/9736">LES</A> on 2006-03-24: This =
program causes=20
"segmentation fault" in my Linux box with ActiveTcl 8.5a4.</P>
<P><A href=3D"http://wiki.tcl.tk/2825">Alex Caldwell</A> Thanks, So far =
I have=20
only tested it on Windows XP with Active Tcl 8.4.9, tclsqlite 3.3.4, and =
Tablelist 4.3</P>
<HR>
<P><A href=3D"http://wiki.tcl.tk/1767">AK</A> wrote (in email):</P>
<P>This application seems to have problems when a table has an index set =
on=20
it.</P>
<P>I used it on a database I had here and it showed me additional =
columns which=20
were not in the table. From some clues (like the title of one being =
PRIMARY) I=20
guess they were for the index. However the app filled these columns with =
the=20
data from the table, not from the index, causing the values to be =
shuffled=20
around over several entries. Instead of, for example</P><PRE> a b c d e
a b c d e
...</PRE>
<P>I got shown</P><PRE> a b c d e a
b c d e a b
c d e a b c
...</PRE>
<HR>
<P><A href=3D"http://wiki.tcl.tk/2825">Alex Caldwell</A> <B>Email =
Discussion=20
Regarding Display Problem</B></P>
<P>Hi again,</P>
<P>I think I remember something that applies here - With tclsqlite, if =
you have=20
a table in the SQLite database and ask for a row back as a Tcl list, you =
can get=20
a list like this if there is an empty value in the SQLite table (I may =
be using=20
the wrong term there, is it the same as a Null value to SQLite?) in that =
row:</P><PRE> e d f {} g</PRE>
<P>I found that when you then insert a list like that into a row in the=20
Tablelist widget, the tablelist widget ignores the {} member of the =
list, and=20
moves the other members of the list to the right of it one cell over to =
the=20
left. Then the rows that come after that row in the table also all get =
shifted=20
over to the left too, so the first member of the next row will be =
inserted in=20
the last cell on the previous row's line in the tablelist widget. In our =
database, I substituted empty members of the table with a space or a _ =
so the=20
list would look like:</P><PRE> e d f {_} g</PRE>
<P>or</P><PRE> e d f { } g</PRE>
<P>This seemed to keep the Tcl list lengths in sync with the SQLite =
table and=20
the Tablelist widget's rows. I then trimmed off the extra space or _ =
when some=20
data was actually finally added to that field in the tablelist widget by =
the=20
user. I am thinking this might be where the shifting you are seeing is =
coming=20
from. I should also mention that the SQL query combobox is not fully =
compliant=20
with standard SQL. It is sensitive to the amount of whitespace - it only =
allows=20
one space between keywords in the SQL statement. It is likely it may not =
understand complicated SQL queries with nested sub queries and stuff =
like that.=20
It has only been tested with some simple queries that we used in our =
little=20
project.</P>
<HR>
<P><A href=3D"http://wiki.tcl.tk/6250">Csaba Nemethi</A> on 2006-03-24: =
It is not=20
correct that Tablelist ignores empty list elements when inserting a row. =
Here is=20
a simple example:</P><PRE> package require Tablelist
tablelist::tableist .tbl -columns {0 A 0 B 0 C}
grid .tbl
.tbl insert end {a b c}
.tbl insert end {a {} c}
.tbl insert end {{} b c}</PRE>
<P><A href=3D"http://wiki.tcl.tk/2825">Alex Caldwell</A> Thanks, I see =
that you=20
are right. I think the problems was actually sort of the reverse of what =
I said.=20
I think it comes when I collect the list from the row in the tablelist =
that is=20
being edited and send it to SQLite for updating the row. If there is an =
empty=20
cell, my list would shorten by one and that would shift the data over in =
the=20
SQLite table. So I made the cells default to contain a space, and that =
seemed to=20
be a work around for the problem I was running into. When the user =
enters some=20
data into an "empty" cell, I trim off the extra whitespace on the =
ends.</P>
<HR>
<P><A href=3D"http://wiki.tcl.tk/1767">AK</A>. My guess would then be =
that the=20
code simply creates a tablelist with the wrong number of columns:</P>
<P>Sqlite returns a list</P><PRE> {a b c d e a b c d e ...}</PRE>
<P>i.e. groups of 5. And the application inserts this into a tablelist =
which is=20
configured for n (n !=3D 5) columns, and thus takes the input in groups =
of n, and=20
this shifts everything around.</P>
<HR>
<P><A href=3D"http://wiki.tcl.tk/2825">Alex Caldwell</A> Through the use =
of some=20
really ugly looking <A href=3D"http://wiki.tcl.tk/987">regsub</A> =
expressions, I=20
was able to get the program to handle the database schema sent to me by =
<A=20
href=3D"http://wiki.tcl.tk/1767">AK</A> that was not displaying =
properly. The way=20
it gets the column names is to query the database for the table schemas. =
Then it=20
picks apart the table schema using <A =
href=3D"http://wiki.tcl.tk/986">regexp</A>=20
and <A href=3D"http://wiki.tcl.tk/987">regsub</A>, trying to get the =
column names.=20
But obviously, I had only done it on a simple table schema with no =
indexes on=20
them as in this example, which it now seems to handle. I am sure there =
are more=20
variations of table schema that it won't handle, but if I got some =
samples of=20
schema that have problems like this, I may be able to modify the "schema =
parser"=20
to become more robust:</P>
<P><B>From Email Discussion Regarding Display Problems:</B></P>
<P>This schema should show the troubles:</P><PRE> CREATE =
TABLE objects
( name TEXT NOT NULL,
version TEXT NOT NULL,
signature TEXT NOT NULL,
PRIMARY KEY (name, version),
UNIQUE (signature)
)
;
CREATE TABLE attr
( signature TEXT NOT NULL,
name TEXT NOT NULL,
value TEXT NOT NULL,
file TEXT NOT NULL,
PRIMARY KEY (signature, name)
)
;
CREATE INDEX attr_file
ON attr (file)
;</PRE>
<P>Andreas Kupries</P>
<HR>
<P><A href=3D"http://wiki.tcl.tk/1767">AK</A>: Alex, thank you very much =
for your=20
responsiveness. I just retrieved the updated code of this application =
and tried=20
again to view my database. Everything is now looking fine. Thanks =
again.</P>
<HR>
<P><A href=3D"http://wiki.tcl.tk/472">LV</A> 2007 Sep 06 I wonder - =
perhaps=20
correspondence with the SQLite developer might provide a more tcl =
compatible=20
interface for getting schema information. In that way, you wouldn't have =
to mess=20
with all the regular expressions.</P>
<P>I mean, unless the schema is kept in full ascii sql format, sqlite is =
generating the above from metadata. So it shouldn't be <B>that</B> bit =
of a deal=20
to return the information in the form of a tcl list, for instance, or =
perhaps a=20
dict.</P>
<HR>
<P><A href=3D"http://wiki.tcl.tk/14273">HJG</A> 2007-09-05 There is no =
menu and no=20
buttons, so how should saving a new database work ?</P>
<HR>
<P>[ <A href=3D"http://wiki.tcl.tk/2272">Category Application</A> | <A=20
href=3D"http://wiki.tcl.tk/3114">Category Database</A> ]</P></DIV></DIV>
<DIV id=3Dmenu_area>
<DIV id=3Dwiki_menu>
<UL id=3Dmenu>
<LI><A href=3D"http://wiki.tcl.tk/">Home</A>
<LI><A href=3D"http://wiki.tcl.tk/4">Recent changes</A>
<LI><A href=3D"http://wiki.tcl.tk/3">Help</A>
<LI><A href=3D"http://wiki.tcl.tk/_edit/15631">Edit</A>
<LI><A href=3D"http://wiki.tcl.tk/_history/15631">History</A>
<LI><A =
href=3D"http://wiki.tcl.tk/_ref/15631">References</A></LI></UL></DIV>
<FORM id=3Dsearchform action=3D/_search method=3Dget><INPUT =
type=3Dhidden=20
name=3D_charset_> <INPUT id=3Dsearchtxt onblur=3DsetSearch(); =
onfocus=3DclearSearch();=20
value=3D"Search in titles" name=3DS> </FORM>
<FORM id=3Dgsearchform action=3D/_gsearch method=3Dget><INPUT =
type=3Dhidden=20
name=3D_charset_> <INPUT id=3Dgoogletxt onblur=3DsetGoogle(); =
onfocus=3DclearGoogle();=20
value=3D"Search in pages" name=3DS> </FORM>
<DIV class=3Dnavigation>
<DIV id=3Dpage_toc></DIV></DIV>
<DIV class=3Dextra>
<DIV id=3Dwiki_toc>
<DIV class=3Dtoc1>Getting started=20
<DIV class=3Dtoc2><A class=3Dtoc href=3D"http://wiki.tcl.tk/299">What is =
Tcl?</A></DIV>
<DIV class=3Dtoc2><A class=3Dtoc href=3D"http://wiki.tcl.tk/487">What is =
Tk?</A></DIV>
<DIV class=3Dtoc2><A class=3Dtoc =
href=3D"http://wiki.tcl.tk/20786">Getting=20
Tcl/Tk</A></DIV>
<DIV class=3Dtoc2><A class=3Dtoc =
href=3D"http://wiki.tcl.tk/20788">Getting=20
help</A></DIV>
<DIV class=3Dtoc2><A class=3Dtoc =
href=3D"http://wiki.tcl.tk/20789">Learning=20
Tcl</A></DIV>
<DIV class=3Dtoc2><A class=3Dtoc href=3D"http://wiki.tcl.tk/20790">The =
Tcl Dev=20
Xchange</A></DIV>
<DIV class=3Dtoc3><A class=3Dtoc href=3D"http://wiki.tcl.tk/20791">About =
the=20
Wiki</A></DIV></DIV>
<DIV class=3Dtoc1>Community=20
<DIV class=3Dtoc2><A class=3Dtoc =
href=3D"http://wiki.tcl.tk/590">Advocacy</A></DIV>
<DIV class=3Dtoc2><A class=3Dtoc =
href=3D"http://wiki.tcl.tk/828">Conferences</A></DIV>
<DIV class=3Dtoc2><A class=3Dtoc href=3D"http://wiki.tcl.tk/20792">Chat, =
news,=20
lists</A></DIV>
<DIV class=3Dtoc2><A class=3Dtoc =
href=3D"http://wiki.tcl.tk/20794">History</A></DIV>
<DIV class=3Dtoc2><A class=3Dtoc =
href=3D"http://wiki.tcl.tk/17182">Humor</A></DIV>
<DIV class=3Dtoc2><A class=3Dtoc =
href=3D"http://wiki.tcl.tk/10681">People</A></DIV>
<DIV class=3Dtoc3><A class=3Dtoc href=3D"http://wiki.tcl.tk/20810">Tcl=20
websites</A></DIV></DIV>
<DIV class=3Dtoc1>Reference=20
<DIV class=3Dtoc2><A class=3Dtoc =
href=3D"http://wiki.tcl.tk/1887">Companies</A></DIV>
<DIV class=3Dtoc2><A class=3Dtoc =
href=3D"http://wiki.tcl.tk/20788">Getting=20
help</A></DIV>
<DIV class=3Dtoc2><A class=3Dtoc =
href=3D"http://wiki.tcl.tk/20795">Online=20
books</A></DIV>
<DIV class=3Dtoc2><A class=3Dtoc =
href=3D"http://wiki.tcl.tk/20796">Online=20
tutorials</A></DIV>
<DIV class=3Dtoc2><A class=3Dtoc href=3D"http://wiki.tcl.tk/3109">Manual =
pages</A></DIV>
<DIV class=3Dtoc2><A class=3Dtoc href=3D"http://wiki.tcl.tk/20797">Tcl=20
roadmap</A></DIV>
<DIV class=3Dtoc3><A class=3Dtoc=20
href=3D"http://wiki.tcl.tk/49">Acronyms</A></DIV></DIV>
<DIV class=3Dtoc1>Tcl software=20
<DIV class=3Dtoc2><A class=3Dtoc=20
href=3D"http://wiki.tcl.tk/20798">Applications</A></DIV>
<DIV class=3Dtoc2><A class=3Dtoc href=3D"http://wiki.tcl.tk/20799">The =
Tcl=20
core</A></DIV>
<DIV class=3Dtoc2><A class=3Dtoc =
href=3D"http://wiki.tcl.tk/20800">Development=20
tools</A></DIV>
<DIV class=3Dtoc2><A class=3Dtoc=20
href=3D"http://wiki.tcl.tk/11485">Documentation</A></DIV>
<DIV class=3Dtoc2><A class=3Dtoc =
href=3D"http://wiki.tcl.tk/940">Extensions</A></DIV>
<DIV class=3Dtoc3><A class=3Dtoc href=3D"http://wiki.tcl.tk/20801">Toys =
and=20
games</A></DIV></DIV>
<DIV class=3Dtoc1>Tcl in the wild=20
<DIV class=3Dtoc2><A class=3Dtoc href=3D"http://wiki.tcl.tk/20802">Major =
applications</A></DIV>
<DIV class=3Dtoc2><A class=3Dtoc=20
href=3D"http://wiki.tcl.tk/20803">Businesses</A></DIV>
<DIV class=3Dtoc2><A class=3Dtoc =
href=3D"http://wiki.tcl.tk/20804">Education</A></DIV>
<DIV class=3Dtoc2><A class=3Dtoc=20
href=3D"http://wiki.tcl.tk/20805">Engineering</A></DIV>
<DIV class=3Dtoc2><A class=3Dtoc=20
href=3D"http://wiki.tcl.tk/20806">Government</A></DIV>
<DIV class=3Dtoc2><A class=3Dtoc =
href=3D"http://wiki.tcl.tk/20811">Medical</A></DIV>
<DIV class=3Dtoc3><A class=3Dtoc=20
href=3D"http://wiki.tcl.tk/20809">Other</A></DIV></DIV></DIV></DIV></DIV>=
<DIV class=3Dfooter>
<P id=3Dfooter><A href=3D"http://wiki.tcl.tk/">Home</A> =E2=80=A2 <A=20
href=3D"http://wiki.tcl.tk/4">Recent changes</A> =E2=80=A2 <A=20
href=3D"http://wiki.tcl.tk/3">Help</A> =E2=80=A2 <A=20
href=3D"http://wiki.tcl.tk/_edit/15631">Edit</A> =E2=80=A2 <A=20
href=3D"http://wi
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -