'SQLite'에 해당되는 글 5건

  1. 2008.08.11 wxWidgets sqlite3 eclipse Tool Settings
  2. 2008.08.08 sqlite make
  3. 2008.07.16 sqlite3 wxList with try catch
  4. 2008.07.15 sqlite3 wxList 이용.
  5. 2008.06.27 sqlite3 simple examples
GCC C++ Compiler
Directories
  C:\bin\msys\1.0\local\include\wx-2.8
  C:\bin\msys\1.0\local\include
  C:\bin\msys\1.0\local\include

-D
  _WXMSW__
  WXUSINGDLL
  WX_PRECOMP

Optimization
  Optimize more (-O2)

Debuging
  Maximum (-g3)

Miscellaneous
  -c -fmessage-length=0 -mthreads -Wundef -Wno-ctor-dtor-privacy -fno-strict-aliasing

MinGW C++ Linker
Libraries
  rpcrt4
  oleaut32
  ole32
  uuid
  winspool
  winmm
  shell32
  comctl32
  comdlg32
  ctl3d32
  advapi32
  wsock32
  gdi32
  wx_base_xml-2.8
  wx_msw_adv-2.8
  wx_msw_html-2.8
  wx_msw_core-2.8
  wx_base-2.8
  wxtiff-2.8
  wxpng-2.8
  wxzlib-2.8
  wxregex-2.8
  wxexpat-2.8
  sqlite3

Libraries
  "C:\bin\msys\1.0\local\lib"

Miscellaneous
  -mthreads -mwindows


기타
Run Configurations / Environment / PATH 에
dll경로를 지정해서 올려 준다.
Posted by stekilove
,

sqlite make

computer programming 2008. 8. 8. 15:39
MinGW 설치
MSYS 설치


http://sourceforge.net/forum/forum.php?forum_id=731558&abmode=1
에서 msys 패치

sqlite 다운 받아 압축을 푼다.

MSYS실행
sqlite를 링크한다.

그리고 아래와 같이 명령어들을 실행시킨다.

configure --enable-static=yes --enable-threadsafe --disable-tcl

make

make install

make clean

깔끔하다. -_-;;

Posted by stekilove
,
edit source with try-catch.


StekiDB.h                                                                   

#ifndef __STEKIDB_h__
#define __STEKIDB_h__

#include <wx/string.h>
#include <wx/list.h>
#include <sqlite3.h>

class StekiDBException
{
private:
    wxString msg;
public:
    StekiDBException(const wxString &msg){ this->msg.Append(msg); };
    virtual ~StekiDBException(){};
    const wxString getMessage() const {
        return msg;
    }
};

class StekiDBConnection
{
private:
        wxString dbName;     
       
public:
    sqlite3 *db;

    StekiDBConnection(const wxString &dbName);
    virtual ~StekiDBConnection();
    void close();
};

class StekiDBResultSet : public wxList
{
public:
    StekiDBResultSet();
    ~StekiDBResultSet();
};

class StekiDBStatement
{
private:
    StekiDBConnection *conn;
public:
    StekiDBStatement(StekiDBConnection *conn);
    virtual ~StekiDBStatement();
    StekiDBResultSet * executeQuery( const wxString &sql );
};

class StekiDBValue : public wxObject
{
public:
    wxString *value;
    wxString *colName;
public:
    StekiDBValue(wxString *colName, wxString *value){ this->colName=colName; this->value=value; }
    virtual ~StekiDBValue(){ free(value); free(colName); }
};


#endif



StekiDB.cpp                                                                             

#include "StekiDB.h"

/**
**  StekiDBConnection
**
**/

StekiDBConnection::StekiDBConnection(const wxString &dbName){
    this->dbName=dbName;
   
    char *zErrMsg = 0;
    int rc;
   
    rc = sqlite3_open(dbName, &db);
    if( rc )
    {
        throw ( StekiDBException(wxString("Can't open database: ").Append( wxString(sqlite3_errmsg(db))))  );
//        wxMessageBox(wxT("Can't open database: ") + wxString(sqlite3_errmsg(db)));
    }
}

StekiDBConnection::~StekiDBConnection(){
    close();
}

void StekiDBConnection::close(){
    if(db!=NULL) sqlite3_close(db);
}

/**
**  callback_resultset
**
**/

static int callback_resultset(void *pArg, int argc, char **argv, char **azColName)
{
    StekiDBResultSet *rset=(StekiDBResultSet *)pArg;

    wxList *list=new wxList();
    int i;
    for(i=0; i<argc; i++)
    {
        //printf("%s=%s, ", azColName[i], argv[i] ? argv[i] : "NULL");
        wxString *colName = new wxString( azColName[i] );
        wxString *str = new wxString( argv[i] ? argv[i] : "NULL" );
        StekiDBValue *value = new StekiDBValue( colName, str );
        list->Append( value  );
    }
    rset->Append( list );

    return 0;
}

