加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

SQLite3使用

发布时间:2020-12-12 23:51:40 所属栏目:百科 来源:网络整理
导读:SQLite3使用 www.sqlite.org下载shell把exe放置C:WINDOWSsystem32下 创建数据库user sqlite3 user 创建表tbl create table tbl(name char(10),age smallint,score float); 查询表 .table 插入数据 insert into tbl values('yanggang',24,98); insert into

SQLite3使用

www.sqlite.org下载shell把exe放置C:WINDOWSsystem32下

创建数据库user

sqlite3 user

创建表tbl

create table tbl(name char(10),age smallint,score float);

查询表

.table

插入数据

insert into tbl values('yanggang',24,98);

insert into tbl values('sunboy',20,78.5);

查询数据

select * from tbl;

修改显示模式

.mode column


sqlite3 表里插入系统时间(时间戳)

CREATE TABLE time([ID] INTEGER PRIMARY KEY,[IDCardNo] VARCHAR (50),[CreatedTime] TimeStamp NOT NULL DEFAULT (datetime('now','localtime')));


sqlite3 *db = 0;

  sqlite3_stmt * stmt;

  sqlite3_open("./test.db",&db);

  char* zErrMsg = 0;

  sqlite3_prepare(db,"select * from admin;",-1,&stmt,0);

  int rc = sqlite3_step(stmt);

  while( rc == SQLITE_ROW )

  {

  CString type = sqlite3_column_text(stmt,51); font-family:宋体; font-size:14px; line-height:28px">   CString adminpassword = sqlite3_column_text(stmt,1);

  MessageBox(type);

  MessageBox(adminpassword);

  rc=sqlite3_step(stmt);

  }

  sqlite3_finalize(stmt);

  sqlite3_close(db)

sqlite3取数据库数据

sqlite3 * db = NULL;
char * err_msg = NULL;
sqlite3_stmt * stmt;

char *sql = sqlite3_mprintf("select * from ALLID"); //获得表内所有记录
sqlite3_prepare(db,sql,0);
int rc = sqlite3_step(stmt);
m_report.DeleteAllItems();
while( rc == SQLITE_ROW ) // 逐行取出需要的数据
{



CString id = sqlite3_column_text(stmt,1);
CString setname = sqlite3_column_text(stmt,2);
//MessageBox(id);
m_report.InsertItem(m_report.GetItemCount(),id);
m_report.SetItemText(m_report.GetItemCount()-1,1,setname);
//if(DataReport.Mid(ring+3,1)=="*") m_report.SetItemText(m_report.GetItemCount()-1,3,DataReport.Mid(ring+4,2));
//if(DataReport.Mid(ring+6,4,DataReport.Mid(ring+7,2));
//m_report.SetItemText(m_report.GetItemCount()-1,5,time);


rc=sqlite3_step(stmt);
}
sqlite3_finalize(stmt);
sqlite3_close(db);


sqlite3存入中文数据navicat premium显示

(1)写入:

char str [256] = "实验";
WCHAR* strA;
int i= MultiByteToWideChar ( CP_ACP,(char*) str,NULL,0);
strA = new WCHAR[i];
MultiByteToWideChar ( CP_ACP,( char * ) str,strA,i);
i= WideCharToMultiByte(CP_UTF8,NULL);
char *strB=new char[i]; // 即所需的类型
WideCharToMultiByte (CP_UTF8,strB,i,NULL);

(2)读出到mfc

CString setname = sqlite3_column_text(stmt,2); char *str =(LPSTR)(LPCTSTR)setname; // char str [256] = "实验"; int len = ::MultiByteToWideChar(CP_UTF8,str,0); vector<wchar_t> unicode(len); MultiByteToWideChar(CP_UTF8,&unicode[0],len); setname=CString(&unicode[0]);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读