Symbian database DEMO code

Source: Internet
Author: User
Tags table definition

 

Add: Library EDBMS. Lib

Dbbase. h
// DBMS interface to databases

/*
Dbbase. h
*/

# Ifndef dbbase_h
# Define dbbase_h

# Include <d32dbms. h>
# Include <f32file. h>
# Include <s32file. h>
# Include <badesca. h>

// Class rdbstoredatabase;
// Class RFS;
// Class rdbdatabase;
// Class rdbrowset;

Class cdbbase
{
Public:
Void constructl ();

~ Cdbbase ();

Public: // New Function
Tint executesql (tdesc & asql );

Void selectsql (tdesc & asql, rdbview * aview );

Void adddatatotablemaill (tdesc & asql, cdescarray & aparamarray );

Void adddatatotablemaill ();
// Void adddatatotableaccount ();

PRIVATE:
// Create database
Void makedatabasel ();

Void opendatabasel ();

Void createtablel ();

Void createtablemaill (rdbdatabase & adatabase );

Void createtableaccountl (rdbdatabase & adatabase );

Void makedatabasel (const tdesc & adatabasefilename );

Void createtablel (rdbdatabase & adatabase );



PRIVATE:

Tparse idatabasefilename;

RFS ifssession;

Rdbstoredatabase idatabase;

Cfilestore * istore;
};

# Endif

// End of File

Dbbase. cpp
// DBMS interface to databases

/*
Dbbase. cpp
*/

# Include "dbbase. H"

Void cdbbase: constructl ()
{
_ Partition (kdbname, "mail_mt.db ");
_ Partition (kcepoc32exdata, "C: // epoc32ex/Data //");

Tint fsret = ifssession. Connect (); // start a file session
If (fsret! = Kerrnone)
{
User: Leave (fsret );
}

Ifssession. parse (kdbname, kcepoc32exdata, idatabasefilename );

If (ifssession. isvalidname (kcepoc32exdata) = efalse)
{
Ifssession. mkdirall (kcepoc32exdata );
}

Trapd (error, opendatabasel ());

If (error! = Kerrnone)
{
If (error = kerrnotfound)
{
Makedatabasel ();
}
}
}

Cdbbase ::~ Cdbbase ()
{
// Idatabase. Close ();
Ifssession. Close (); // close the file session
}

Void cdbbase: opendatabasel ()
{
Istore = cfilestore: openlc (ifssession, idatabasefilename. fullname (), efileread | efilewrite );
Idatabase. openl (istore, istore-> root ());
Idatabase. Close ();
// Pop store
Cleanupstack: popanddestroy ();
}

Void cdbbase: makedatabasel ()
{
Makedatabasel (idatabasefilename. fullname ());
}

Void cdbbase: makedatabasel (const tdesc & adatabasefilename)
{
// Construct a file store object-the file to contain
// Database replaces any existing file of the same name.
Istore = cpermanentfilestore: replacelc (ifssession, adatabasefilename, efileread | efilewrite );
// Complete file store Creation
Istore-> settypel (istore-> layout ());

// Create a database in the store
// Rdbstoredatabase;
Tstreamid id = idatabase. createl (istore );
// Nb. The database won't be closed on Failure
// Cleanup can be done; more usually database objects
// Are not automatic variables.

// Keep Database ID as root of store
Istore-> setrootl (ID );

// Complete database creation by commiting the store
Istore-> commitl ();

Createtablel ();
// Close the database
Idatabase. Close ();

// Do not commit store: database has taken control of COMMIT
Cleanupstack: popanddestroy ();
}

Void cdbbase: createtablel ()
{
Createtablel (idatabase );
}

Void cdbbase: createtablel (rdbdatabase & adatabase)
{
Createtablemaill (adatabase );

Createtableaccountl (adatabase );
}

Void cdbbase: createtablemaill (rdbdatabase & adatabase)
{
_ Partition (kcolid, "d_mail_id ");
_ Partition (kcolfrom, "from_mail ");
_ Partition (kcoltitle, "title_mail ");
_ Contents (kcolcontent, "content_mail ");
_ Partition (kcoldate, "date_mail ");
_ Partition (kcolread, "is_read ");
_ Partition (kcoldelete, "is_delete ");
_ Partition (kcolget, "is_get ");
_ Partition (ktable, "d_mail ");

// Create a table definition
Cdbcolset * columns = cdbcolset: newlc ();

Tdbcol d_mail_id (kcolid, edbcolint32 );
D_mail_id.iattributes = tdbcol: eautoincrement;
Columns-> addl (d_mail_id );

Tdbcol from_mail (kcolfrom, edbcoltext, 60 );
Columns-> addl (from_mail );

Tdbcol title_mail (kcoltitle, edbcoltext, 60 );
Columns-> addl (title_mail );

Tdbcol content_mail (kcolcontent, edbcoltext );
Columns-> addl (content_mail );

Tdbcol date_mail (kcoldate, edbcoltext, 20 );
Columns-> addl (date_mail );

Tdbcol is_read (kcolread, edbcolbit );
Columns-> addl (is_read );

Tdbcol is_delete (kcoldelete, edbcolbit );
Columns-> addl (is_delete );

Tdbcol is_get (kcolget, edbcolbit );
Columns-> addl (is_get );

User: leaveiferror (adatabase. createtable (ktable, * columns ));

// Cleanup the column set
Cleanupstack: popanddestroy ();
}

