<span id="Label3"></p><p><span style="font-size: 18pt"><span style="font-size: 18pt"><strong>usage details of SQLite in Android</strong></span></span><br><br><span style="font-size: 18px"><span style="font-size: 18px">today I will share with you how to use SQLite in Android. </span></span><br><br><span style="font-size: 18px"><span style="font-size: 18px"> </span></span><span style="font-size: 18px"><span style="font-size: 18px">first, Let's look at the Sqlite,sqlite is a lightweight <span style="font-size: 18px">embedded</span> database that adheres to the acid (atomicity, consistency, isolation, durability) associated database management System. </span></span><br><br><span style="font-size: 18px"><span style="font-size: 18px">Features of Sqlite:</span></span><br><br><span style="font-size: 18px"><span style="font-size: 18px"><strong>1. Lightweight</strong></span></span><br><span style="font-size: 18px">with <span style="font-size: 18px">SQLite You only need to bring a dynamic library, you can enjoy its full functionality, and the size of the dynamic library is relatively small. </span></span><br><span style="font-size: 18px"><span style="font-size: 18px"><strong>2. Independence (no installation Required)</strong></span></span><br><span style="font-size: 18px"><span style="font-size: 18px">the core engine of the SQLite database does not need to rely on Third-party software, nor does it require the so-called "install". </span></span><br><span style="font-size: 18px"><span style="font-size: 18px"><strong>3. Isolation</strong></span></span><br><span style="font-size: 18px"><span style="font-size: 18px">all information in the SQLite database (such as tables, views, triggers, Etc.) is contained within a folder for easy administration and MAINTENANCE. </span></span><br><span style="font-size: 18px"><span style="font-size: 18px"><strong>4. Cross-platform</strong></span></span><br><span style="font-size: 18px"><span style="font-size: 18px">SQLite currently supports most operating systems (windows,linux,android,ios), less than computer operating systems are also capable of running on numerous mobile systems</span></span><br><span style="font-size: 18px"><span style="font-size: 18px"><strong>5. Multi-lingual Interface</strong></span></span><br><span style="font-size: 18px">the <span style="font-size: 18px">SQLite Database supports multiple language programming Interfaces. </span></span><br><span style="font-size: 18px"><span style="font-size: 18px"><strong>6. Security</strong></span></span><br><span style="font-size: 18px"><span style="font-size: 18px">the SQLite database implements independent transaction processing through exclusive and shared locks at the database level. This means that multiple processes can read data from the same database at the same time, but only one can write Data. </span></span><br><span style="font-size: 18px"><span style="font-size: 18px"> </span></span><br><span style="font-size: 18px"><span style="font-size: 18px"><strong>SQLite Data type:</strong></span></span><br><br><span style="font-size: 18px"><span style="font-size: 18px">regular data uses fixed static data types, and SQLite uses Dynamic Data types, which are automatically judged based on the value of the Deposit. </span></span><br><span style="font-size: 18px"><span style="font-size: 18px"> </span></span><br><span style="font-size: 18px"><span style="font-size: 18px">SQLite has the following five commonly used data types:</span></span><br><span style="font-size: 18px"><span style="font-size: 18px"> ?</span></span><br><span style="font-size: 18px"><span style="font-size: 18px">Null: represents a null value</span></span><br><span style="font-size: 18px">integer <span style="font-size: 18px">: Used to store an integer, which can be stored using the 1,2,3,4,6,8 bit, depending on the size.</span></span><br><span style="font-size: 18px"><span style="font-size: 18px">Real:ieee floating point</span></span><br><span style="font-size: 18px"><span style="font-size: 18px">TEXT: stored by string</span></span><br><span style="font-size: 18px"><span style="font-size: 18px">BLOB: stored in binary value, without any changes.</span></span><br><span style="font-size: 18px"><span style="font-size: 18px"> </span></span><br><span style="font-size: 18px"><span style="font-size: 18px">Note that these types are properties of the value itself, not the properties of the Column. however, in order to be compatible with other DBMS (as well as SQL standard), the type of the column can be specified in its CREATE table statement, so SQLite has a concept of column similarity (column Affinity) . Column affinity is a property of a column, and SQLite has the following column Similarities:</span></span><br><span style="font-size: 18px"><span style="font-size: 18px"> </span></span><br><span style="font-size: 18px">the <span style="font-size: 18px">text:text column uses Null,text or blobs to store any data inserted into this column, and if the data is a number, it is converted to TEXT.</span></span><br><span style="font-size: 18px">the <span style="font-size: 18px">numeric:numeric column can use any storage type, which first attempts to convert the inserted data into a real or integer type, and if successful it is stored as real and integer, otherwise unchanged.</span></span><br><span style="font-size: 18px"><span style="font-size: 18px">integer: similar to numeric, except that it converts the integer value to integer, if it is a real type and does not have a decimal part, it is also</span> converted to an integer</span><br><span style="font-size: 18px"><span style="font-size: 18px">real: and the numeric type is just that it will convert to real and the integer value to be converted to Real.</span></span><br><span style="font-size: 18px"><span style="font-size: 18px">none: try not to make any changes.</span></span><br><span style="font-size: 18px"><span style="font-size: 18px"> </span></span><br><span style="font-size: 18px"><span style="font-size: 18px">SQLite determines the column similarity of each column based on the CREATE table Statement. the rules are as follows (case-insensitive):</span></span><br><span style="font-size: 18px"><span style="font-size: 18px">1. If an int is included in the data type, it is an integer</span></span><br><span style="font-size: 18px"><span style="font-size: 18px">2. If the data type includes char,clob,text, the text</span></span><br><span style="font-size: 18px"><span style="font-size: 18px">3. If a blob is included in the data type, or if no data type is specified, none</span></span><br><span style="font-size: 18px"><span style="font-size: 18px">4. If the data type includes Real,floa or doub, it is the real</span></span><br><span style="font-size: 18px"><span style="font-size: 18px">5. The rest of the situation is numeric</span></span><br><span style="font-size: 18px"><span style="font-size: 18px"> </span></span><br><span style="font-size: 18px"><span style="font-size: 18px"><strong>Common methods of sqlitedatabase, method names, and methods represent Meanings:</strong></span></span><br><br><span style="font-size: 18px"><span style="font-size: 18px">Open or create a database</span></span><br><span style="font-size: 18px"><span style="font-size: 18px">openorcreatedatabase (String path,sqlitedatabase.cursorfactory Factory)</span></span>、</p><p><p><br><span style="font-size: 18px">Insert a record</span><br><span style="font-size: 18px">Insert (String table,string nullcolumnhack,contentvalues values)</span><br><span style="font-size: 18px"></span></p></p><p><p></p></p><p><p><br><span style="font-size: 18px">Delete a record</span><br><span style="font-size: 18px">Delete (String table,string whereclause,string[] Whereargs)</span><br><span style="font-size: 18px"></span></p></p><p><p></p></p><p><p><br><span style="font-size: 18px">Query a record</span><br><span style="font-size: 18px">Query (String table,string[] columns,string selection,string[] selectionargs,string groupby,string having,String )</span><br><span style="font-size: 18px"></span></p></p><p><p></p></p><p><p><br><span style="font-size: 18px">Modify a record</span><br><span style="font-size: 18px">Update (String table,contentvalues values,string whereclause,string[] Whereargs)</span><br><span style="font-size: 18px"></span></p></p><p><p></p></p><p><p><br><span style="font-size: 18px">Execute an SQL statement</span><br><span style="font-size: 18px">Execsql (String sql)</span><br><span style="font-size: 18px"></span></p></p><p><p></p></p><p><p><br><span style="font-size: 18px">Close the database</span><br><span style="font-size: 18px">Close ()</span></p></p><p><p></p></p><p><p></p></p><p><p><br><br><span style="font-size: 18px"><strong>In the process of using sqlite, we have to use an auxiliary class ———— Sqliteopenhelper</strong></span><br><br><span style="font-size: 18px">Sqliteopenhelper is a helper class for sqlitedatabase that manages the creation of databases and the updating of versions. It is generally established that a class inherits it and implements its OnCreate and Onupgrade methods.</span><br><span style="font-size: 18px"></span><br><span style="font-size: 18px">Sqliteopenhelper provides common methods, method names, and methods that indicate meaning:</span><br><span style="font-size: 18px"></span><br><span style="font-size: 18px">Constructs a method, typically passing a parameter to create a database name, version, etc.</span><br><span style="font-size: 18px">Sqliteopenhelper (Context context,string name,sqlitedatabase.cursorfactory factory,int Version)</span><br><span style="font-size: 18px"></span></p></p><p><p></p></p><p><p><br><span style="font-size: 18px">Called when a database is created</span><br><span style="font-size: 18px">OnCreate (sqlitedatabase Db)</span><br><span style="font-size: 18px"></span></p></p><p><p></p></p><p><p><br><span style="font-size: 18px">Called when the version is updated</span><br><span style="font-size: 18px">Onupgrade (sqlitedatabase db,int oldversion, int Newversion)</span><br><span style="font-size: 18px"></span></p></p><p><p></p></p><p><p><br><span style="font-size: 18px">Create or open a read-only database</span><br><span style="font-size: 18px">Getreadabledatabase ()</span></p></p><p><p></p></p><p><p></p></p><p><p><br><span style="font-size: 18px">Create or open a Read-write database</span><br><span style="font-size: 18px">Getwritabledatabase ()</span></p></p><p><p> </p></p><p><p><br><br></p></p><p><p><span style="font-size: 16px"> <span style="text-decoration: underline; color: #ff0000">Source</span> : http://download.csdn.net/detail/littyzhon/9839805</span></p></p><p><p></p></p><p><p>Android sqlit Database Learning</p></p></span>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service