Sqlite嵌入式資料庫講解

來源:互聯網
上載者:User

標籤:

在電腦系統中,儲存資料的方式一般有兩種:
1. 普通檔案方式
2. 資料庫方式


相比於普通檔案方式,使用資料庫來管理大批量資料具有更高的效率與安全性。


資料庫系統一般由3個部分構成
1. 資料庫
2. 資料庫管理系統
3. 資料庫訪問應用

 

在資料庫中,資料都是以表的形式存在。表與表之間,可能存在關聯關係

 

 

SQL(結構化查詢語言 (SQL)),是一種特殊的程式設計語言,用於訪問資料庫中的數據。

1. 建立一張表
create table tabname(col1 type1 [not null] [primary key],col2 type2 [notnull],..)


2. 向表中插入資料
insert into table1(field1,field2) values(value1,value2)


3. 從表中查詢需要的資料
select * from table1 where field1 like ’%value1%’


4. 刪除表中的資料
delete from table1 where 範圍

 

Sqlite資料庫訪問應用程式

#include <stdio.h> #include <sqlite3.h>    static int callback(void *NotUsed, int argc, char **argv, char **azColName) {       int i;      for(i=0; i<argc; i++)      {          printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");      }      printf("\n");     return 0;}    int main(int argc, char **argv) {      sqlite3 *db;      char *zErrMsg = 0;      int rc;           if( argc!=3 )      {          fprintf(stderr, "Usage: %s DATABASE SQL-STATEMENT\n", argv[0]);      }           /*開啟資料庫*/     rc = sqlite3_open(argv[1], &db);           if( rc )      {         fprintf(stderr, "Can‘t open database: %s\n", sqlite3_errmsg(db));         sqlite3_close(db);      }           /*執行sql語言*/     rc = sqlite3_exec(db, argv[2], callback, 0, &zErrMsg);           if( rc!=SQLITE_OK )      {          fprintf(stderr, "SQL error: %s\n", zErrMsg);      }           /*關閉資料庫*/     sqlite3_close(db);      return 0; }

 

Sqlite嵌入式資料庫講解

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.