/**
**  StekiDBResultSet
**
**/
StekiDBResultSet::StekiDBResultSet(){
}

StekiDBResultSet::~StekiDBResultSet(){
    this->DeleteContents(true);
}

/**
**  StekiDBStatement
**
**/

StekiDBStatement::StekiDBStatement(StekiDBConnection *conn){
    this->conn=conn;
}

/**
**
**
**/
StekiDBStatement::~StekiDBStatement(){
}

StekiDBResultSet * StekiDBStatement::executeQuery( const wxString &sql ){
    char *zErrMsg = 0;
   
    StekiDBResultSet *rset = new StekiDBResultSet();

    int rc = sqlite3_exec(conn->db, sql.c_str(), callback_resultset, rset, &zErrMsg);
    if( rc!=SQLITE_OK )
    {
        throw ( StekiDBException(wxString("SQL error: ").Append( wxString(zErrMsg)))  );
//        wxMessageBox(wxT("SQL error: ") + wxString(zErrMsg));
    }

    return rset;
}



Example.cpp                                                                     

void MyFrame::OnMyDBReadBtn(wxCommandEvent&)
{
    StekiDBConnection *conn;
    StekiDBStatement *stmt;
    StekiDBResultSet *rset;

    try {
        conn = new StekiDBConnection("steki.db");
        stmt = new StekiDBStatement(conn);   
        rset = stmt->executeQuery( "select * from x" );

        for ( wxList::Node *node = rset->GetFirst(); node; node = node->GetNext() ){
            wxList *rsetlist = (wxList *)node->GetData();
          
            for ( wxList::Node *node2 = rsetlist->GetFirst(); node2; node2 = node2->GetNext() ){
                StekiDBValue *value = (StekiDBValue *)node2->GetData();
              
                wtc->AppendText( *value->value );
                wtc->AppendText( "," );
            }  
            wtc->AppendText("\n");
        }
    } catch (StekiDBException e) {
        wxMessageBox(e.getMessage());
    }

    if(rset!=NULL) free (rset);
    if(stmt!=NULL) free (stmt);
    if(conn!=NULL) free (conn);
}
Posted by stekilove
,
sqlite3와 wxWidgets 를 이용해서 아래와 같이 만들어 보았다.

StekiDB.h                                                              


#ifndef __STEKIDB_h__
#define __STEKIDB_h__

#include <wx/msgdlg.h>
#include <wx/string.h>
#include <wx/list.h>
#include <sqlite3.h>

class StekiDBConnection
{
private:
        wxString dbName;     
       
public:
    sqlite3 *db;

    StekiDBConnection(const wxString &dbName);
    virtual ~StekiDBConnection();
    void close();
};

class StekiDBResultSet : public wxList
{
public:
    StekiDBResultSet();
    ~StekiDBResultSet();
};

class StekiDBStatement
{
private:
    StekiDBConnection *conn;
public:
    StekiDBStatement(StekiDBConnection *conn);
    virtual ~StekiDBStatement();
    StekiDBResultSet * executeQuery( const wxString &sql );
};

class StekiDBValue : public wxObject
{
public:
    wxString *value;
    wxString *colName;
public:
    StekiDBValue(wxString *colName, wxString *value){ this->colName=colName; this->value=value; }
    virtual ~StekiDBValue(){ free(value); free(colName); }
};


#endif


StekiDB.cpp                                                                  

#include "StekiDB.h"

/**
**  StekiDBConnection
**
**/

StekiDBConnection::StekiDBConnection(const wxString &dbName){
    this->dbName=dbName;
   
    char *zErrMsg = 0;
    int rc;
   
    rc = sqlite3_open(dbName, &db);
    if( rc )
    {
        wxMessageBox(wxT("Can't open database: ") + wxString(sqlite3_errmsg(db)));
    }
}

StekiDBConnection::~StekiDBConnection(){
    close();
}

void StekiDBConnection::close(){
    if(db!=NULL) sqlite3_close(db);
}

/**
**  callback_resultset
**
**/

static int callback_resultset(void *pArg, int argc, char **argv, char **azColName)
{
    StekiDBResultSet *rset=(StekiDBResultSet *)pArg;

    wxList *list=new wxList();
    int i;
    for(i=0; i<argc; i++)
    {
        //printf("%s=%s, ", azColName[i], argv[i] ? argv[i] : "NULL");
        wxString *colName = new wxString( azColName[i] );
        wxString *str = new wxString( argv[i] ? argv[i] : "NULL" );
        StekiDBValue *value = new StekiDBValue( colName, str );
        list->Append( value  );
    }
    rset->Append( list );

    return 0;
}

