This is an extension for the SQLite Embeddable SQL Database Engine. SQLite is a C library that implements an embeddable SQL database engine. Programs that link with the SQLite library can have SQL database access without running a separate RDBMS process.
SQLite is not a client library used to connect to a big database server. SQLite is the server. The SQLite library reads and writes directly to and from the database files on disk.
在 vc工程目录下 设置 Link L/对象类模块 为 sqlite3.lib
c/c++ 分类 precompiled header 选择不使用预补偿页眉
首先将SQLITE3的七个文件放在和vc工程文件同一目录下
在工程中加入 CppSQLite3DB.cpp和CppSQLite3DB.h文件
# include "CppSQLite3.h"
extern CppSQLite3DB db;/////数据库对象
remove("c:\\test.db");
db.open("c:\\test.db");///打开数据库文件
建立表格:
db.execDML("create table Customer(CustomerName char(50), RoomNumber int, CustomerId int, ComeTime int,Money int);");
db.execDML("create table Room(RoomNumber int, RoomPrice int, RoomState char[20]);");
db.execDML("create table Manager(ManagerName char[20],PassWord int);");
插入数据:
string szCmd;
string szName = m_data1;
szCmd = "insert into Customer values(" ;
szCmd +="'";
szCmd +=szName;
szCmd +="'";
szCmd +=",";
sprintf(a,"%d",m_data2);
szCmd += a;
szCmd += ",";
sprintf(b,"%d",m_data3);
szCmd +=b;
szCmd +=",";
sprintf(c,"%d",m_data4);
szCmd += c;
szCmd += ",";
sprintf(d,"%d",m_data5);
szCmd += d;
szCmd += ");";
db.execDML(szCmd.c_str());/////////////插入SQL语句
MessageBox("提交成功,请继续!");
更新数据:
char k[20];//提交后更新房间信息
string szCkd;
szCkd="update Room set RoomState = 'notnull' where RoomNumber=";
sprintf(k,"%d",m_data2);
szCkd +=k;
szCkd +=";";
db.execDML(szCkd.c_str()); //////////插入SQL语句
查询数据:
CppSQLite3Query q = db.execQuery("select * from Customer;");
while(!q.eof()){
UpdateData(true);
if(m_data1==q.getIntField(1))
{
s.m_data1=q.getStringField(0);
s.m_data2=q.getIntField(1);
s.m_data3=q.getIntField(2);
s.m_data4=q.getFloatField(3);
s.m_data5=q.getIntField(4);
s.DoModal();
UpdateData(false);
break;}
q.nextRow();
if(q.eof()==true)
MessageBox("本旅馆无该房间!");
}
删除数据:
char a[20];
sprintf(a,"%d",m_data2);
string szCmd;
szCmd="delete from Room where RoomNumber =" ;
szCmd+=a;
szCmd+=";";
int b=0;
b=db.execDML(szCmd.c_str());
if(b==0)
MessageBox("操作错误,没有该房间信息");
else
MessageBox("删除房间信息成功");
以上为SQLITE3在窗体交互下简易实现几种数据库基本功能的详细说明!
14 个解决方案
#1
一些实际代码:
Customer 模块:
#include "CppSQLite3.h"
extern CppSQLite3DB db;/////数据库对象
void Customer::OnSubmit()
{ UpdateData(true);
CppSQLite3Query p = db.execQuery("select * from Room");///数据库查询对象
while(!p.eof())
{ if(m_data2==p.getIntField(0))
{
if(strcmp("notnull",p.getStringField(2))==0)
{ MessageBox("该房间已有人住!"); break;}
else{
char a[20],b[20],c[20],d[20]; //////提交信息
if(m_data1==" "||m_data2==0||m_data3==0||m_data4==0)
MessageBox("打*号者不能为空!!!");
else{
string szCmd;
string szName = m_data1;
szCmd = "insert into Customer values(" ;
szCmd +="'";
szCmd +=szName;
szCmd +="'";
szCmd +=",";
sprintf(a,"%d",m_data2);
szCmd += a;
szCmd += ",";
sprintf(b,"%d",m_data3);
szCmd +=b;
szCmd +=",";
sprintf(c,"%d",m_data4);
szCmd += c;
szCmd += ",";
sprintf(d,"%d",m_data5);
szCmd += d;
szCmd += ");"
db.execDML(szCmd.c_str());
MessageBox("提交成功,请继续!");
break;
}
}
}
p.nextRow();
if(p.eof()==true)
{ MessageBox("本旅馆无该房间");}
}
}
void Customer::OnUpdata()
{ UpdateData(true);
char k[20];//提交后更新房间信息
string szCkd;
szCkd="update Room set RoomState = 'notnull' where RoomNumber=";
sprintf(k,"%d",m_data2);
szCkd +=k;
szCkd +=";";
db.execDML(szCkd.c_str());
}
void Customer::OnTimer(UINT nIDEvent) /////////记时函数,提醒管理员客人费用到期
{
if(nIDEvent==0)
{
MoneyForAllDay +=MoneyForOneDay;
if(MoneyForAllDay>=m_data5)
{
KillTimer(0);
sprintf(Room,"%d号客人预交费用已经到期!",m_data2);
MessageBox(Room);
}
}
CDialog::OnTimer(nIDEvent);
}
void Customer::OnCheckTime() ////查询用户费用及住天数提交给记时函数
{
CppSQLite3Query p = db.execQuery("select * from Room;");
while(!p.eof()){
if(m_data2==p.getIntField(0))
{
MoneyForOneDay=p.getIntField(1);
break;
}
p.nextRow();
}
SetTimer(0,20000,NULL);
}
void Information::CheckRoomNumber() /////////按房间号码查询顾客信息
{ SubmitCustomer s;
CppSQLite3Query q = db.execQuery("select * from Customer;");
while(!q.eof()){
UpdateData(true);
if(m_data1==q.getIntField(1))
{
s.m_data1=q.getStringField(0);
s.m_data2=q.getIntField(1);
s.m_data3=q.getIntField(2);
s.m_data4=q.getFloatField(3);
s.m_data5=q.getIntField(4);
s.DoModal();
UpdateData(false);
break;}
q.nextRow();
if(q.eof()==true)
MessageBox("本旅馆无该房间!");
}
void Information::CheckCustomerId() 按客人id查询客人信息
{
SubmitCustomer s;
CppSQLite3Query q = db.execQuery("select * from Customer;");
while(!q.eof()){
UpdateData(true);
if(m_data2==q.getIntField(2))
{
s.m_data1=q.getStringField(0);
s.m_data2=q.getIntField(1);
s.m_data3=q.getIntField(2);
s.m_data4=q.getFloatField(3);
s.m_data5=q.getIntField(4);
s.DoModal();
UpdateData(false);
break;}
q.nextRow();
if(q.eof()==true)
MessageBox("本旅馆无该客人!");
}
}
void CheckMoney::OnCompute()
{
double Data,a; int b; int MoneyForOneDay;
CppSQLite3Query q = db.execQuery("select * from Customer;");////用户数据库查询对象
CppSQLite3Query p = db.execQuery("select * from Room;");/////房间数据库查询对象
UpdateData(true);
while(!q.eof()){
if(m_data3==q.getIntField(1))
{
a=q.getFloatField(3);
b=q.getIntField(4);
Data=m_data1-a;
break;
}
q.nextRow();
if(q.eof()==true) MessageBox("无该客人记录");
}
while(!p.eof()){
if(m_data3==p.getIntField(0))
{
MoneyForOneDay=p.getIntField(1);
break;
}
p.nextRow();
if(p.eof()==true) MessageBox("无该客房记录");
}
m_data2=Data*MoneyForOneDay-b;
UpdateData(false);
}
void CheckMoney::OnUpdata() /////结帐后数据更新
{
UpdateData(true);
char k[20];
string szCkd
szCkd="update Room set RoomState = 'null' where RoomNumber=";
sprintf(k,"%d",m_data3);
szCkd +=k;
szCkd +=";";
db.execDML(szCkd.c_str());
}
Room 模块:
#include "CppSQLite3.h"
extern CppSQLite3DB db;
void Room::OnSubmit()
{
UpdateData(true);
if(m_data1==0||m_data2==0)
MessageBox("打*号者不能为空!!!");
else{
char a[20],b[20];
string szCmd;
string szName =m_data3;
szCmd = "insert into Room values(" ;
sprintf(a,"%d",m_data1);
szCmd += a;
szCmd += ",";
sprintf(b,"%d",m_data2);
szCmd += b;
szCmd += ",";
szCmd +="'";
szCmd +=szName;
szCmd +="'";
szCmd +=");";
db.execDML(szCmd.c_str());
MessageBox("提交成功,请继续!");
}
}
void Room::OnCheck()
{ SubmitRoom s;
CppSQLite3Query p = db.execQuery("select * from Room;");
while(!p.eof())
{ UpdateData(true);
if(m_data1==p.getIntField(0))
{
s.m_data1=p.getIntField(0);
s.m_data2=p.getIntField(1);
s.m_data3=p.getStringField(2);
s.DoModal();
UpdateData(false);
break;
}
p.nextRow();
}
if(p.eof()==true) MessageBox("本旅馆无该房间");
}
void Room::OnDelete()
{
char a[20];
UpdateData(true);
sprintf(a,"%d",m_data2);
string szCmd;
szCmd="delete from Room where RoomNumber =" ;
szCmd+=a;
szCmd+=";";
int b=0;
b=db.execDML(szCmd.c_str());
if(b==0)
MessageBox("操作错误,没有该房间信息");
else
MessageBox("删除房间信息成功");
}
void Room::OnUpdate()
{
UpdateData(true);
if(m_data1==0||m_data2==0)
MessageBox("打*号者不能为空!!!");
else{
char a[20],b[20];
string szCmd;
string szName =m_data3;
szCmd = "insert into Room values(" ;
sprintf(a,"%d",m_data1);
szCmd += a;
szCmd += ",";
sprintf(b,"%d",m_data2);
szCmd += b;
szCmd += ",";
szCmd +="'";
szCmd +=szName;
szCmd +="'";
szCmd +=");";
db.execDML(szCmd.c_str());
MessageBox("提交成功,请继续!");
}
}
Manager 模块:
#include "CppSQLite3.h"
extern CppSQLite3DB db;
void Manger::Login()
{
UpdateData(true);
Main s;
CppSQLite3Query q = db.execQuery("select * from Manager;");
int a=q.getIntField(1);
if(m_data1=="Administrator"&&m_data2==a)
{ CDialog::OnCancel(); s.DoModal();}
else
MessageBox("用户名或密码不正确,请重新输入");
}
void Manger::OnIdSubmit()
{
CppSQLite3Query q = db.execQuery("select * from Manager;");
int a=q.getIntField(1);
UpdateData(true);
if(m_data1!=a)
MessageBox("原始密码输入错误!");
else{
if(m_data2!=m_data3)
MessageBox("两次密码输入不一致,请重新输入!");
}
}
void Manger::OnUpdate()
{ UpdateData(true);
char k[20];
string szCkd;
szCkd="update Manager set PassWord =" ;
sprintf(k,"%d",m_data3);
szCkd +=k;
szCkd +="where ManagerName = 'Administrator';";
db.execDML(szCkd.c_str());
MessageBox("密码更新成功!");
CDialog::OnCancel();
}
Customer 模块:
#include "CppSQLite3.h"
extern CppSQLite3DB db;/////数据库对象
void Customer::OnSubmit()
{ UpdateData(true);
CppSQLite3Query p = db.execQuery("select * from Room");///数据库查询对象
while(!p.eof())
{ if(m_data2==p.getIntField(0))
{
if(strcmp("notnull",p.getStringField(2))==0)
{ MessageBox("该房间已有人住!"); break;}
else{
char a[20],b[20],c[20],d[20]; //////提交信息
if(m_data1==" "||m_data2==0||m_data3==0||m_data4==0)
MessageBox("打*号者不能为空!!!");
else{
string szCmd;
string szName = m_data1;
szCmd = "insert into Customer values(" ;
szCmd +="'";
szCmd +=szName;
szCmd +="'";
szCmd +=",";
sprintf(a,"%d",m_data2);
szCmd += a;
szCmd += ",";
sprintf(b,"%d",m_data3);
szCmd +=b;
szCmd +=",";
sprintf(c,"%d",m_data4);
szCmd += c;
szCmd += ",";
sprintf(d,"%d",m_data5);
szCmd += d;
szCmd += ");"
db.execDML(szCmd.c_str());
MessageBox("提交成功,请继续!");
break;
}
}
}
p.nextRow();
if(p.eof()==true)
{ MessageBox("本旅馆无该房间");}
}
}
void Customer::OnUpdata()
{ UpdateData(true);
char k[20];//提交后更新房间信息
string szCkd;
szCkd="update Room set RoomState = 'notnull' where RoomNumber=";
sprintf(k,"%d",m_data2);
szCkd +=k;
szCkd +=";";
db.execDML(szCkd.c_str());
}
void Customer::OnTimer(UINT nIDEvent) /////////记时函数,提醒管理员客人费用到期
{
if(nIDEvent==0)
{
MoneyForAllDay +=MoneyForOneDay;
if(MoneyForAllDay>=m_data5)
{
KillTimer(0);
sprintf(Room,"%d号客人预交费用已经到期!",m_data2);
MessageBox(Room);
}
}
CDialog::OnTimer(nIDEvent);
}
void Customer::OnCheckTime() ////查询用户费用及住天数提交给记时函数
{
CppSQLite3Query p = db.execQuery("select * from Room;");
while(!p.eof()){
if(m_data2==p.getIntField(0))
{
MoneyForOneDay=p.getIntField(1);
break;
}
p.nextRow();
}
SetTimer(0,20000,NULL);
}
void Information::CheckRoomNumber() /////////按房间号码查询顾客信息
{ SubmitCustomer s;
CppSQLite3Query q = db.execQuery("select * from Customer;");
while(!q.eof()){
UpdateData(true);
if(m_data1==q.getIntField(1))
{
s.m_data1=q.getStringField(0);
s.m_data2=q.getIntField(1);
s.m_data3=q.getIntField(2);
s.m_data4=q.getFloatField(3);
s.m_data5=q.getIntField(4);
s.DoModal();
UpdateData(false);
break;}
q.nextRow();
if(q.eof()==true)
MessageBox("本旅馆无该房间!");
}
void Information::CheckCustomerId() 按客人id查询客人信息
{
SubmitCustomer s;
CppSQLite3Query q = db.execQuery("select * from Customer;");
while(!q.eof()){
UpdateData(true);
if(m_data2==q.getIntField(2))
{
s.m_data1=q.getStringField(0);
s.m_data2=q.getIntField(1);
s.m_data3=q.getIntField(2);
s.m_data4=q.getFloatField(3);
s.m_data5=q.getIntField(4);
s.DoModal();
UpdateData(false);
break;}
q.nextRow();
if(q.eof()==true)
MessageBox("本旅馆无该客人!");
}
}
void CheckMoney::OnCompute()
{
double Data,a; int b; int MoneyForOneDay;
CppSQLite3Query q = db.execQuery("select * from Customer;");////用户数据库查询对象
CppSQLite3Query p = db.execQuery("select * from Room;");/////房间数据库查询对象
UpdateData(true);
while(!q.eof()){
if(m_data3==q.getIntField(1))
{
a=q.getFloatField(3);
b=q.getIntField(4);
Data=m_data1-a;
break;
}
q.nextRow();
if(q.eof()==true) MessageBox("无该客人记录");
}
while(!p.eof()){
if(m_data3==p.getIntField(0))
{
MoneyForOneDay=p.getIntField(1);
break;
}
p.nextRow();
if(p.eof()==true) MessageBox("无该客房记录");
}
m_data2=Data*MoneyForOneDay-b;
UpdateData(false);
}
void CheckMoney::OnUpdata() /////结帐后数据更新
{
UpdateData(true);
char k[20];
string szCkd
szCkd="update Room set RoomState = 'null' where RoomNumber=";
sprintf(k,"%d",m_data3);
szCkd +=k;
szCkd +=";";
db.execDML(szCkd.c_str());
}
Room 模块:
#include "CppSQLite3.h"
extern CppSQLite3DB db;
void Room::OnSubmit()
{
UpdateData(true);
if(m_data1==0||m_data2==0)
MessageBox("打*号者不能为空!!!");
else{
char a[20],b[20];
string szCmd;
string szName =m_data3;
szCmd = "insert into Room values(" ;
sprintf(a,"%d",m_data1);
szCmd += a;
szCmd += ",";
sprintf(b,"%d",m_data2);
szCmd += b;
szCmd += ",";
szCmd +="'";
szCmd +=szName;
szCmd +="'";
szCmd +=");";
db.execDML(szCmd.c_str());
MessageBox("提交成功,请继续!");
}
}
void Room::OnCheck()
{ SubmitRoom s;
CppSQLite3Query p = db.execQuery("select * from Room;");
while(!p.eof())
{ UpdateData(true);
if(m_data1==p.getIntField(0))
{
s.m_data1=p.getIntField(0);
s.m_data2=p.getIntField(1);
s.m_data3=p.getStringField(2);
s.DoModal();
UpdateData(false);
break;
}
p.nextRow();
}
if(p.eof()==true) MessageBox("本旅馆无该房间");
}
void Room::OnDelete()
{
char a[20];
UpdateData(true);
sprintf(a,"%d",m_data2);
string szCmd;
szCmd="delete from Room where RoomNumber =" ;
szCmd+=a;
szCmd+=";";
int b=0;
b=db.execDML(szCmd.c_str());
if(b==0)
MessageBox("操作错误,没有该房间信息");
else
MessageBox("删除房间信息成功");
}
void Room::OnUpdate()
{
UpdateData(true);
if(m_data1==0||m_data2==0)
MessageBox("打*号者不能为空!!!");
else{
char a[20],b[20];
string szCmd;
string szName =m_data3;
szCmd = "insert into Room values(" ;
sprintf(a,"%d",m_data1);
szCmd += a;
szCmd += ",";
sprintf(b,"%d",m_data2);
szCmd += b;
szCmd += ",";
szCmd +="'";
szCmd +=szName;
szCmd +="'";
szCmd +=");";
db.execDML(szCmd.c_str());
MessageBox("提交成功,请继续!");
}
}
Manager 模块:
#include "CppSQLite3.h"
extern CppSQLite3DB db;
void Manger::Login()
{
UpdateData(true);
Main s;
CppSQLite3Query q = db.execQuery("select * from Manager;");
int a=q.getIntField(1);
if(m_data1=="Administrator"&&m_data2==a)
{ CDialog::OnCancel(); s.DoModal();}
else
MessageBox("用户名或密码不正确,请重新输入");
}
void Manger::OnIdSubmit()
{
CppSQLite3Query q = db.execQuery("select * from Manager;");
int a=q.getIntField(1);
UpdateData(true);
if(m_data1!=a)
MessageBox("原始密码输入错误!");
else{
if(m_data2!=m_data3)
MessageBox("两次密码输入不一致,请重新输入!");
}
}
void Manger::OnUpdate()
{ UpdateData(true);
char k[20];
string szCkd;
szCkd="update Manager set PassWord =" ;
sprintf(k,"%d",m_data3);
szCkd +=k;
szCkd +="where ManagerName = 'Administrator';";
db.execDML(szCkd.c_str());
MessageBox("密码更新成功!");
CDialog::OnCancel();
}
#2
赫赫,顶一下
#3
呵呵 无人问津 新的东西面对现实的时候就是这么残酷!
#4
你的问题是什么??
#5
我怎么没有在http://www.sqlite.org上找到SQLITE3的七个文件和CppSQLite3DB.cpp和CppSQLite3DB.h和sqlite3.lib???
企盼回复!!!
企盼回复!!!
#6
高人,我也想在vc上用sqlite3,但现在找到的dll压缩包中并没有.h文件,用源代码压缩包中的.h文件,编译是说dll错误。
我下载的dll压缩包是sqlitedll-3_0_8.zip
我下载的源代码压缩包是sqlite-source-3_0_8.zip
都是在http://www.sqlite.org/download.html上下载的。
恳请高人指点:vc中怎么用啊?
我下载的dll压缩包是sqlitedll-3_0_8.zip
我下载的源代码压缩包是sqlite-source-3_0_8.zip
都是在http://www.sqlite.org/download.html上下载的。
恳请高人指点:vc中怎么用啊?
#7
我在vc中new了一个win32 dynamic-Link Library;然后把sqlite-source-3_0_8.zip中所有的.c和.h文件加入这个项目中,编译后产生了dll文件,但没有找到lib文件,怎么样才能生成lib文件啊?
#8
这个是使用了 Sqlite 的一个 C++ wrap
不sqlite 的 C函数接口封装在了C++类中,使用更加方便。
编译后,需要把 sqlite3.dll 放在 exe文件同一个目录,或系统目录中。
不sqlite 的 C函数接口封装在了C++类中,使用更加方便。
编译后,需要把 sqlite3.dll 放在 exe文件同一个目录,或系统目录中。
#9
哈哈,原来是用static library,不要选中precompiled header ,谢谢楼主。多多交流。
#10
Sqlite 的一个 C++ wrap
我也有下载过一个,不过不会用。
我又有个问题:sqlite.org的quickstart中这样几行语句,可是查询结果的记录集呢?
rc = sqlite3_exec(db, argv[2], callback, 0, &zErrMsg);
if( rc!=SQLITE_OK ){
fprintf(stderr, "SQL error: %s\n", zErrMsg);
}
搂主的语句很清楚,可惜我用的是3.0.8的,没有这样的定义记录集的。
CppSQLite3Query q = db.execQuery("select * from Customer;");
while(!q.eof()){.............
我也有下载过一个,不过不会用。
我又有个问题:sqlite.org的quickstart中这样几行语句,可是查询结果的记录集呢?
rc = sqlite3_exec(db, argv[2], callback, 0, &zErrMsg);
if( rc!=SQLITE_OK ){
fprintf(stderr, "SQL error: %s\n", zErrMsg);
}
搂主的语句很清楚,可惜我用的是3.0.8的,没有这样的定义记录集的。
CppSQLite3Query q = db.execQuery("select * from Customer;");
while(!q.eof()){.............
#11
大虾,下面那个网站实在太慢了,无法下载。已经下载到的,能不能分享一下啊。
http://www.codeproject.com/database/CppSQLite/CppSQLite_3_1_demo_and_src.zip
punch@eastday.com
http://www.codeproject.com/database/CppSQLite/CppSQLite_3_1_demo_and_src.zip
punch@eastday.com
#12
各位 我的qq是49294399
#13
直接把sqlite的代码放到你的工程中就好了, 这个东西确实比较强大, 是和中小企业开发, 小型数据库软件:比如XX管理系统开发, 我们一直都用它:)
#14
嘿嘿, liixixi() 同学说的好啊。
#1
一些实际代码:
Customer 模块:
#include "CppSQLite3.h"
extern CppSQLite3DB db;/////数据库对象
void Customer::OnSubmit()
{ UpdateData(true);
CppSQLite3Query p = db.execQuery("select * from Room");///数据库查询对象
while(!p.eof())
{ if(m_data2==p.getIntField(0))
{
if(strcmp("notnull",p.getStringField(2))==0)
{ MessageBox("该房间已有人住!"); break;}
else{
char a[20],b[20],c[20],d[20]; //////提交信息
if(m_data1==" "||m_data2==0||m_data3==0||m_data4==0)
MessageBox("打*号者不能为空!!!");
else{
string szCmd;
string szName = m_data1;
szCmd = "insert into Customer values(" ;
szCmd +="'";
szCmd +=szName;
szCmd +="'";
szCmd +=",";
sprintf(a,"%d",m_data2);
szCmd += a;
szCmd += ",";
sprintf(b,"%d",m_data3);
szCmd +=b;
szCmd +=",";
sprintf(c,"%d",m_data4);
szCmd += c;
szCmd += ",";
sprintf(d,"%d",m_data5);
szCmd += d;
szCmd += ");"
db.execDML(szCmd.c_str());
MessageBox("提交成功,请继续!");
break;
}
}
}
p.nextRow();
if(p.eof()==true)
{ MessageBox("本旅馆无该房间");}
}
}
void Customer::OnUpdata()
{ UpdateData(true);
char k[20];//提交后更新房间信息
string szCkd;
szCkd="update Room set RoomState = 'notnull' where RoomNumber=";
sprintf(k,"%d",m_data2);
szCkd +=k;
szCkd +=";";
db.execDML(szCkd.c_str());
}
void Customer::OnTimer(UINT nIDEvent) /////////记时函数,提醒管理员客人费用到期
{
if(nIDEvent==0)
{
MoneyForAllDay +=MoneyForOneDay;
if(MoneyForAllDay>=m_data5)
{
KillTimer(0);
sprintf(Room,"%d号客人预交费用已经到期!",m_data2);
MessageBox(Room);
}
}
CDialog::OnTimer(nIDEvent);
}
void Customer::OnCheckTime() ////查询用户费用及住天数提交给记时函数
{
CppSQLite3Query p = db.execQuery("select * from Room;");
while(!p.eof()){
if(m_data2==p.getIntField(0))
{
MoneyForOneDay=p.getIntField(1);
break;
}
p.nextRow();
}
SetTimer(0,20000,NULL);
}
void Information::CheckRoomNumber() /////////按房间号码查询顾客信息
{ SubmitCustomer s;
CppSQLite3Query q = db.execQuery("select * from Customer;");
while(!q.eof()){
UpdateData(true);
if(m_data1==q.getIntField(1))
{
s.m_data1=q.getStringField(0);
s.m_data2=q.getIntField(1);
s.m_data3=q.getIntField(2);
s.m_data4=q.getFloatField(3);
s.m_data5=q.getIntField(4);
s.DoModal();
UpdateData(false);
break;}
q.nextRow();
if(q.eof()==true)
MessageBox("本旅馆无该房间!");
}
void Information::CheckCustomerId() 按客人id查询客人信息
{
SubmitCustomer s;
CppSQLite3Query q = db.execQuery("select * from Customer;");
while(!q.eof()){
UpdateData(true);
if(m_data2==q.getIntField(2))
{
s.m_data1=q.getStringField(0);
s.m_data2=q.getIntField(1);
s.m_data3=q.getIntField(2);
s.m_data4=q.getFloatField(3);
s.m_data5=q.getIntField(4);
s.DoModal();
UpdateData(false);
break;}
q.nextRow();
if(q.eof()==true)
MessageBox("本旅馆无该客人!");
}
}
void CheckMoney::OnCompute()
{
double Data,a; int b; int MoneyForOneDay;
CppSQLite3Query q = db.execQuery("select * from Customer;");////用户数据库查询对象
CppSQLite3Query p = db.execQuery("select * from Room;");/////房间数据库查询对象
UpdateData(true);
while(!q.eof()){
if(m_data3==q.getIntField(1))
{
a=q.getFloatField(3);
b=q.getIntField(4);
Data=m_data1-a;
break;
}
q.nextRow();
if(q.eof()==true) MessageBox("无该客人记录");
}
while(!p.eof()){
if(m_data3==p.getIntField(0))
{
MoneyForOneDay=p.getIntField(1);
break;
}
p.nextRow();
if(p.eof()==true) MessageBox("无该客房记录");
}
m_data2=Data*MoneyForOneDay-b;
UpdateData(false);
}
void CheckMoney::OnUpdata() /////结帐后数据更新
{
UpdateData(true);
char k[20];
string szCkd
szCkd="update Room set RoomState = 'null' where RoomNumber=";
sprintf(k,"%d",m_data3);
szCkd +=k;
szCkd +=";";
db.execDML(szCkd.c_str());
}
Room 模块:
#include "CppSQLite3.h"
extern CppSQLite3DB db;
void Room::OnSubmit()
{
UpdateData(true);
if(m_data1==0||m_data2==0)
MessageBox("打*号者不能为空!!!");
else{
char a[20],b[20];
string szCmd;
string szName =m_data3;
szCmd = "insert into Room values(" ;
sprintf(a,"%d",m_data1);
szCmd += a;
szCmd += ",";
sprintf(b,"%d",m_data2);
szCmd += b;
szCmd += ",";
szCmd +="'";
szCmd +=szName;
szCmd +="'";
szCmd +=");";
db.execDML(szCmd.c_str());
MessageBox("提交成功,请继续!");
}
}
void Room::OnCheck()
{ SubmitRoom s;
CppSQLite3Query p = db.execQuery("select * from Room;");
while(!p.eof())
{ UpdateData(true);
if(m_data1==p.getIntField(0))
{
s.m_data1=p.getIntField(0);
s.m_data2=p.getIntField(1);
s.m_data3=p.getStringField(2);
s.DoModal();
UpdateData(false);
break;
}
p.nextRow();
}
if(p.eof()==true) MessageBox("本旅馆无该房间");
}
void Room::OnDelete()
{
char a[20];
UpdateData(true);
sprintf(a,"%d",m_data2);
string szCmd;
szCmd="delete from Room where RoomNumber =" ;
szCmd+=a;
szCmd+=";";
int b=0;
b=db.execDML(szCmd.c_str());
if(b==0)
MessageBox("操作错误,没有该房间信息");
else
MessageBox("删除房间信息成功");
}
void Room::OnUpdate()
{
UpdateData(true);
if(m_data1==0||m_data2==0)
MessageBox("打*号者不能为空!!!");
else{
char a[20],b[20];
string szCmd;
string szName =m_data3;
szCmd = "insert into Room values(" ;
sprintf(a,"%d",m_data1);
szCmd += a;
szCmd += ",";
sprintf(b,"%d",m_data2);
szCmd += b;
szCmd += ",";
szCmd +="'";
szCmd +=szName;
szCmd +="'";
szCmd +=");";
db.execDML(szCmd.c_str());
MessageBox("提交成功,请继续!");
}
}
Manager 模块:
#include "CppSQLite3.h"
extern CppSQLite3DB db;
void Manger::Login()
{
UpdateData(true);
Main s;
CppSQLite3Query q = db.execQuery("select * from Manager;");
int a=q.getIntField(1);
if(m_data1=="Administrator"&&m_data2==a)
{ CDialog::OnCancel(); s.DoModal();}
else
MessageBox("用户名或密码不正确,请重新输入");
}
void Manger::OnIdSubmit()
{
CppSQLite3Query q = db.execQuery("select * from Manager;");
int a=q.getIntField(1);
UpdateData(true);
if(m_data1!=a)
MessageBox("原始密码输入错误!");
else{
if(m_data2!=m_data3)
MessageBox("两次密码输入不一致,请重新输入!");
}
}
void Manger::OnUpdate()
{ UpdateData(true);
char k[20];
string szCkd;
szCkd="update Manager set PassWord =" ;
sprintf(k,"%d",m_data3);
szCkd +=k;
szCkd +="where ManagerName = 'Administrator';";
db.execDML(szCkd.c_str());
MessageBox("密码更新成功!");
CDialog::OnCancel();
}
Customer 模块:
#include "CppSQLite3.h"
extern CppSQLite3DB db;/////数据库对象
void Customer::OnSubmit()
{ UpdateData(true);
CppSQLite3Query p = db.execQuery("select * from Room");///数据库查询对象
while(!p.eof())
{ if(m_data2==p.getIntField(0))
{
if(strcmp("notnull",p.getStringField(2))==0)
{ MessageBox("该房间已有人住!"); break;}
else{
char a[20],b[20],c[20],d[20]; //////提交信息
if(m_data1==" "||m_data2==0||m_data3==0||m_data4==0)
MessageBox("打*号者不能为空!!!");
else{
string szCmd;
string szName = m_data1;
szCmd = "insert into Customer values(" ;
szCmd +="'";
szCmd +=szName;
szCmd +="'";
szCmd +=",";
sprintf(a,"%d",m_data2);
szCmd += a;
szCmd += ",";
sprintf(b,"%d",m_data3);
szCmd +=b;
szCmd +=",";
sprintf(c,"%d",m_data4);
szCmd += c;
szCmd += ",";
sprintf(d,"%d",m_data5);
szCmd += d;
szCmd += ");"
db.execDML(szCmd.c_str());
MessageBox("提交成功,请继续!");
break;
}
}
}
p.nextRow();
if(p.eof()==true)
{ MessageBox("本旅馆无该房间");}
}
}
void Customer::OnUpdata()
{ UpdateData(true);
char k[20];//提交后更新房间信息
string szCkd;
szCkd="update Room set RoomState = 'notnull' where RoomNumber=";
sprintf(k,"%d",m_data2);
szCkd +=k;
szCkd +=";";
db.execDML(szCkd.c_str());
}
void Customer::OnTimer(UINT nIDEvent) /////////记时函数,提醒管理员客人费用到期
{
if(nIDEvent==0)
{
MoneyForAllDay +=MoneyForOneDay;
if(MoneyForAllDay>=m_data5)
{
KillTimer(0);
sprintf(Room,"%d号客人预交费用已经到期!",m_data2);
MessageBox(Room);
}
}
CDialog::OnTimer(nIDEvent);
}
void Customer::OnCheckTime() ////查询用户费用及住天数提交给记时函数
{
CppSQLite3Query p = db.execQuery("select * from Room;");
while(!p.eof()){
if(m_data2==p.getIntField(0))
{
MoneyForOneDay=p.getIntField(1);
break;
}
p.nextRow();
}
SetTimer(0,20000,NULL);
}
void Information::CheckRoomNumber() /////////按房间号码查询顾客信息
{ SubmitCustomer s;
CppSQLite3Query q = db.execQuery("select * from Customer;");
while(!q.eof()){
UpdateData(true);
if(m_data1==q.getIntField(1))
{
s.m_data1=q.getStringField(0);
s.m_data2=q.getIntField(1);
s.m_data3=q.getIntField(2);
s.m_data4=q.getFloatField(3);
s.m_data5=q.getIntField(4);
s.DoModal();
UpdateData(false);
break;}
q.nextRow();
if(q.eof()==true)
MessageBox("本旅馆无该房间!");
}
void Information::CheckCustomerId() 按客人id查询客人信息
{
SubmitCustomer s;
CppSQLite3Query q = db.execQuery("select * from Customer;");
while(!q.eof()){
UpdateData(true);
if(m_data2==q.getIntField(2))
{
s.m_data1=q.getStringField(0);
s.m_data2=q.getIntField(1);
s.m_data3=q.getIntField(2);
s.m_data4=q.getFloatField(3);
s.m_data5=q.getIntField(4);
s.DoModal();
UpdateData(false);
break;}
q.nextRow();
if(q.eof()==true)
MessageBox("本旅馆无该客人!");
}
}
void CheckMoney::OnCompute()
{
double Data,a; int b; int MoneyForOneDay;
CppSQLite3Query q = db.execQuery("select * from Customer;");////用户数据库查询对象
CppSQLite3Query p = db.execQuery("select * from Room;");/////房间数据库查询对象
UpdateData(true);
while(!q.eof()){
if(m_data3==q.getIntField(1))
{
a=q.getFloatField(3);
b=q.getIntField(4);
Data=m_data1-a;
break;
}
q.nextRow();
if(q.eof()==true) MessageBox("无该客人记录");
}
while(!p.eof()){
if(m_data3==p.getIntField(0))
{
MoneyForOneDay=p.getIntField(1);
break;
}
p.nextRow();
if(p.eof()==true) MessageBox("无该客房记录");
}
m_data2=Data*MoneyForOneDay-b;
UpdateData(false);
}
void CheckMoney::OnUpdata() /////结帐后数据更新
{
UpdateData(true);
char k[20];
string szCkd
szCkd="update Room set RoomState = 'null' where RoomNumber=";
sprintf(k,"%d",m_data3);
szCkd +=k;
szCkd +=";";
db.execDML(szCkd.c_str());
}
Room 模块:
#include "CppSQLite3.h"
extern CppSQLite3DB db;
void Room::OnSubmit()
{
UpdateData(true);
if(m_data1==0||m_data2==0)
MessageBox("打*号者不能为空!!!");
else{
char a[20],b[20];
string szCmd;
string szName =m_data3;
szCmd = "insert into Room values(" ;
sprintf(a,"%d",m_data1);
szCmd += a;
szCmd += ",";
sprintf(b,"%d",m_data2);
szCmd += b;
szCmd += ",";
szCmd +="'";
szCmd +=szName;
szCmd +="'";
szCmd +=");";
db.execDML(szCmd.c_str());
MessageBox("提交成功,请继续!");
}
}
void Room::OnCheck()
{ SubmitRoom s;
CppSQLite3Query p = db.execQuery("select * from Room;");
while(!p.eof())
{ UpdateData(true);
if(m_data1==p.getIntField(0))
{
s.m_data1=p.getIntField(0);
s.m_data2=p.getIntField(1);
s.m_data3=p.getStringField(2);
s.DoModal();
UpdateData(false);
break;
}
p.nextRow();
}
if(p.eof()==true) MessageBox("本旅馆无该房间");
}
void Room::OnDelete()
{
char a[20];
UpdateData(true);
sprintf(a,"%d",m_data2);
string szCmd;
szCmd="delete from Room where RoomNumber =" ;
szCmd+=a;
szCmd+=";";
int b=0;
b=db.execDML(szCmd.c_str());
if(b==0)
MessageBox("操作错误,没有该房间信息");
else
MessageBox("删除房间信息成功");
}
void Room::OnUpdate()
{
UpdateData(true);
if(m_data1==0||m_data2==0)
MessageBox("打*号者不能为空!!!");
else{
char a[20],b[20];
string szCmd;
string szName =m_data3;
szCmd = "insert into Room values(" ;
sprintf(a,"%d",m_data1);
szCmd += a;
szCmd += ",";
sprintf(b,"%d",m_data2);
szCmd += b;
szCmd += ",";
szCmd +="'";
szCmd +=szName;
szCmd +="'";
szCmd +=");";
db.execDML(szCmd.c_str());
MessageBox("提交成功,请继续!");
}
}
Manager 模块:
#include "CppSQLite3.h"
extern CppSQLite3DB db;
void Manger::Login()
{
UpdateData(true);
Main s;
CppSQLite3Query q = db.execQuery("select * from Manager;");
int a=q.getIntField(1);
if(m_data1=="Administrator"&&m_data2==a)
{ CDialog::OnCancel(); s.DoModal();}
else
MessageBox("用户名或密码不正确,请重新输入");
}
void Manger::OnIdSubmit()
{
CppSQLite3Query q = db.execQuery("select * from Manager;");
int a=q.getIntField(1);
UpdateData(true);
if(m_data1!=a)
MessageBox("原始密码输入错误!");
else{
if(m_data2!=m_data3)
MessageBox("两次密码输入不一致,请重新输入!");
}
}
void Manger::OnUpdate()
{ UpdateData(true);
char k[20];
string szCkd;
szCkd="update Manager set PassWord =" ;
sprintf(k,"%d",m_data3);
szCkd +=k;
szCkd +="where ManagerName = 'Administrator';";
db.execDML(szCkd.c_str());
MessageBox("密码更新成功!");
CDialog::OnCancel();
}
#2
赫赫,顶一下
#3
呵呵 无人问津 新的东西面对现实的时候就是这么残酷!
#4
你的问题是什么??
#5
我怎么没有在http://www.sqlite.org上找到SQLITE3的七个文件和CppSQLite3DB.cpp和CppSQLite3DB.h和sqlite3.lib???
企盼回复!!!
企盼回复!!!
#6
高人,我也想在vc上用sqlite3,但现在找到的dll压缩包中并没有.h文件,用源代码压缩包中的.h文件,编译是说dll错误。
我下载的dll压缩包是sqlitedll-3_0_8.zip
我下载的源代码压缩包是sqlite-source-3_0_8.zip
都是在http://www.sqlite.org/download.html上下载的。
恳请高人指点:vc中怎么用啊?
我下载的dll压缩包是sqlitedll-3_0_8.zip
我下载的源代码压缩包是sqlite-source-3_0_8.zip
都是在http://www.sqlite.org/download.html上下载的。
恳请高人指点:vc中怎么用啊?
#7
我在vc中new了一个win32 dynamic-Link Library;然后把sqlite-source-3_0_8.zip中所有的.c和.h文件加入这个项目中,编译后产生了dll文件,但没有找到lib文件,怎么样才能生成lib文件啊?
#8
这个是使用了 Sqlite 的一个 C++ wrap
不sqlite 的 C函数接口封装在了C++类中,使用更加方便。
编译后,需要把 sqlite3.dll 放在 exe文件同一个目录,或系统目录中。
不sqlite 的 C函数接口封装在了C++类中,使用更加方便。
编译后,需要把 sqlite3.dll 放在 exe文件同一个目录,或系统目录中。
#9
哈哈,原来是用static library,不要选中precompiled header ,谢谢楼主。多多交流。
#10
Sqlite 的一个 C++ wrap
我也有下载过一个,不过不会用。
我又有个问题:sqlite.org的quickstart中这样几行语句,可是查询结果的记录集呢?
rc = sqlite3_exec(db, argv[2], callback, 0, &zErrMsg);
if( rc!=SQLITE_OK ){
fprintf(stderr, "SQL error: %s\n", zErrMsg);
}
搂主的语句很清楚,可惜我用的是3.0.8的,没有这样的定义记录集的。
CppSQLite3Query q = db.execQuery("select * from Customer;");
while(!q.eof()){.............
我也有下载过一个,不过不会用。
我又有个问题:sqlite.org的quickstart中这样几行语句,可是查询结果的记录集呢?
rc = sqlite3_exec(db, argv[2], callback, 0, &zErrMsg);
if( rc!=SQLITE_OK ){
fprintf(stderr, "SQL error: %s\n", zErrMsg);
}
搂主的语句很清楚,可惜我用的是3.0.8的,没有这样的定义记录集的。
CppSQLite3Query q = db.execQuery("select * from Customer;");
while(!q.eof()){.............
#11
大虾,下面那个网站实在太慢了,无法下载。已经下载到的,能不能分享一下啊。
http://www.codeproject.com/database/CppSQLite/CppSQLite_3_1_demo_and_src.zip
punch@eastday.com
http://www.codeproject.com/database/CppSQLite/CppSQLite_3_1_demo_and_src.zip
punch@eastday.com
#12
各位 我的qq是49294399
#13
直接把sqlite的代码放到你的工程中就好了, 这个东西确实比较强大, 是和中小企业开发, 小型数据库软件:比如XX管理系统开发, 我们一直都用它:)
#14
嘿嘿, liixixi() 同学说的好啊。