Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

SQLite lesson 3 use examples

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

1 Open the database file

Sqlite3* m_db = NULL

Int ret = sqlite3_open_v2 ("test.db", & db, SQLITE_OPEN_READWRITE, NULL)

If (ret! = SQLITE_OK)

{

Return

}

2 if the table does not exist, create the table

Char szCreateUserDataSql [1024] = "create table if not exists tb_user (id INTEGER,\)

Type INTEGER,\

Kind INTEGER) "

3 create a unique primary key ID

Char szCreateUserDataSql [1024] = "create table if not exists tb_user (id INTEGER PRIMARY KEY AUTOINCREMENT,\)

Type INTEGER,\

Kind INTEGER) "

4 query

Char szSql [1024] = {0}

Sprintf (szSql, "select distinct * from tb_test")

Sqlite3_stmt* stmt = NULL

Sqlite3_prepare (m_db, szSql,-1, & stmt, 0)

While (sqlite3_step (stmt) = = SQLITE_ROW)

{

Const unsigned char* szPOIName = sqlite3_column_text (stmt, 0)

Char szName [128] = {0}

If (szPOIName)

{

Sprintf (szName, "% s", szPOIName)

}

Int kx = sqlite3_column_int (stmt, 3)

Float x = sqlite3_column_double (stmt, 5)

}

Sqlite3_finalize (stmt)

5 get the error message of sql execution failure

Char* errMsg = NULL

Char* szSql = "select * from address"

NRet = sqlite3_exec (pDB, szSql, NULL, NULL, & errMsg)

If (nRet! = SQLITE_OK)

{

Cout

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report