日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > linux >内容正文

linux

Linux下,sqlite简单实例

發(fā)布時間:2023/12/10 linux 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Linux下,sqlite简单实例 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
#include "stdlib.h"
#include "stdio.h"

#include "sqlite3.h"

int main()
{
? ? ?charcSql[1024] = {0};
?? ?sqlite3*pSql = NULL;
?? ?char *pError= NULL;
?? ?int i = 0, j= 0;
?? ?char**ppTableData = NULL;
?? ?int nRow =0, nColumn = 0;
?? ?int pos =0;

?? //打開數(shù)據(jù)庫
???sqlite3_open("server.db",&pSql);

?? //如果userInfo表不存在,則創(chuàng)建一個。
???sprintf(cSql, "create table if not existsuserInfo"
??????"("
??????"cUserName varchar(32) not null primarykey,"//用戶名 關(guān)鍵字 不能為空
??????"cUserPwd varchar(32) not null,"//用戶密碼 不能為空
??????"nUserPower interger default 1,"//用戶權(quán)限 默認(rèn)為1
??????"cCreateTime varchar(32)default(datetime('now','localtime')),"//創(chuàng)建時間?默認(rèn)為當(dāng)前本地時間
??????"cModifyTime varchar(32)default(datetime('now','localtime')),"//最后一次修改時間
??????"cLoginTime varchar(32)default(datetime('now','localtime')),"//最后一次登錄時間
??????"cDescribe varchar(256) default('nodescribe')"//用戶描述信息
??????")");

???if(sqlite3_exec(pSql, cSql, 0, 0,&pError) != SQLITE_OK)
?? ?{
??????printf("(%s)\r\n", pError);
?? ?}

??? //刪除一項
???sprintf(cSql, "delete from userInfo where cUserName='%s'","admin");
???if(sqlite3_exec(pSql, cSql, 0, 0, &pError) !=SQLITE_OK)
??? {
??????printf("(%s)\r\n", pError);
??? }

??? //插入一項UserName = admin, cUserPwd = password
???sprintf(cSql, "insert into userInfo (cUserName,cUserPwd) values ('%s', '%s')", "admin", "password");
???if(sqlite3_exec(pSql, cSql, 0, 0,&pError) != SQLITE_OK)
?? ?{
??????printf("(%s)\r\n", pError);
?? ?}

?? //修改一項
???sprintf(cSql, "update userInfo set cUserPwd='%s', nUserPower=%d,cDescribe='%s' where cUserName='%s'", "88888888", 2, "super user","admin");
???if(sqlite3_exec(pSql, cSql, 0, 0, &pError) !=SQLITE_OK)
??? {
??????printf("(%s)\r\n", pError);
?????? return-1;
??? }

?? //查找所有項,并顯示
???sprintf(cSql, "select * from userInfo");
???if(sqlite3_exec(pSql, cSql, 0, 0,&pError) != SQLITE_OK)
?? ?{
??????printf("(%s)\r\n", pError);
?? ?}
?? ?else
?? ?{
?????//獲取選擇的項目
??????sqlite3_get_table(pSql, cSql,&ppTableData, &nRow,&nColumn, &pError);
??????printf("nRow??= %d, nColumn = %d\r\n", nRow, nColumn);
??????pos = nColumn;
??????for(i = 0;i < nRow;i++)
??????{
?????????for(j = 0;j < nColumn;j++)
?????????{
????????????printf("i %d, j %d, value = %s\r\n", i, j,ppTableData[pos++]);
?????????}
??????}
????? //釋放空間
??????sqlite3_free_table(ppTableData);
?? ?}

?? //查找cUserName = admin,cUserPwd = password的項
???sprintf(cSql, "select * from userInfo wherecUserName='admin' and cUserPwd='password'");
???if(sqlite3_exec(pSql, cSql, 0, 0,&pError) != SQLITE_OK)
?? ?{
??????printf("(%s)\r\n", pError);
?? ?}
?? ?else
?? ?{
??????sqlite3_get_table(pSql, cSql,&ppTableData, &nRow,&nColumn, &pError);
??????if(nRow <= 0)
??????{
?????????printf("no find cUserName='admin' andcUserPwd='password'\r\n");
??????}
??????else
??????{
?????????printf("find success\r\n");
?????????pos = nColumn;
?????????for(i = 0;i < nRow;i++)
?????????{
????????????for(j = 0;j < nColumn;j++)
????????????{
???????????????printf("i %d, j %d, value = %s\r\n", i, j,ppTableData[pos++]);
????????????}
?????????}
??????}
??????sqlite3_free_table(ppTableData);
?? ?}

?? //關(guān)閉數(shù)據(jù)庫
???sqlite3_close(pSql);

?? ?return0;
}

總結(jié)

以上是生活随笔為你收集整理的Linux下,sqlite简单实例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。