Ubuntu under wxwidgets student apartment management programming, sqlite3 usage (MySQL database), form, below is the section add and remove features, other features can contact me.

Source: Internet
Author: User
Tags strcmp wxwidgets

The following is an increase and deletion of information management for student apartments, for informational purposes only.
void Stumanaframe::onadd (Wxcommandevent &event)
{
Add student ' s dormitory infomation
Sqlite3 *db=null;
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 is not 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 establishing a database



1. Install sqlite3 Online First, try the command installation
[Email protected]:~$ sudo apt-get install sqlite3
2. Test will appear after successful installation
[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. Find the path to the 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. Examples of specific sqlite3 operations
[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. Examples of specific sqlite3 operations
[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), name char (1) Not Null,dormitoryid char (a) not Null,phone Char 3));
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]ntu-virtual-machine:~/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$

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.