Hudzilla.org - the homepage of Paul Hudson
Contents > Databases > SQLite Wish List | Report Bug | About Me ]

9.7.2     Before you begin

This is NOT the latest copy of this book; click here for the latest version.

There are some "unique" aspects to SQLite that you should be aware of, of which the most important is its handling of field types. SQLite does not distinguish between data types beyond "string" and "number" - CHAR(255), for example, is the same as VARCHAR(20) is the same as TEXT, which makes it typeless like PHP. This might sound confusing, but it essentially boils down to "if your data type has CHAR, TEXT, BLOB, or CLOB in it, it is text; otherwise, it is a number". Note that this is fuzzy matching - VARCHAR has "CHAR" in, thus it is considered to be a text field.

There is one exception to this state of affairs, and that is when you want an auto-incrementing primary key value. If you define a field as being "INTEGER PRIMARY KEY", it must contain a 32-bit signed integer - equivalent to an INT data type in MySQL - and, if you do not fill this value when you insert a row, SQLite will automatically fill it with an integer one higher than the highest in there already. If the value is already at 2147483647, which is the highest number it can hold, SQLite will hand out random numbers. Note that the data type must be INTEGER and not INT - INT will be treated as a normal number field.

Finally, note that because SQLite stores its data in files, it is not able to handle multiple simultaneous writes to the same table. Essentially, when a write query comes in, SQLite locks the database (a file), performs the write, then unlocks the file - during the locked time, no other queries can write to that database. This is clearly a problem if you want your database to scale, or if you are using a system that does not have a reliable file locking mechanism such as NFS.





<< 9.7.1 Using SQLite   9.7.3 Getting started: sqlite_open(), sqlite_close(), sqlite_query(), and sqlite_fetch_array() >>
Table of Contents
Want to see this stuff in print? PHP in a Nutshell takes the core topics covered here, adds in thousands of edits from the editorial team and myself, and combines them to make an unbeatable reference for PHP programmers at all levels.



My latest book has hundreds more tips on how to use PHP, Apache, and MySQL, plus Perl, Python, shell scripts, performance tuning, and more!



Top-right shadow
 
Bottom-left shadow Bottom shadow

Comments from other readers
Be the first to add a comment to this chapter!



Add comment
Please note that by posting a comment here you are committing it to the public domain. This is important so that others can make use of your code themselves, and also so that I can incorporate helpful notes directly into the main text. Comments are limited to 2000 characters in length.

If you are reporting an error in the content, please tell me directly.

Your name/email address:
Your comment:
 
Now, in order to verify that you're a real person, please answer this simple question: what is three plus two?
The answer is:
(please write in
numbers, eg 19)


Top-right shadow
 
Bottom-left shadow Bottom shadow