C 簡單呼叫Sqlite函式(一)

2021-07-27 06:00:34 字數 2467 閱讀 3170

sqlite是遵守acid的關聯式資料庫管理系統,它包含在乙個相對小的c庫中。

它是d.richardhipp建立的共有領域專案。

sqlite官方原始碼不支援加密解密,資料庫檔案中的資料以全明文的形式存

在。不過作者顯然仔細考慮過這個問題,留下了實現加密的介面。

sqlite api簡介:

1、 其中sqlite3_open自然是開啟乙個sqlite資料庫(當該資料庫不存

在時會自動建立乙個空庫),相應的sqlite3_close是關閉資料庫。

2、 sqlite3_stmt可以認為是物件級別的sql語句。對於頻繁使用的sql,

可通過sqlite3_prepare_v2方法將其加工成stmt可以獲得效能提公升。

stmt用完後需要呼叫相應的sqlite3_finalize方法來釋放底層資料

庫資源。

3、 sqlite支援有引數的sql語句,支援?、?123、:name、@name、$name

等多種引數寫法。支援一系列的sqlite3_bind_type方法來進行引數

繫結。4、  可以通過sqlite3_step方法來執行乙個準備好的stmt語句。成功執

行時:對於無返回值的語句返回sqlite_done;對於有返回值的語句

返回sqlite_row,可通過迭代sqlite3_step方法來訪問結果的每一行。

sqlite3_column_type方法可以取得結果行某列的具體值。

*/#include

#include

#include

#include "main.h"

#include

// 第一步:導入庫和標頭檔案

#include "sqlite3.h"

#ifdef _debug

#pragma comment(lib,"sqlite3.lib")

#endif

using namespace std;

sqlite3 * pdb; // sqlite3為乙個結構體

typedef struct tagmsg_item

tagmsg_item& operator=(const tagmsg_item& rmsgitem)

public:

unsigned long uluid;

std::string

szfromuser;

std::string   sztouser;

std::string

strdatetime;

std::string

strmsg;

}msg_item,*pmsg_item;

typedef std::listlistmsgitem; 

listmsgitem m_listmsg;

/*函式名:createtable(sqlite3 *db)

功能:建立一張資料表table

*/int createtable(sqlite3 *db)

return 0;}/*

函式名:insertdb()

功能:建立一張資料表table

*/int insertdb()

return 0;

}static int callback(void *notused, int argc, char **argv, char **azcolname)  

std::cout<< "\n";  

return 0;  

} int selectdb()

else  

return 0;  

}void main()

//  第三步:建立乙個資料表

res = createtable(pdb);

if (res)

//  第四步:實現基本的「增、刪、改、查」的功能

res = insertdb();//增

res = selectdb();//查

#if 0

//  日期提取

ctime time;

std::string date("2016-12-03 12:12:10");

time = cstringtodate(date);

//  檢查cstring是不是純數字

#endif

//5. 最後,我們需要關閉資料庫的鏈結,使用 sqlite3_close(phandle->psqlite); 語句。

對函式的簡單呼叫

1.實現乙個函式,列印乘法口訣表,口訣表的行數和列數自己指定,輸入9,輸出9 9口訣表,輸出12,輸出12 12的乘法口訣表。define crt secure no warnings 1 include int main int a 0 scanf d a void table int x tab...

反射簡單呼叫

1 class program 2 構造函式呼叫有參建構函式 16object obj constructor.invoke new object 17 methodinfo method1 type.getmethod sayname 得到無參公有方法 18 methodinfo method2 ...

SQLite簡介,C 呼叫SQLite

當我們用到海量資料時一般會用oracle,sql server,db2,sybase,mysql等資料庫來儲存和管理資料.如果只是程式中需要儲存少量資料的話直接整到登錄檔裡,或者儲存到乙個xml檔案中.那如果資料量剛好不多不少,用oracle這樣的資料庫有點小題大作,沒有必要.有個xml儲存的話訪問...