📄 faq.tcl
字号:
the database before they will be able to see the new table.</p>}faq { Is SQLite threadsafe?} { <p>Yes. Sometimes. In order to be thread-safe, SQLite must be compiled with the THREADSAFE preprocessor macro set to 1. In the default distribution, the windows binaries are compiled to be threadsafe but the linux binaries are not. If you want to change this, you'll have to recompile.</p> <p>"Threadsafe" in the previous paragraph means that two or more threads can run SQLite at the same time on different "<b>sqlite</b>" structures returned from separate calls to <b>sqlite_open()</b>. It is never safe to use the same <b>sqlite</b> structure pointer simultaneously in two or more threads.</p> <p>Note that if two or more threads have the same database open and one thread creates a new table or index, the other threads might not be able to see the new table right away. You might have to get the other threads to close and reopen their connection to the database before they will be able to see the new table.</p> <p>Under UNIX, you should not carry an open SQLite database across a fork() system call into the child process. Problems will result if you do.</p>}faq { How do I list all tables/indices contained in an SQLite database} { <p>If you are running the <b>sqlite</b> command-line access program you can type "<b>.tables</b>" to get a list of all tables. Or you can type "<b>.schema</b>" to see the complete database schema including all tables and indices. Either of these commands can be followed by a LIKE pattern that will restrict the tables that are displayed.</p> <p>From within a C/C++ program (or a script using Tcl/Ruby/Perl/Python bindings) you can get access to table and index names by doing a SELECT on a special table named "<b>SQLITE_MASTER</b>". Every SQLite database has an SQLITE_MASTER table that defines the schema for the database. The SQLITE_MASTER table looks like this:</p><blockquote><pre>CREATE TABLE sqlite_master ( type TEXT, name TEXT, tbl_name TEXT, rootpage INTEGER, sql TEXT);</pre></blockquote> <p>For tables, the <b>type</b> field will always be <b>'table'</b> and the <b>name</b> field will be the name of the table. So to get a list of all tables in the database, use the following SELECT command:</p><blockquote><pre>SELECT name FROM sqlite_masterWHERE type='table'ORDER BY name;</pre></blockquote> <p>For indices, <b>type</b> is equal to <b>'index'</b>, <b>name</b> is the name of the index and <b>tbl_name</b> is the name of the table to which the index belongs. For both tables and indices, the <b>sql</b> field is the text of the original CREATE TABLE or CREATE INDEX statement that created the table or index. For automatically created indices (used to implement the PRIMARY KEY or UNIQUE constraints) the <b>sql</b> field is NULL.</p> <p>The SQLITE_MASTER table is read-only. You cannot change this table using UPDATE, INSERT, or DELETE. The table is automatically updated by CREATE TABLE, CREATE INDEX, DROP TABLE, and DROP INDEX commands.</p> <p>Temporary tables do not appear in the SQLITE_MASTER table. Temporary tables and their indices and triggers occur in another special table named SQLITE_TEMP_MASTER. SQLITE_TEMP_MASTER works just like SQLITE_MASTER except that it is only visible to the application that created the temporary tables. To get a list of all tables, both permanent and temporary, one can use a command similar to the following:<blockquote><pre>SELECT name FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master)WHERE type='table'ORDER BY name</pre></blockquote>}faq { Are there any known size limits to SQLite databases?} { <p>As of version 2.7.4, SQLite can handle databases up to 2^41 bytes (2 terabytes) in size on both Windows and Unix. Older version of SQLite were limited to databases of 2^31 bytes (2 gigabytes).</p> <p>SQLite arbitrarily limits the amount of data in one row to 1 megabyte. There is a single #define in the source code that can be changed to raise this limit as high as 16 megabytes if desired.</p> <p>There is a theoretical limit of about 2^32 (4 billion) rows in a single table, but this limit has never been tested.</p> There is also a theoretical limit of about 2^32 tables and indices.</p> <p>The name and "CREATE TABLE" statement for a table must fit entirely within a 1-megabyte row of the SQLITE_MASTER table. Other than this, there are no constraints on the length of the name of a table, or on the number of columns, etc. Indices are similarly unconstrained.</p> <p>The names of tables, indices, view, triggers, and columns can be as long as desired. However, the names of SQL functions (as created by the <a href="c_interface.html#cfunc">sqlite_create_function()</a> API) may not exceed 255 characters in length.</p>}faq { What is the maximum size of a VARCHAR in SQLite?} { <p>Remember, SQLite is typeless. A VARCHAR column can hold as much data as any other column. The total amount of data in a single row of the database is limited to 1 megabyte. You can increase this limit to 16 megabytes, if you need to, by adjusting a single #define in the source tree and recompiling.</p> <p>For maximum speed and space efficiency, you should try to keep the amount of data in a single row below about 230 bytes.</p>}faq { Does SQLite support a BLOB type?} { <p>You can declare a table column to be of type "BLOB" but it will still only store null-terminated strings. This is because the only way to insert information into an SQLite database is using an INSERT SQL statement, and you can not include binary data in the middle of the ASCII text string of an INSERT statement.</p> <p>SQLite is 8-bit clean with regard to the data it stores as long as the data does not contain any '\000' characters. If you want to store binary data, consider encoding your data in such a way that it contains no NUL characters and inserting it that way. You might use URL-style encoding: encode NUL as "%00" and "%" as "%25". Or, you might consider encoding your binary data using base-64. There is a source file named "<b>src/encode.c</b>" in the SQLite distribution that contains implementations of functions named "<b>sqlite_encode_binary()</b> and <b>sqlite_decode_binary()</b> that can be used for converting binary data to ASCII and back again, if you like.</p> }faq { How do I add or delete columns from an existing table in SQLite.} { <p>SQLite does not support the "ALTER TABLE" SQL command. If you what to change the structure of a table, you have to recreate the table. You can save existing data to a temporary table, drop the old table, create the new table, then copy the data back in from the temporary table.</p> <p>For example, suppose you have a table named "t1" with columns names "a", "b", and "c" and that you want to delete column "c" from this table. The following steps illustrate how this could be done: </p> <blockquote><pre>BEGIN TRANSACTION;CREATE TEMPORARY TABLE t1_backup(a,b);INSERT INTO t1_backup SELECT a,b FROM t1;DROP TABLE t1;CREATE TABLE t1(a,b);INSERT INTO t1 SELECT a,b FROM t1_backup;DROP TABLE t1_backup;COMMIT;</pre></blockquote>}faq { I deleted a lot of data but the database file did not get any smaller. Is this a bug?} { <p>No. When you delete information from an SQLite database, the unused disk space is added to an internal "free-list" and is reused the next time you insert data. The disk space is not lost. But neither is it returned to the operating system.</p> <p>If you delete a lot of data and want to shrink the database file, run the VACUUM command (version 2.8.1 and later). VACUUM will reconstruct the database from scratch. This will leave the database with an empty free-list and a file that is minimal in size. Note, however, that the VACUUM can take some time to run (around a half second per megabyte on the Linux box where SQLite is developed) and it can use up to twice as much temporary disk space as the original file while it is running. </p>}faq { Can I use SQLite in my commerical product without paying royalties?} { <p>Yes. SQLite is in the public domain. No claim of ownership is made to any part of the code. You can do anything you want with it.</p>}# End of questions and answers.#############puts {<DL COMPACT>}for {set i 1} {$i<$cnt} {incr i} { puts " <DT><A HREF=\"#q$i\">($i)</A></DT>" puts " <DD>[lindex $faq($i) 0]</DD>"}puts {</DL>}for {set i 1} {$i<$cnt} {incr i} { puts "<A NAME=\"q$i\"><HR />" puts "<P><B>($i) [lindex $faq($i) 0]</B></P>\n" puts "<BLOCKQUOTE>[lindex $faq($i) 1]</BLOCKQUOTE></LI>\n"}puts {</OL><p><hr /></p><p><a href="index.html"><img src="/goback.jpg" border=0 />Back to the SQLite Home Page</a></p></body></html>}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -