WxWidgets student apartment management programming in Ubuntu and sqlite3 usage (mysql data _ MySQL

Source: Internet
Author: User
WxWidgets student apartment management programming under Ubuntu, sqlite3 usage (mysql database), form, below is part of the add and delete... Ubuntu

The following is the addition and deletion of student apartment information management for your reference 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 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 ');",
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 database creation


1. first install sqlite3 online and try the command to install it.
Ubuntu @ ubuntu-virtual-machine :~ $ Sudo apt-get install sqlite3
2. after the installation is successful, the test will show
Ubuntu @ ubuntu-virtual-machine :~ $ Sqlite3
SQLite version 3.7.9 2011-11-01 00:52:41
Enter ". help" for instructions
Enter SQL statements terminated with ";"
Sqlite>. exit
3. find the sqlite3 path
Ubuntu @ ubuntu-virtual-machine :~ $ Which sqlite3
/Usr/bin/sqlite3
Ubuntu @ ubuntu-virtual-machine :~ $ 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. instance for specific sqlite3 operations
Ubuntu @ ubuntu-virtual-machine :~ $ Mkdir mydb
Ubuntu @ ubuntu-virtual-machine :~ $ Cd mydb
Ubuntu @ ubuntu-virtual-machine :~ /Mydb $ ls
Ubuntu @ ubuntu-virtual-machine :~ /Mydb $ sqlite3 stu. db
SQLite version 3.7.9 2011-11-01 00:52:41
Enter ". help" for instructions
Enter SQL statements terminated with ";"
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, 'hangsan', 18 );
Sqlite> select * from stu;
1 | lisi | 20
2 | zhangsan | 18
Sqlite>. exit
Ubuntu @ ubuntu-virtual-machine :~ /Mydb $ ls
Stu. db
5. instance for specific sqlite3 operations
Ubuntu @ ubuntu-virtual-machine :~ $ Cd StuMana
Ubuntu @ ubuntu-virtual-machine :~ /StuMana $ sqlite3 stuinfo. db
SQLite version 3.7.9 2011-11-01 00:52:41
Enter ". help" for instructions
Enter SQL statements terminated with ";"
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 ('000000', 'liya ', '15 # 000000', '000000', '000000 ');
Sqlite> insert into stuinfo values ('20170101', 'hangaihua', '15 # 20170101', '20160301', '20160301 ');
Sqlite> select * from stuinfo;
1115115247 | LiYa | 15 #501 | 15500761772 | 614100932
1115115276 | ZhangAihua | 15 #424 | 18330000036 | 627100056
Sqlite>. exit
Ubuntu @ ubuntu-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
Ubuntu @ ubuntu-virtual-machine :~ /StuMana $

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.