SQLITE3 is a little experience in VCMFC

xiaoxiao2021-03-06  89

Introduction to SQLite:

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.

Set the LINK L / Object class module in the VC engineering directory for SQLite3.lib

C / C classification precompiled header Select Do not use pre-compensation header

First put the seven files of SQLITE3 in the same directory of the VC project file

Add cppsqlite3db.cpp and cppsqlite3db.h files in the project

# include "cppsqlite3.h"

Extern CPPSQLITE3DB DB; / Database Object

Remove ("c: //test.db");

DB.Open ("c: //test.db"); /// Open Database File

Create a form:

Db.execdml ("Create Table Custom (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);");

Insert data:

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 ()); / insert SQL statement

MessageBox ("Submit success, please continue!");

Update data: char k [20]; // Submit the room information

String szckd;

Szckd = "Update Room Set Roomstate = 'Notnull' Where Roomnumber =";

Sprintf (k, "% d", m_data2);

SZCKD = K;

SZCKD = ";";

db.execdml (szckd.c_str ()); // Insert SQL statement

Query data:

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 ("This hotel has no room!");

}

delete data:

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 ("Operation error, no room information");

Else

MessageBox ("Delete Room Information Success");

The above is a brief description of the basic functions of several databases under the interaction of SQLITE3!

转载请注明原文地址:https://www.9cbs.com/read-95928.html

New Post(0)