[Previous] [Next] [Contents]

CHAPTER 4. DEVELOPING APPLICATIONS

 

4.7 DATABASE

A. Overview

  • The "sqlite" database is pre-installed in MIZI Prizm SDK.
  • You can use Addressbook data using "libmzpim". The libmzpim reads database directly using class MzEdbc while DB Manager helps data sharing in writing.
  • DB Manager is an independent application. If you try to write data using DB Manager then data transmission through Unix domain socket shall be right.
  • The "class MzEdbc" supports SQL which is regarded as an abstract class for database. It means MzEdbc provides same API set to any database.
  • Detailed information about sqlite could be found in http://www.sqlite.org

 

B. Features

  • Implements most of SQL92. (Features not supported)
  • A complete database (with multiple tables and indices) is stored in a single disk file.
  • Atomic commit and rollback protect data integrity.
  • Database files can be freely shared between machines with different byte orders.
  • Supports databases up to 2 terabytes (2^41 bytes) in size.
  • Small memory footprint: less than 25K lines of C code.
  • Two times faster than PostgreSQL and MySQL for many common operations.
  • Very simple C/C++ interface requires the use of only three functions and one opaque structure.
  • TCL bindings included. Bindings for many other languages available separately.
  • Simple, well-commented source code.
  • Automated test suite provides near 100% code coverage.
  • Self-contained: no external dependencies.
  • Built and tested under Linux and Windows.
  • Sources are in the public domain. Use for any purpose.

 

C. Database I/O Structure for MIZI Prizm 2.0

 

D. Examples

