IOS SQLite3 usage and tips

Source: Internet
Author: User

The client for iOS applications generally stores data in SQLite3. The following describes the data types supported by iOS SQLite3 and their relationships. Most databases use static strict type systems. The column type is specified when creating a table. SQLite uses a dynamic type system. The column type is determined by the value.

Data Types of iOS SQLite3

 
 
  1. NULL:NULLvalue 

Integer: The value belongs to the signedinteger type. The value can be 1, 2, 3, 4, 6, or 8 bytes.

  • REAL: floating point type
  • TEXT: character type stored in UTF-8, UTF-16BEorUTF-16LE Encoding
  • BLOB: binary data

Other data types

The Integerprimarykey column is an exception ??

  • Boolean Type: SQLite does not define the boolean type, but stores boolean values by Integer, 0 (false), 1 (true)

Dateandtime type

The date and time types are not defined in SQLite. the date and time can be stored in TEXT, REAL, or orINTEGER.

TEXT: stored as a string ("YYYY-MM-DDHH: MM: SS. SSS ").

 
 
  1. REAL:asJuliandaynumbers,thenumberofdayssincenooninGreenwichonNovember24,4714B.C.accordingtotheprolepticGregoriancalendar.   
  2.    
  3. INTEGER:asUnixTime,thenumberofsecondssince1970-01-0100:00:00UTC. 

SQLiteTypeAffinity (type detection)

The type of the value used for automatic detection. The following lists how Affinity determines the type rules.

(1) If the type declaration contains int, use INTEGERaffinity.

(2) If the type declaration contains "CHAR", "CLOB", or "TEXT", use Textaffinity

(3) If the type declaration contains BLOB or the type is not specified, use affinityNONE

(4) If the type declaration contains "REAL", "FLOA", or "DOUB", use REALaffinity

(5) otherwise use Numericaffinity

Type comparison NULL

Memcmp function prototype

 
 
  1. intmemcmp(constvoid*ptr1,constvoid*ptr2,size_tnum); 

Compares the two pointers to the first num bytes in the memory.

Type conversion before comparison

L (INTEGER, REALorNUMERIC) and (TEXTorNONE), the TEXT and NONE will be converted to NUMERIC

When lTEXT and NONE are compared, NONE is converted to TEXT

Compare other cases directly.

Summary: The content of the iOS SQLite3 type system has been introduced. I hope you can learn the operation content of iOS SQLite to help you.

Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.