/**
**  StekiDBResultSet
**
**/
StekiDBResultSet::StekiDBResultSet(){
}

StekiDBResultSet::~StekiDBResultSet(){
    this->DeleteContents(true);
}

/**
**  StekiDBStatement
**
**/

StekiDBStatement::StekiDBStatement(StekiDBConnection *conn){
    this->conn=conn;
}

/**
** StekiDBStatement
**
**/
StekiDBStatement::~StekiDBStatement(){
}

StekiDBResultSet * StekiDBStatement::executeQuery( const wxString &sql ){
    char *zErrMsg = 0;
   
    StekiDBResultSet *rset = new StekiDBResultSet();

    int rc = sqlite3_exec(conn->db, sql.c_str(), callback_resultset, rset, &zErrMsg);
    if( rc!=SQLITE_OK )
    {
        wxMessageBox(wxT("SQL error: ") + wxString(zErrMsg));
    }

    return rset;
}



Example.cpp                                                                   

void MyFrame::OnMyDBReadBtn(wxCommandEvent&)
{
    StekiDBConnection *conn = new StekiDBConnection("steki.db");
    StekiDBStatement *stmt = new StekiDBStatement(conn);   
    StekiDBResultSet *rset = stmt->executeQuery( "select * from x" );

    for ( wxList::Node *node = rset->GetFirst(); node; node = node->GetNext() ){
        wxList *rsetlist = (wxList *)node->GetData();
      
        for ( wxList::Node *node2=rsetlist->GetFirst();node2;node2=node2->GetNext() )
       {
            StekiDBValue *value = (StekiDBValue *)node2->GetData();
          
            wtc->AppendText( *value->value );
            wtc->AppendText( "," );
        }  
        wtc->AppendText("\n");
    }

    free (rset);
    free (stmt);
    free (conn);
}
Posted by stekilove
,
#include <sqlite3.h>

class prjWxEx01Frm : public wxFrame
private:
    sqlite3 *db;

...
...
...


//----------------------------------------------------------------------------
// prjWxEx01Frm
//----------------------------------------------------------------------------
//Add Custom Events only in the appropriate block.
//Code added in other places will be removed by wxDev-C++
////Event Table Start
BEGIN_EVENT_TABLE(prjWxEx01Frm,wxFrame)
    ////Manual Code Start
    ////Manual Code End
    
    EVT_CLOSE(prjWxEx01Frm::OnClose)
    EVT_ACTIVATE(prjWxEx01Frm::prjWxEx01FrmActivate)
    EVT_BUTTON(ID_WXBTNNEXT,prjWxEx01Frm::WxBtnNextClick)


END_EVENT_TABLE()
////Event Table End


void prjWxEx01Frm::OnClose(wxCloseEvent& event)
{
    sqlite3_close(db);
    Destroy();
}

/*
 * prjWxEx01FrmActivate
 */
void prjWxEx01Frm::prjWxEx01FrmActivate(wxActivateEvent& event)
{
    dbFileName=wxString( "D:/hobby_cpp/x4_sqlite/test.db" );
    int rc = sqlite3_open(dbFileName, &db);
    if( rc )
    {
        wxString str( sqlite3_errmsg(db) );
        wxMessageBox(wxT("Can't open database: ") + str);

        sqlite3_close(db);
    }
}

static int callback(void *pArg, int argc, char **argv, char **azColName){
    StekiResultSet *rset=(StekiResultSet *)pArg;
    
    wxString info;
    for(int i=0;i <argc;i++)
    {
       info.Append(wxString(azColName[i])+wxT("=")+wxT(argv[i])+wxT("\t"));
    }
    rset->add( info );
    
    // return 0 or else the sqlexec will be aborted.
    return 0;
}

/*
 * WxBtnNextClick
 */
void prjWxEx01Frm::WxBtnNextClick(wxCommandEvent& event)
{
    WxMemoMean->SetValue(_T(""));
    
    StekiResultSet *resultSet = new StekiResultSet();
    
    char *zErrMsg = 0;
    wxString strSql("select * from x;");
    int rc = sqlite3_exec( db, strSql, callback, (void *)resultSet, &zErrMsg);
    if( rc!=SQLITE_OK ){
        wxString strErrMsg( zErrMsg );
        wxMessageBox(wxT("SQL error: ") + strErrMsg);
        return;
    }

    appendText( *resultSet->toString() );
    free( resultSet );
    
}

Posted by stekilove
,