Void cdbbase: createtableaccountl (rdbdatabase & adatabase)
{
_ Partition (kcolid, "d_account_id ");
_ Revoke (kcolreceivertype, "receiver_type ");
_ Partition (kcolsendtype, "send_type ");
_ Collect (kcolreceiverserver, "receiver_server ");
_ Partition (kcolsendserver, "send_server ");
_ Partition (kcoluser, "user_name ");
_ Partition (kcolpass, "user_pass ");
_ Partition (ktable, "d_account ");

Cdbcolset * columns = cdbcolset: newlc ();

Tdbcol d_account_id (kcolid, edbcolint32 );
D_account_id.iattributes = tdbcol: eautoincrement;
Columns-> addl (d_account_id );

Tdbcol receiver_type (kcolreceivertype, edbcoltext, 20 );
Columns-> addl (receiver_type );

Tdbcol send_type (kcolsendtype, edbcoltext, 20 );
Columns-> addl (send_type );

Tdbcol receiver_server (kcolreceiverserver, edbcoltext, 20 );
Columns-> addl (receiver_server );

Tdbcol send_server (kcolsendserver, edbcoltext, 20 );
Columns-> addl (send_server );

Tdbcol user_name (kcoluser, edbcoltext, 60 );
User_name.iattributes = tdbcol: enotnull;
Columns-> addl (user_name );

Tdbcol user_pass (kcolpass, edbcoltext, 60 );
Columns-> addl (user_pass );

User: leaveiferror (adatabase. createtable (ktable, * columns ));

Cleanupstack: popanddestroy ();
}

//////////////////////////////////////// //////////////////////////////////
// Return: kerrnone, if the operation is complete or 1,
// If the operation requires further incremental execution
// Or another of the system-wide error codes.
Tint cdbbase: executesql (tdesc & asql)
{
Istore = cfilestore: openlc (ifssession, idatabasefilename. fullname (), efileread | efilewrite );
Idatabase. openl (istore, istore-> root ());

Rdbupdate update;
Tint r = update. Execute (idatabase, asql );
Update. Close ();

Idatabase. Close ();
// Pop store
Cleanupstack: popanddestroy ();
Return R;
}

Void cdbbase: adddatatotablemaill ()
{
Istore = cfilestore: openlc (ifssession, idatabasefilename. fullname (), efileread | efilewrite );
Idatabase. openl (istore, istore-> root ());

_ Statement (ksqlstatement, "select from_mail from d_mail ");
_ Partition (kfrommail1, "luw@163.com ");

Rdbview view;
User: leaveiferror (view. Prepare (idatabase, tdbquery (ksqlstatement, edbcomparenormal )));
User: leaveiferror (view. evaluateall ());

View. insertl ();

View. setcoll (1, kfrommail1 );

View. putl ();

View. Close ();

Idatabase. Close ();
// Pop store
Cleanupstack: popanddestroy ();
}

Void cdbbase: adddatatotablemaill (tdesc & asql, cdescarray & aparamarray)
{
Istore = cfilestore: openlc (ifssession, idatabasefilename. fullname (), efileread | efilewrite );
Idatabase. openl (istore, istore-> root ());

Rdbview view;
User: leaveiferror (view. Prepare (idatabase, tdbquery (asql, edbcomparenormal )));
User: leaveiferror (view. evaluateall ());

View. insertl ();

For (INT I = 1; I <= aparamarray. Count (); I ++)
{
View. setcoll (I, aparamarray [I-1]);
}

View. putl ();

View. Close ();

Idatabase. Close ();
// Pop store
Cleanupstack: popanddestroy ();
}

Void cdbbase: selectsql (tdesc & asql, rdbview * aview)
{
Istore = cfilestore: openlc (ifssession, idatabasefilename. fullname (), efileread | efilewrite );
Idatabase. openl (istore, istore-> root ());

User: leaveiferror (aview-> prepare (idatabase, tdbquery (asql, edbcomparenormal )));
User: leaveiferror (aview-> evaluateall ());

Tint A = aview-> countl ();
For (aview-> firstl (); aview-> atrow (); aview-> nextl ())
{
Aview-> getl ();
// Tptrc T = aview-> coldes (1 );
}

Idatabase. Close ();
// Pop store
Cleanupstack: popanddestroy ();
}

// End of File

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.