wxwidgets mysql_Ubuntu下wxWidgets学生公寓管理编程,sqlite3的用法(mysql数据库),窗体,下面是部分添加和删除功能,其他功能可以联系我。。...

int flag;

char *errmsg;

flag = sqlite3_open("./stuinfo.db",&db);

if(SQLITE_OK != flag)

{

wxLogMessage("Database connect failed!");

exit(-1);

}

char id[20], name[20], dorid[20], phone[20], qq[20];

strcpy(id, m_id->GetValue().mb_str());

strcpy(name, m_name->GetValue().mb_str());

strcpy(dorid, m_dormitoryid->GetValue().mb_str());

strcpy(phone, m_phone->GetValue().mb_str());

strcpy(qq, m_qq->GetValue().mb_str());

if(strcmp("", id) == 0)

{

wxLogMessage("the stu‘s id can not be null");

return;

}

if(strcmp("", name) == 0)

{

wxLogMessage("the stu‘s name can not be null");

return;

}

char st[500];

sprintf(st, "insert into stu values(‘%s‘, ‘%s‘, ‘%s‘, ‘%s‘, ‘%s‘);",

id, name, dorid, phone, qq);

sqlite3_exec(db,st,NULL,NULL,&errmsg );

wxLogMessage(wxString(errmsg));

sqlite3_close(db);

}

void StuManaFrame::OnDelete(wxCommandEvent &event)

{

//delete student‘s dormitory infomation

sqlite3 *db=NULL;

int flag;

char *errmsg;

char stuid[20];

flag = sqlite3_open("./stuinfo.db",&db);

if(SQLITE_OK != flag)

{

wxLogMessage("Database connect failed!");

exit(-1);

}

strcpy(stuid, m_deleteid->GetValue().mb_str());

if(strcmp("", stuid) == 1)

{

wxLogMessage("the stu‘s id deleted can not be null");

return;

}

char *sql=sqlite3_mprintf("delete from stu where id =‘%s‘;",stuid);

if(sqlite3_exec(db,sql,NULL,NULL,&errmsg) != SQLITE_OK)

{

wxLogMessage("Error");

wxLogMessage(errmsg);

return;

}

else

{

wxLogMessage("delete success!!");

return;

}

}

sqlite3建立数据库

1.先在线安装sqlite3,试用一下命令安装

[email protected]:~$ sudo apt-get install sqlite3

2.安装成功后测试会出现

[email protected]:~$ sqlite3

SQLite version 3.7.9 2011-11-01 00:52:41

Enter ".help" for instructions

Enter SQL statements terminated with a ";"

sqlite> .exit

3.查找sqlite3的路径

[email protected]:~$ which sqlite3

/usr/bin/sqlite3

[email protected]:~$ ls

core              OSlab1    Public                           Videos

Desktop           OSlab2    Qt                               vmwaretools

Documents         OSlab3    sqlite-amalgamation-3080403      wx

Downloads         OSlab4    sqlite-amalgamation-3080403.zip  wx3.0

examples.desktop  OSlab5    StuMana                          wxlab

Music             Pictures  Templates

4.具体sqlite3操作的实例

[email protected]:~$ mkdir mydb

[email protected]:~$ cd mydb

[email protected]:~/mydb$ ls

[email protected]:~/mydb$ sqlite3 stu.db

SQLite version 3.7.9 2011-11-01 00:52:41

Enter ".help" for instructions

Enter SQL statements terminated with a ";"

sqlite> create table stu(sno int primary key, sname text not null, sage int);

sqlite> insert into stu(1, ‘Lisi‘, 20);

Error: near "1": syntax error

sqlite> insert into stu values(1, ‘lisi‘, 20);

sqlite> insert into stu values(2, ‘zhangsan‘, 18);

sqlite> select * from stu;

1|lisi|20

2|zhangsan|18

sqlite> .exit

[email protected]:~/mydb$ ls

stu.db

5.具体sqlite3操作的实例

[email protected]:~$ cd StuMana

[email protected]:~/StuMana$ sqlite3 stuinfo.db

SQLite version 3.7.9 2011-11-01 00:52:41

Enter ".help" for instructions

Enter SQL statements terminated with a ";"

sqlite> create table stuinfo (id char(10),name char(15) not null,dormitoryid char(20) not null,phone char(11),qq char(13));

sqlite> insert into stuinfo values(‘1115115247‘,‘LiYa‘,‘15#501‘,‘15530061772‘,‘614100932‘);

sqlite> insert into stuinfo values(‘1115115276‘,‘ZhangAihua‘,‘15#424‘,‘18330000036‘,‘627100056‘);

sqlite> select * from stuinfo;

1115115247|LiYa|15#501|15500761772|614100932

1115115276|ZhangAihua|15#424|18330000036|627100056

sqlite> .exit

[email protected]:~/StuMana$ ls

bin           stuinfo.db      StuMana.depend   WxWizFrame.fbp

GUIFrame.cpp  StuManaApp.cpp  StuMana.layout   WxWizFrame.fbp.bak

GUIFrame.h    StuManaApp.h    StuManaMain.cpp

obj           StuMana.cbp     StuManaMain.h

[email protected]:~/StuMana$

原文:http://blog.csdn.net/u012388338/article/details/27211769

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值