Series 60 中Symbian OS提供了一个数据库引擎
使用的时候需要用到库edbms.lib efsrv.lib
包含头文件d32dbms.h f32file.h
设置数据库文件路径
_LIT(KFileName,"c:\\test.db");
1. 建立一个数据库文件:
//建立表的sql语句
_LIT(KSQLCreateTable, "CREATE TABLE notesEntry(id COUNTER,note varchar,alarm varchar,private varchar)");
RFs fsSession = iEikonEnv->FsSession();
RDbNamedDatabase database;
User::LeaveIfError(fsSession.Connect());
User::LeaveIfError(database.Create(fsSession, KFileName));
User::LeaveIfError(database.Execute(KSQLCreateTable));
database.Close();
fsSession.Close();
2.插入或修改记录
//sql语句
_LIT(KSQL, "Insert into notesEntry(note,alarm ,private) values('s','s','s')");
或者
_LIT(KSQL, "update notesEntry set note = '90' ");
RDbs rdbs;
RDbNamedDatabase database;
User::LeaveIfError(rdbs.Connect());
User::LeaveIfError(database.Open(rdbs,KFileName));
User::LeaveIfError(database.Execute(KSQL));
database.Close();
rdbs.Close();
3.查看记录
_LIT(KSQLQueryTable, "Select id,note,alarm ,private from notesEntry");
RDbs rdbs;
RDbNamedDatabase database;
User::LeaveIfError(rdbs.Connect());
User::LeaveIfError(database.Open(rdbs,KFileName));
RDbView view;
User::LeaveIfError(view.Prepare(database,TDbQuery(KSQLQueryTable,EDbCompareNormal)));
User::LeaveIfError(view.EvaluateAll());
for (view.FirstL();view.AtRow();view.NextL())
{
view.GetL();
TUint32 id=view.ColUint32(1);
}
view.Close();
database.Close();
rdbs.Close();