Following examples show how to access Addressbook DB.

  1. Load
  2. View
  3. Edit
  • 1. Load
  • /********************************************************************* 
    * $Id: load_test.cpp,v 1.0 2003/08/14 12:56:36 antizm Exp $ 
    * 
    * Implementation of Load Contact 
    * 
    * Created : 20030814 
    * 
    * Copyright (C) 2000-2003 Mizi Research, Inc. AS. All rights reserved. 
    * 
    *********************************************************************/ 
     
     
    //------ Standard Header ----------------------------------- 
    #include <stdio.h>              // printf 
     
    //------ QT Header ----------------------------------------- 
    #include <qstring.h>            // QString class 
     
    //------ MIZI Header --------------------------------------- 
    #include <mzruimdoc.h>          // MzRUIMDirectDoc, MzRUIM class 
    #include <mzpimspersondoc.h>    // MzAddressbookDirectDoc class 
     
     
     
    void Dummy:loadContact() 
    { 
            // connect signal from R-UIM and local DB 
            connect(&MzRUIMDirectDoc::instance(), 
                            SIGNAL(signalSelect(int, char **)), 
                            this, 
                            SLOT(slotRUIMList(int, char **))); 
     
            connect(&MzAddressbookDirectDoc::instance(), 
                            SIGNAL(signalSelect(int, char **)), 
                            this, 
                            SLOT(slotInsertList(int, char **))); 
     
     
            // ... 
     
             
            // 1. Load R-UIM data 
            MzRUIMDirectDoc::instance().load(); 
             
             
            // 2. Load local DB 
            //  
            //   First arguement is private field, but it is not used.  
            //   (it'll be deleted soon) 
            //   if private field is true, load data except private record.  
            //   Otherwise it is false, load all data. 
            //         
            //   Second arguement is first character of first name to be looking up.
            //   If it is empty, load all data. 
            //
            MzAddressbookDirectDoc::instance().load(false, "");  
             
             
            // ... 
     
             
            // disconnect signal 
            disconnect(&MzRUIMDirectDoc::instance(), 
                            SIGNAL(signalSelect(int, char **)), 
                            this, 
                            SLOT(slotRUIMList(int, char **))); 
     
            disconnect(&MzAddressbookDirectDoc::instance(), 
                            SIGNAL(signalSelect(int, char **)), 
                            this, 
                            SLOT(slotInsertList(int, char **))); 
    } 
     
     
    void Dummy::slotRUIMList(int , char **data) 
    { 
            printf("=From R-UIM====================================\n"); 
        // Database ID 
        printf("ID      =[%s]\n", QString::fromUtf8(data[0]).local8Bit().data() ); 
        // Quick Number (Speed Dial Number)  
        printf("ADD     =[%s]\n", QString::fromUtf8(data[1]).local8Bit().data() ); 
        // Name 
        printf("NAME    =[%s]\n", QString::fromUtf8(data[2]).local8Bit().data() ); 
        // ABB. is Abbreviation code for chinese code (PINYIN) 
        printf("ABB.    =[%s]\n", QString::fromUtf8(data[3]).local8Bit().data() ); 
        // Tel Number 
        printf("NUMBER  =[%s]\n", QString::fromUtf8(data[4]).local8Bit().data() ); 
    } 
     
    void Dummy::slotLocalDBList(int , char **data) 
    { 
            printf("=From Local DB================================\n"); 
        // Database ID 
        printf("ID      =[%s]\n", QString::fromUtf8(data[0]).local8Bit().data() ); 
        // Primary Telepone's Type  
        printf("TYPE    =[%s]\n", QString::fromUtf8(data[1]).local8Bit().data() ); 
        // Name 
        printf("NAME    =[%s]\n", QString::fromUtf8(data[2]).local8Bit().data() ); 
        // Primary Telephone Number  
        printf("PRIM    =[%s]\n", QString::fromUtf8(data[3]).local8Bit().data() ); 
        // ABB. is Abbreviation code for chinese code (PINYIN) 
        printf("ABB.    =[%s]\n", QString::fromUtf8(data[4]).local8Bit().data() ); 
        // Photo file path  
        printf("PHOTO   =[%s]\n", QString::fromUtf8(data[5]).local8Bit().data() ); 
        // Category Name 
        printf("CATEGORY=[%s]\n", QString::fromUtf8(data[6]).local8Bit().data() ); 
        // Home Phone 
        printf("HOME    =[%s]\n", QString::fromUtf8(data[7]).local8Bit().data() ); 
        // Work Phone 
        printf("WORK    =[%s]\n", QString::fromUtf8(data[8]).local8Bit().data() ); 
        // Cellular 
        printf("MOBILE  =[%s]\n", QString::fromUtf8(data[9]).local8Bit().data() ); 
        // Pager 
        printf("PAGER   =[%s]\n", QString::fromUtf8(data[10]).local8Bit().data() ); 
        // FAX 
        printf("FAX     =[%s]\n", QString::fromUtf8(data[11]).local8Bit().data() ); 
        // Other Phone 
        printf("OTHER   =[%s]\n", QString::fromUtf8(data[12]).local8Bit().data() ); 
        // Email 
        printf("EMAIL   =[%s]\n", QString::fromUtf8(data[13]).local8Bit().data() ); 
    } 
     
    /* EOF */  
    
    

     

  • 2. View
  • /********************************************************************* 
    * $Id: voice_test.cpp,v 1.0 2003/08/04 11:22:15 antizm Exp $ 
    * 
    * Implementation of Lookup Address  
    * 
    * Created : 20030804 
    * 
    * Copyright (C) 2000-2003 Mizi Research, Inc. AS. All rights reserved. 
    * 
    *********************************************************************/ 
     
     
    //------ Standard Header ----------------------------------- 
    #include <stdio.h>                      // printf 
     
    //------ QT Header ----------------------------------------- 
    #include <qstring.h>                    // QString class 
    #include <qcstring.h>                   // QCString class 
     
    //------ MIZI Header --------------------------------------- 
    #include <mzapplication.h>              // MzApplication class 
    #include <mzaction.h>                   // MzAction class 
    #include <mztask.h>                     // MzTaskControl class 
    #include <mzruimdoc.h>                  // MzRUIMDirectDoc, MzRUIM class 
    #include <mzpimspersondoc.h>            // MzAddressbookDirectDoc class 
     
     
    void Dummy::lookupAddress(const QString &strName)  
    { 
            // First find a name from R-UIM Card. 
            MzRUIM *p = MzRUIMDirectDoc::instance().findByName(strName); 
            if (p != NULL) { 
                    printf("Name is found.\n"); 
                    launchAddress(true, p->id()); 
                     
            } else { 
                             
                    // If A name is not found from R-UIM card,  
                    // find a name from Local Data. 
                    printf("Name is not found.\n"); 
                    unsigned int nID = MzAddressbookDirectDoc::instance().findByName(strName); 
                     
                    if (nID != 0) { 
                            printf("Name is found.\n"); 
                            launchAddress(false, nID); 
                             
                    } else { 
                            printf("Name is not found.\n"); 
                    } 
            } 
    } 
     
    void Dummy::launchAddress(bool bRUIM, unsigned int nID) 
    { 
            QCString cstr; 
            if (bRUIM == true) { 
                    cstr = "ruimview_open"; 
            } else { 
                    cstr = "addressbookview_open_ex"; 
            } 
            MzAction *openWith = new MzAction(QString::number(nID),  
                            MzApplication::instance()->mainWindow()->actionCollection(), 
                            cstr); 
            MzAction::activate("addressbook", openWith); 
            delete openWith; 
                             
            MzTaskControl tc("addressbook"); 
            tc.activate(); 
    } 
     
    /* EOF */  
    
    

     

  • 3. Edit
  • /********************************************************************* 
    * $Id: voice_edit_test.cpp,v 1.0 2003/09/07 21:05:47 antizm Exp $ 
    * 
    * Implementation of Lookup Address & Edit Address 
    * 
    * Created : 20030907 
    * 
    * Copyright (C) 2000-2003 Mizi Research, Inc. AS. All rights reserved. 
    * 
    *********************************************************************/ 
     
     
    //------ Standard Header ----------------------------------- 
    #include <stdio.h>                      // printf 
     
    //------ QT Header ----------------------------------------- 
    #include <qstring.h>                    // QString class 
    #include <qcstring.h>                   // QCString class 
     
    //------ MIZI Header --------------------------------------- 
    #include <mzapplication.h>              // MzApplication class 
    #include <mzaction.h>                   // MzAction class 
    #include <mztask.h>                     // MzTaskControl class 
    #include <mzruimdoc.h>                  // MzRUIMDirectDoc, MzRUIM class 
    #include <mzpimspersondoc.h>            // MzAddressbookDirectDoc class 
     
     
    void Dummy::lookupAddress(const QString &strName)  
    { 
            // First find a name from R-UIM Card. 
            MzRUIM *p = MzRUIMDirectDoc::instance().findByName(strName); 
            if (p != NULL) { 
                    printf("Name is found.\n"); 
                    launchEditAddress(true, p->id()); 
                     
            } else { 
                             
                    // If A name is not found from R-UIM card,  
                    // find a name from Local Data. 
                    printf("Name is not found.\n"); 
                    unsigned int nID = MzAddressbookDirectDoc::instance().findByName(strName); 
                     
                    if (nID != 0) { 
                            printf("Name is found.\n"); 
                            launchEditAddress(false, nID); 
                             
                    } else { 
                            printf("Name is not found.\n"); 
                    } 
            } 
    } 
     
    void Dummy::launchEditAddress(bool bRUIM, unsigned int nID) 
    { 
            QCString cstrAction; 
            QString  strCommand; 
             
            if (bRUIM == true) { 
                    cstrAction = "ruimedit_open_ex"; 
                    strCommand = "mzruim.command.edit.id:"; 
            } else { 
                    cstrAction = "addressbookedit_open_ex"; 
                    strCommand = "mzadd.command.edit.id:"; 
            } 
            strCommand += QString::number(nID); 
             
             
            MzAction *openWith = new MzAction(strCommand,  
                            MzApplication::instance()->mainWindow()->actionCollection(), 
                            cstrAction); 
            MzAction::activate("addressbook", openWith); 
            delete openWith; 
                             
            MzTaskControl tc("addressbook"); 
            tc.activate(); 
    } 
     
    /* EOF */ 
    
    

     


    [Previous] [Next] [Contents] MIZI Prizm 2.0.0