Example #1
0
void TableSettings::FillColumns()
{
    wxVector<wxVariant> line;

    m_dvColumns->DeleteAllItems();

    for( SerializableList::iterator it = m_lstColumns.begin();
         it != m_lstColumns.end(); ++it ) {

        Column *c = wxDynamicCast( *it, Column );
        if( c ) {
            IDbType *type = c->GetType();

            line.clear();
            line.push_back( wxVariant( c->GetName() ) );
            line.push_back( wxVariant( type->GetTypeName() ) );
            line.push_back( wxVariant( wxString::Format( wxT("%ld,%ld"), type->GetSize(), type->GetSize2() ) ) );
            line.push_back( wxVariant( type->GetNotNull() ) );
            line.push_back( wxVariant( type->GetAutoIncrement() ) );
            line.push_back( wxVariant( IsPrimaryKey( c->GetName() ) ) );

            m_dvColumns->AppendItem( line, reinterpret_cast<wxUIntPtr>(c) );
        }
    }
}
Example #2
0
Column* TableSettings::GetColumn(const wxString& name)
{
    for( SerializableList::iterator it = m_lstColumns.begin();
         it != m_lstColumns.end(); ++it ) {

        Column *c = wxDynamicCast( *it, Column );
        if( c && ( c->GetName() == name ) ) return c;
    }

    return NULL;
}
Example #3
0
void TableSettings::FillRefTableColums(Table* tab)
{
    if( tab ) {
        m_choiceRefCol->Clear();
        m_choiceRefCol->Append( wxT("") );

        for( SerializableList::iterator it = tab->GetChildrenList().begin();
             it != tab->GetChildrenList().end(); ++it ) {

            Column *c = wxDynamicCast( *it, Column );
            if( c ) m_choiceRefCol->Append( c->GetName() );
        }
    }
}
Example #4
0
void test_describe(void)
{
    ocout << otext("\n>>>>> TEST DESCRIBING TABLE \n\n");
    ocout << otext("Column Name         Type                ") << oendl;
    ocout << otext("----------------------------------------") << oendl;
    ocout << std::setiosflags(std::ios::left);

    TypeInfo table(con, otext("test_fetch"), TypeInfo::Table);

    for (int i = 1, n = table.GetColumnCount(); i <= n; i++)
    {
        Column col = table.GetColumn(i);

        ocout << std::setw(20) << col.GetName().c_str()
            << std::setw(20) << col.GetFullSQLType().c_str()
            << oendl;
    }

    /* TEST DESCRIBING TYPE ------------------------------------------------- */

    ocout << otext("\n>>>>> TEST DESCRIBING TYPE \n\n");
    ocout << otext("Column Name         Type                ") << oendl;
    ocout << otext("----------------------------------------") << oendl;
    ocout << std::setiosflags(std::ios::left);

    TypeInfo type(con, otext("test_t"), TypeInfo::Type);

    for (int i = 1, n = type.GetColumnCount(); i <= n; i++)
    {
        Column col = type.GetColumn(i);

        ocout << std::setw(20) << col.GetName().c_str()
            << std::setw(20) << col.GetFullSQLType().c_str()
            << oendl;
    }
}
Example #5
0
void TableSettings::OnRemoveColumnClick(wxCommandEvent& event)
{
    Column *col = GetColumn( GetSelectedColumnName() );
    if( col ) {
		// delete associated keys
		SerializableList keys;
		GetConstraints( keys, col->GetName() );
		for(SerializableList::iterator it = keys.begin(); it != keys.end(); ++it ) {
			Constraint *key = (Constraint*) *it;
			m_lstKeys.DeleteObject( key );
			delete key;
		}
		// delete the column
        m_lstColumns.DeleteObject( col );
        delete col;
        UpdateView();
    }
}
Example #6
0
wxString MySqlDbAdapter::GetCreateTableSql(Table* tab, bool dropTable)
{
	//TODO:SQL:
	wxString str = wxT("");
	if (dropTable) str = wxString::Format(wxT("SET FOREIGN_KEY_CHECKS = 0;\nDROP TABLE IF EXISTS `%s` ;\nSET FOREIGN_KEY_CHECKS = 1; \n"),tab->GetName().c_str());
	str.append(wxString::Format(wxT("CREATE TABLE `%s` (\n"),tab->GetName().c_str()));



	SerializableList::compatibility_iterator node = tab->GetFirstChildNode();
	while( node ) {
		Column* col = NULL;
		if( node->GetData()->IsKindOf( CLASSINFO(Column)) ) col = (Column*) node->GetData();
		if(col)	str.append(wxString::Format(wxT("\t`%s` %s"),col->GetName().c_str(), col->GetType()->ReturnSql().c_str()));

		Constraint* constr = wxDynamicCast(node->GetData(),Constraint);
		if (constr) {
			if (constr->GetType() == Constraint::primaryKey) str.append(wxString::Format(wxT("\tPRIMARY KEY (`%s`) \n"), constr->GetLocalColumn().c_str()));
		}

		node = node->GetNext();
		if (node) {
			if (wxDynamicCast(node->GetData(),Column)) str.append(wxT(",\n ")) ;
			else if ((constr = wxDynamicCast(node->GetData(),Constraint))) {
				if (constr->GetType() == Constraint::primaryKey) str.append(wxT(",\n ")) ;
			}

		}
		//else  str.append(wxT("\n ")) ;
	}

	/*	Column* col = tab->GetFristColumn();
		while (col) {
			str.append(wxString::Format(wxT("\t`%s` %s"),col->getName().c_str(), col->getPType()->ReturnSql().c_str()));
			col = wxDynamicCast(col->GetSibbling(),Column);
			if (col) str.append(wxT(",\n ")) ;
			else  str.append(wxT("\n ")) ;
		}*/

	str.append(wxT("\n) ENGINE=INNODB;\n"));
	str.append(wxT("-- -------------------------------------------------------------\n"));
	return str;
}
Example #7
0
void TableSettings::UpdateView()
{
    int crow = m_dvColumns->GetSelectedRow();
    //int krow = m_dvKeys->GetSelectedRow();

    FillColumns();
    FillKeys();

    m_choiceLocalCol->Clear();
    m_choiceLocalCol->Append( wxT("") );
    for( SerializableList::iterator it = m_lstColumns.begin(); it != m_lstColumns.end(); ++it ) {
        Column *c = (Column*) *it;
        if( c )	m_choiceLocalCol->Append( c->GetName() );
    }

    m_choiceLocalCol->SetStringSelection( wxT("") );
    m_choiceRefTable->SetStringSelection( wxT("") );
    m_choiceRefCol->SetStringSelection( wxT("") );
    m_radioOnDelete->SetSelection( 0 );
    m_radioOnUpdate->SetSelection( 0 );

    if( crow != wxNOT_FOUND && crow < m_dvColumns->GetItemCount() ) m_dvColumns->SelectRow( crow );
    //if( krow != wxNOT_FOUND && krow < m_dvKeys->GetItemCount() ) m_dvKeys->SelectRow( krow );
}
Example #8
0
void TableSettings::OnColumnChanged(wxDataViewEvent& event)
{
    Column *col = reinterpret_cast<Column*>(m_dvColumns->GetItemData( event.GetItem() ) );
    if( col ) {
        wxVariant val;
        event.GetModel()->GetValue( val, event.GetItem(), event.GetColumn() );
        if( ! val.IsNull() ) {
            switch( event.GetColumn() ) {
            case 0: {
                // rename local columns in keys
                SerializableList keys;
                GetConstraints( keys, col->GetName() );
                for(SerializableList::iterator it = keys.begin(); it != keys.end(); ++it ) {
                    Constraint *key = (Constraint*) *it;
                    if( key->GetType() == Constraint::primaryKey ) key->SetName( wxT("PK_") + val.GetString() );
                    key->SetLocalColumn( val.GetString() );
                }
                // rename table column
                col->SetName( val.GetString() );
                break;
            }
            case 1: {
                col->SetType( m_pDbAdapter->GetDbTypeByName( val.GetString() ) );
                break;
            }
            case 2: {
                long s1, s2;
                s1 = s2 = 0;
                wxSscanf( val.GetString(), wxT("%ld,%ld"), &s1, &s2 );
                IDbType *type = col->GetType();
                if( type->HaveSize() ) type->SetSize( s1 );
                else {
                    m_infobar->ShowMessage( wxT("This data type doesn't support size definition."), wxICON_WARNING );
                    Refresh();
                }
                if( type->HaveSize2() ) type->SetSize2( s1 );
                else { 
                    m_infobar->ShowMessage( wxT("This data type doesn't support size definition."), wxICON_WARNING );
                    Refresh();
                }
                break;
            }
            case 3: {
                IDbType *type = col->GetType();
                if( type->HaveNotNull() ) type->SetNotNull( val.GetBool() );
                else {
                    m_infobar->ShowMessage( wxT("This data type doesn't support NOT NULL feature."), wxICON_WARNING );
                    Refresh();
                }
                break;
            }
            case 4: {
                IDbType *type = col->GetType();
                if( type->HaveAutoIncrement() ) type->SetAutoIncrement( val.GetBool() );
                else { 
                    m_infobar->ShowMessage( wxT("This data type doesn't support AUTOINCREMENT feature."), wxICON_WARNING );
                    Refresh();
                }
                break;
            }
            case 5: {
                Constraint *key = GetConstraint( Constraint::primaryKey, col->GetName() );
                if( key ) {
                    // remove primary key if exists
                    m_lstKeys.DeleteObject( key );
                    delete key;
                } else {
                    // create new primary key
                    key = new Constraint( wxT("PK_") + col->GetName(),
                                          col->GetName(),
                                          Constraint::primaryKey,
                                          Constraint::noAction,
                                          Constraint::noAction );

                    m_lstKeys.Append( key );
                }
                break;
            }
            }
        }
    }

    event.Skip();

    UpdateView();
}
Example #9
0
void DbViewerPanel::OnPopupClick(wxCommandEvent& evt)
{
    if(!m_selectedID.IsOk()) return;

    try {
        if(evt.GetId() == XRCID("IDR_DBVIEWER_COPY_COLUMN")) {
            DbItem* data = (DbItem*)m_treeDatabases->GetItemData(m_selectedID);
            if(data) {
                Column* col = wxDynamicCast(data->GetData(), Column);
                if(col) {
                    wxString colname = col->GetName();
                    ::CopyToClipboard(colname);
                }
            }
        } else if(evt.GetId() == XRCID("IDR_DBVIEWER_ADD_DATABASE")) {
            if(m_pEditedConnection) {
                // TODO:LANG:
                wxString dbName = wxGetTextFromUser(_("Database name"), _("Add database"));
                if(!dbName.IsEmpty()) {
                    DatabaseLayerPtr pDbLayer = m_pEditedConnection->GetDbAdapter()->GetDatabaseLayer(wxT(""));
                    wxString sql = m_pEditedConnection->GetDbAdapter()->GetCreateDatabaseSql(dbName);
                    if(!sql.empty()) {

                        pDbLayer->RunQuery(sql);
                        pDbLayer->Close();

                        // TODO:LANG:
                        wxMessageBox(_("Database created successfully"));

                        RefreshDbView();
                    } else {
                        // TODO:LANG:
                        wxMessageDialog dlg(
                            this, _("Can't create new db in this database engine!"), _("Error"), wxOK | wxICON_ERROR);
                        dlg.ShowModal();
                    }
                }
            }
        } else if(evt.GetId() == XRCID("IDR_DBVIEWER_DROP_DATABASE")) {
            DbItem* data = (DbItem*)m_treeDatabases->GetItemData(m_selectedID);
            if(data) {
                Database* pDb = (Database*)wxDynamicCast(data->GetData(), Database);
                if(pDb) {
                    wxString dropSQL = pDb->GetDbAdapter()->GetDropDatabaseSql(pDb);
                    if(!dropSQL.IsEmpty()) {
                        // TODO:LANG:
                        wxMessageDialog dlg(this, wxString::Format(_("Remove database '%s'?"), pDb->GetName().c_str()),
                            _("Drop database"), wxYES_NO);
                        if(dlg.ShowModal() == wxID_YES) {
                            DatabaseLayerPtr pDbLayer = pDb->GetDbAdapter()->GetDatabaseLayer(wxT(""));
                            pDbLayer->RunQuery(dropSQL);
                            pDbLayer->Close();
                            // TODO:LANG:
                            wxMessageBox(_("Database dropped successfully"));
                            RefreshDbView();
                        }
                    }
                }
            }
        } else if(evt.GetId() == XRCID("IDR_DBVIEWER_ERD_TABLE")) {
            DbItem* data = (DbItem*)m_treeDatabases->GetItemData(m_selectedID);
            if(data) {
                Table* pTab = (Table*)wxDynamicCast(data->GetData(), Table);
                if(pTab) {
                    wxString pagename;
                    pagename = CreatePanelName(pTab, DbViewerPanel::Erd);
                    ErdPanel* erdpanel =
                        new ErdPanel(m_pNotebook, pTab->GetDbAdapter()->Clone(), m_pConnections, (Table*)pTab->Clone());
                    AddEditorPage(erdpanel, pagename);
                }
            }
        } else if(evt.GetId() == XRCID("IDR_DBVIEWER_ERD_DB")) {
            DbItem* data = (DbItem*)m_treeDatabases->GetItemData(m_selectedID);
            if(data) {
                Database* pDb = (Database*)wxDynamicCast(data->GetData(), Database);
                if(pDb) {
                    wxString pagename;
                    pagename = CreatePanelName(pDb, DbViewerPanel::Erd);
                    ErdPanel* erdpanel = new ErdPanel(
                        m_pNotebook, pDb->GetDbAdapter()->Clone(), m_pConnections, (Database*)pDb->Clone());
                    AddEditorPage(erdpanel, pagename);
                }
            }
        } else if(evt.GetId() == XRCID("IDR_DBVIEWER_CLASS_DB")) {
            DbItem* data = (DbItem*)m_treeDatabases->GetItemData(m_selectedID);
            if(data) {
                Database* pDb = (Database*)wxDynamicCast(data->GetData(), Database);
                if(pDb) {
                    pDb = (Database*)pDb->Clone();
                    // NOTE: the refresh functions must be here for propper code generation (they translate views into
                    // tables)
                    pDb->RefreshChildren(true);
                    pDb->RefreshChildrenDetails();
                    ClassGenerateDialog dlg(m_mgr->GetTheApp()->GetTopWindow(), pDb->GetDbAdapter(), pDb, m_mgr);
                    dlg.ShowModal();
                    delete pDb;
                }
            }
        } else if(evt.GetId() == XRCID("IDR_DBVIEWER_CLASS_TABLE")) {
            DbItem* data = (DbItem*)m_treeDatabases->GetItemData(m_selectedID);
            if(data) {
                Table* pTab = (Table*)wxDynamicCast(data->GetData(), Table);
                if(pTab) {
                    ClassGenerateDialog dlg(
                        m_mgr->GetTheApp()->GetTopWindow(), pTab->GetDbAdapter(), (Table*)pTab->Clone(), m_mgr);
                    dlg.ShowModal();
                }
            }
        } else if(evt.GetId() == XRCID("IDR_DBVIEWER_DROP_TABLE")) {
            DbItem* data = (DbItem*)m_treeDatabases->GetItemData(m_selectedID);
            if(data) {
                Table* pTab = (Table*)wxDynamicCast(data->GetData(), Table);
                if(pTab) {
                    wxMessageDialog dlg(this, wxString::Format(_("Remove table '%s'?"), pTab->GetName().c_str()),
                        _("Drop table"), wxYES_NO);
                    if(dlg.ShowModal() == wxID_YES) {
                        DatabaseLayerPtr pDbLayer = pTab->GetDbAdapter()->GetDatabaseLayer(pTab->GetParentName());
                        pDbLayer->RunQuery(pTab->GetDbAdapter()->GetDropTableSql(pTab));
                        pDbLayer->Close();

                        wxMessageBox(_("Table dropped successfully"));
                        RefreshDbView();
                    }
                }
            }
        } else if(evt.GetId() == XRCID("IDR_DBVIEWER_DROP_VIEW")) {
            DbItem* data = (DbItem*)m_treeDatabases->GetItemData(m_selectedID);
            if(data) {
                View* pView = (View*)wxDynamicCast(data->GetData(), View);
                if(pView) {
                    wxMessageDialog dlg(this, wxString::Format(_("Remove view '%s'?"), pView->GetName().c_str()),
                        _("Drop view"), wxYES_NO);
                    if(dlg.ShowModal() == wxID_YES) {
                        DatabaseLayerPtr pDbLayer = pView->GetDbAdapter()->GetDatabaseLayer(pView->GetParentName());
                        pDbLayer->RunQuery(pView->GetDbAdapter()->GetDropViewSql(pView));
                        pDbLayer->Close();

                        wxMessageBox(_("View dropped successfully"));
                        RefreshDbView();
                    }
                }
            }
        } else if(evt.GetId() == XRCID("IDR_DBVIEWER_SQL_TABLE")) {
            DbItem* data = (DbItem*)m_treeDatabases->GetItemData(m_selectedID);
            if(data) {
                Table* pTab = (Table*)wxDynamicCast(data->GetData(), Table);
                if(pTab) {
#ifdef __WXMSW__
                    clWindowUpdateLocker locker(m_mgr->GetEditorPaneNotebook());
#endif
                    wxString pagename = CreatePanelName(pTab, DbViewerPanel::Sql);
                    if(!DoSelectPage(pagename)) {
                        SQLCommandPanel* sqlpage = new SQLCommandPanel(
                            m_pNotebook, pTab->GetDbAdapter()->Clone(), pTab->GetParentName(), pTab->GetName());
                        AddEditorPage(sqlpage, pagename);
                    }
                }
            }
        } else if(evt.GetId() == XRCID("IDR_DBVIEWER_SQL_VIEW")) {
            DbItem* data = (DbItem*)m_treeDatabases->GetItemData(m_selectedID);
            if(data) {
                View* pView = (View*)wxDynamicCast(data->GetData(), View);
                if(pView) {
#ifdef __WXMSW__
                    clWindowUpdateLocker locker(m_mgr->GetEditorPaneNotebook());
#endif
                    wxString pagename = CreatePanelName(pView, DbViewerPanel::Sql);
                    if(!DoSelectPage(pagename)) {
                        SQLCommandPanel* sqlpage = new SQLCommandPanel(
                            m_pNotebook, pView->GetDbAdapter()->Clone(), pView->GetParentName(), pView->GetName());
                        AddEditorPage(sqlpage, pagename);
                    }
                }
            }
        } else if(evt.GetId() == XRCID("IDR_DBVIEWER_SQL_DATABASE")) {
            DbItem* data = (DbItem*)m_treeDatabases->GetItemData(m_selectedID);
            if(data) {
                Database* pDb = (Database*)wxDynamicCast(data->GetData(), Database);
                if(pDb) {
                    wxString pagename = CreatePanelName(pDb, DbViewerPanel::Sql);
                    if(!DoSelectPage(pagename)) {
                        SQLCommandPanel* sqlpage =
                            new SQLCommandPanel(m_pNotebook, pDb->GetDbAdapter()->Clone(), pDb->GetName(), wxT(""));
#ifndef __WXMSW__
                        sqlpage->Show();
#endif
                        AddEditorPage(sqlpage, pagename);
                    }
                }
            }
        } else if(evt.GetId() == XRCID("IDR_DBVIEWER_IMPORT_DATABASE")) {
            DbItem* data = (DbItem*)m_treeDatabases->GetItemData(m_selectedID);
            if(data) {
                Database* pDb = (Database*)wxDynamicCast(data->GetData(), Database);
                if(pDb) {
                    // TODO:LANG:
                    wxFileDialog dlg(this, _("Import database from SQL file ..."), wxGetCwd(), wxT(""),
                        wxT("SQL Files (*.sql)|*.sql"), wxFD_OPEN | wxFD_FILE_MUST_EXIST);
                    if(dlg.ShowModal() == wxID_OK) {
                        ImportDb(dlg.GetPath(), pDb);
                    }
                }
            }
            RefreshDbView();
        } else if(evt.GetId() == XRCID("IDR_DBVIEWER_DUMP_DATABASE")) {
            DbItem* data = (DbItem*)m_treeDatabases->GetItemData(m_selectedID);
            if(data) {
                Database* pDb = (Database*)wxDynamicCast(data->GetData(), Database);
                if(pDb) {
                    // TODO:LANG:
                    wxFileDialog dlg(this, _("Dump data into file ..."), wxT(""), pDb->GetName() + wxT(".sql"),
                        wxT("SQL files (*.sql)|*.sql"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
                    if(dlg.ShowModal() == wxID_OK) {
                        DumpClass* dump = new DumpClass(pDb->GetDbAdapter(), pDb, dlg.GetPath());
                        dump->DumpData();
                        wxMessageBox(_("Data was saved to ") + dlg.GetPath());
                    }
                }
            }
        } else if(evt.GetId() == XRCID("IDR_DBVIEWER_EXPORT_DATABASE")) {
            DbItem* data = (DbItem*)m_treeDatabases->GetItemData(m_selectedID);
            if(data) {
                Database* pDb = (Database*)wxDynamicCast(data->GetData(), Database);
                if(pDb) {
                    wxFileDialog dlg(this, _("Export database..."), wxGetCwd(), wxT(""), wxT("SQL Files (*.sql)|*.sql"),
                        wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
                    if(dlg.ShowModal() == wxID_OK) {
                        // CreateStructure
                        wxString retStr = wxT("-- SQL script created by wxDbExplorer\n\n ");
                        SerializableList::compatibility_iterator tabNode = pDb->GetFirstChildNode();
                        while(tabNode) {
                            Table* tab = wxDynamicCast(tabNode->GetData(), Table);
                            if(tab) {
                                retStr.append(pDb->GetDbAdapter()->GetCreateTableSql(tab, true));
                            }
                            tabNode = tabNode->GetNext();
                        }

                        tabNode = pDb->GetFirstChildNode();
                        while(tabNode) {
                            View* view = wxDynamicCast(tabNode->GetData(), View);
                            if(view) {
                                retStr.append(pDb->GetDbAdapter()->GetCreateViewSql(view, true));
                            }
                            tabNode = tabNode->GetNext();
                        }

                        tabNode = pDb->GetFirstChildNode();
                        while(tabNode) {
                            Table* tab = wxDynamicCast(tabNode->GetData(), Table);
                            if(tab) {
                                retStr.append(pDb->GetDbAdapter()->GetAlterTableConstraintSql(tab));
                            }
                            tabNode = tabNode->GetNext();
                        }

                        DumpClass dump(pDb->GetDbAdapter(), pDb, dlg.GetPath());
                        dump.DumpData();

                        wxTextFile file(dlg.GetPath());
                        if(!file.Exists()) file.Create();
                        file.Open();
                        if(file.IsOpened()) {
                            file.InsertLine(retStr, 0);
                            file.Write(wxTextFileType_None, wxConvUTF8);
                            file.Close();
                        }

                        wxMessageBox(
                            wxString::Format(_("The database has been exported to '%s'."), dlg.GetPath().GetData()),
                            _("wxDbExplorer"));
                    }
                }
            }
        } else {
            evt.Skip();
        }
    } catch(DatabaseLayerException& e) {
        wxString errorMessage = wxString::Format(_("Error (%d): %s"), e.GetErrorCode(), e.GetErrorMessage().c_str());
        wxMessageDialog dlg(this, errorMessage, _("DB Error"), wxOK | wxCENTER | wxICON_ERROR);
        dlg.ShowModal();
    } catch(...) {
        wxMessageDialog dlg(this, _("Unknown error."), _("DB Error"), wxOK | wxCENTER | wxICON_ERROR);
        dlg.ShowModal();
    }
}
bool ClassGenerateDialog::GenerateFile(Table* pTab, wxTextFile& htmpFile, wxString& hFile, const wxString& classItemName, const wxString& classItemDef, const wxString& classColName, const wxString& classTableName, const wxString& classUtilName)
{
    Constraint* pPK = NULL;
    int colCount = 0;
    int lastEditParam = 0;

    SerializableList::compatibility_iterator node = pTab->GetFirstChildNode();
    while( node ) {
        Constraint* pConstr = wxDynamicCast(node->GetData(),Constraint);
        if (pConstr) {
            if (pConstr->GetType() == Constraint::primaryKey) pPK = pConstr;
        } else colCount++;
        node = node->GetNext();
    }
    Column* pPKCol = NULL;

    if (pPK) {
        SerializableList::compatibility_iterator node = pTab->GetFirstChildNode();
        while( node ) {
            Column* pCol = wxDynamicCast(node->GetData(),Column);
            if (pCol) {
                if (pCol->GetName() == pPK->GetLocalColumn()) pPKCol = pCol;
            }
            node = node->GetNext();
        }
    }

    if( (pPKCol == NULL) && (pTab->IsView() == false) ) {
        m_textLog->AppendText( wxString::Format( _("Table %s has no primary key defined!\n"), pTab->GetName().c_str() ) );
        return false;
    }

    for ( wxString str = htmpFile.GetFirstLine(); !htmpFile.Eof(); str = htmpFile.GetNextLine() ) {
        if (str.Contains(wxT("%%classItemGetters%%"))) {
            SerializableList::compatibility_iterator node = pTab->GetFirstChildNode();
            while( node ) {
                Column* pCol = wxDynamicCast(node->GetData(),Column);
                if (pCol) {
                    hFile << wxString::Format(wxT("\tconst %s Get%s() const {"), GetResTypeName(pCol->GetType()->GetUniversalType()).c_str(), pCol->GetName().c_str()) << "\n";
                    hFile << wxString::Format(wxT("\t\treturn m_%s;"), pCol->GetName().c_str()) << "\n";
                    hFile << wxString::Format(wxT("\t\t}")) << "\n";
                }
                node = node->GetNext();
            }

        } else if (str.Contains(wxT("%%classItemVariables%%"))) {
            SerializableList::compatibility_iterator node = pTab->GetFirstChildNode();
            while( node ) {
                Column* pCol = wxDynamicCast(node->GetData(),Column);
                if (pCol) {
                    hFile << wxString::Format(wxT("\t%s m_%s;"), GetTypeName(pCol->GetType()->GetUniversalType()).c_str(), pCol->GetName().c_str())<< "\n";
                }
                node = node->GetNext();
            }

        } else if (str.Contains(wxT("%%classItemLoading%%"))) {
            SerializableList::compatibility_iterator node = pTab->GetFirstChildNode();
            while( node ) {
                Column* pCol = wxDynamicCast(node->GetData(),Column);
                if (pCol) {
                    hFile << wxString::Format(wxT("\t\tm_%s = pResult->%s(wxT(\"%s\"));"),pCol->GetName().c_str(), GetResultFunction(pCol->GetType()->GetUniversalType()).c_str(), pCol->GetName().c_str()) << "\n";
                }
                node = node->GetNext();
            }

        } else if (str.Contains(wxT("%%classItemBindings%%"))) {
            SerializableList::compatibility_iterator node = pTab->GetFirstChildNode();
            while( node ) {
                Column* pCol = wxDynamicCast(node->GetData(),Column);
                if (pCol) {
                    hFile <<  GetDebeaBinding(pCol) << "\n";
                }
                node = node->GetNext();
            }

        } else if (str.Contains(wxT("%%classItemAddParameters%%"))) {
            bool first = true;
            SerializableList::compatibility_iterator node = pTab->GetFirstChildNode();
            while( node ) {
                Column* pCol = wxDynamicCast(node->GetData(),Column);
                if (pCol) {
                    if( first ) {
                        hFile << wxString::Format(wxT("\t\t\t%s %s"), GetParamTypeName(pCol->GetType()->GetUniversalType()).c_str(), pCol->GetName().c_str()) << "\n";
                        first = false;
                    } else {
                        hFile << wxString::Format(wxT("\t\t\t,%s %s"), GetParamTypeName(pCol->GetType()->GetUniversalType()).c_str(), pCol->GetName().c_str()) << "\n";
                    }
                }
                node = node->GetNext();
            }

        } else if (str.Contains(wxT("%%classItemSetParams%%"))) {
            SerializableList::compatibility_iterator node = pTab->GetFirstChildNode();
            while( node ) {
                Column* pCol = wxDynamicCast(node->GetData(),Column);
                if (pCol ) {
                    hFile <<  wxT("\tm_") + pCol->GetName() + wxT(" = ") + pCol->GetName() + wxT(";") << "\n";
                }
                node = node->GetNext();
            }

        } else if (str.Contains(wxT("%%classColLabelFillGrid%%"))) {
            int i = 0;
            SerializableList::compatibility_iterator node = pTab->GetFirstChildNode();
            while( node ) {
                Column* pCol = wxDynamicCast(node->GetData(),Column);
                if (pCol) {
                    hFile << wxT("\t\tpGrid->AppendCols(1);")<< "\n";
                    hFile << wxString::Format(wxT("\t\tpGrid->SetColLabelValue(%i,wxT(\"%s\"));"),i++,pCol->GetName().c_str())<< "\n";
                }
                node = node->GetNext();
            }

        } else if (str.Contains(wxT("%%classColDataFillGrid%%"))) {
            int i = 0;
            SerializableList::compatibility_iterator node = pTab->GetFirstChildNode();
            while( node ) {
                Column* pCol = wxDynamicCast(node->GetData(),Column);
                if (pCol) {
                    hFile << GetFillData(pCol, i++) << "\n";
                }
                node = node->GetNext();
            }

        } else if (str.Contains(wxT("%%primaryKeyHeader%%"))) {
            if (pPKCol) {
                hFile << wxString::Format(wxT("\t/*! \\brief Return %s from db on the %s base */"),pPKCol->GetParentName().c_str(),pPKCol->GetName().c_str()) << "\n";
                hFile << wxString::Format(wxT("\tstatic %s* GetBy%s(%s %s, DatabaseLayer* pDbLayer);"),classItemName.c_str(),pPKCol->GetName().c_str(), GetTypeName(pPKCol->GetType()->GetUniversalType()).c_str(),pPKCol->GetName().c_str()) << "\n";
            }

        } else if (str.Contains(wxT("%%primaryKeyBody%%"))) {
            if (pPKCol) {
                hFile << wxString::Format(wxT("%s* %s::GetBy%s(%s %s, DatabaseLayer* pDbLayer)"),classItemName.c_str(),classItemName.c_str(),pPKCol->GetName().c_str(), GetTypeName(pPKCol->GetType()->GetUniversalType()).c_str(),pPKCol->GetName().c_str()) << "\n";
                hFile << wxT("{") << "\n";
                hFile << wxT("\tDatabaseResultSet* resSet = NULL;") << "\n";
                hFile << wxT("\tPreparedStatement* pStatement = NULL;") << "\n";
                hFile << wxT("\tif (pDbLayer){") << "\n";
                hFile << wxT("\t\tif (pDbLayer->IsOpen()){") << "\n";

                hFile << wxString::Format(wxT("\t\t\tpStatement = pDbLayer->PrepareStatement(wxT(\"SELECT * FROM %s WHERE %s = ?\"));"),classTableName.c_str(), pPKCol->GetName().c_str()) << "\n";
                hFile << wxString::Format(wxT("\t\t\tpStatement->%s(1, %s);"), GetAddParamFunction(pPKCol->GetType()->GetUniversalType()).c_str(), pPKCol->GetName().c_str()) << "\n";
                hFile << wxT("\t\t\tresSet = pStatement->RunQueryWithResults();") << "\n";
                hFile << wxT("\t\t\t}") << "\n";
                hFile << wxT("\t\t}") << "\n";

                hFile << wxT("\tif (resSet){") << "\n";
                hFile << wxString::Format(wxT("\t\tif (resSet->Next()) return new %s(resSet);"),classItemName.c_str()) << "\n";
                hFile << wxT("\t\tpStatement->Close();") << "\n";
                hFile << wxT("\t\t}") << "\n";
                hFile << wxT("\treturn NULL;") << "\n";


                hFile << wxT("}") << "\n";
            }

        } else if (str.Contains(wxT("%%classUtilsAddParameters%%"))) {
            SerializableList::compatibility_iterator node = pTab->GetFirstChildNode();
            while( node ) {
                Column* pCol = wxDynamicCast(node->GetData(),Column);
                if (pCol) {
                    hFile << wxString::Format(wxT("\t\t\t,%s %s"), GetParamTypeName(pCol->GetType()->GetUniversalType()).c_str(), pCol->GetName().c_str()) << "\n";
                }
                node = node->GetNext();
            }

        } else if (str.Contains(wxT("%%classUtilsAddParametersWithoutPK%%"))) {
            SerializableList::compatibility_iterator node = pTab->GetFirstChildNode();
            while( node ) {
                Column* pCol = wxDynamicCast(node->GetData(),Column);
                if (pCol && ( !pPKCol || (pCol->GetName() != pPKCol->GetName()) ) ) {
                    hFile << wxString::Format(wxT("\t\t\t,%s %s"), GetParamTypeName(pCol->GetType()->GetUniversalType()).c_str(), pCol->GetName().c_str()) << "\n";
                }
                node = node->GetNext();
            }

        } else if (str.Contains(wxT("%%classUtilsDeleteParameters%%"))) {
            if (pPKCol) hFile << wxString::Format(wxT("\t\t\t,%s %s"), GetParamTypeName(pPKCol->GetType()->GetUniversalType()).c_str(), pPKCol->GetName().c_str()) << "\n";

        } else if (str.Contains(wxT("%%classUtilsAddSetParams%%"))) {
            int i = 1;
            SerializableList::compatibility_iterator node = pTab->GetFirstChildNode();
            while( node ) {
                Column* pCol = wxDynamicCast(node->GetData(),Column);
                if (pCol) {
                    hFile << wxString::Format(wxT("\t\t\tpStatement->%s(%i, %s);"), GetAddParamFunction(pCol->GetType()->GetUniversalType()).c_str(),i++,pCol->GetName().c_str()) << "\n";
                }
                node = node->GetNext();
            }
            lastEditParam = i;

        } else if (str.Contains(wxT("%%classUtilsAddSetDebeaParams%%"))) {
            SerializableList::compatibility_iterator node = pTab->GetFirstChildNode();
            while( node ) {
                Column* pCol = wxDynamicCast(node->GetData(),Column);
                if (pCol && ( !pPKCol || (pCol->GetName() != pPKCol->GetName()) ) ) {
                    hFile <<  wxT("\t\tc.m_") + pCol->GetName() + wxT(" = ") + pCol->GetName() + wxT(";") << "\n";
                }
                node = node->GetNext();
            }

        } else if (str.Contains(wxT("%%classUtilsAddDelParams%%"))) {
            if (pPKCol) hFile << wxString::Format(wxT("\t\t\tpStatement->%s(%i, %s);"), GetAddParamFunction(pPKCol->GetType()->GetUniversalType()).c_str(),1,pPKCol->GetName().c_str()) << "\n";

        } else if (str.Contains(wxT("%%classUtilsAddStatement%%"))) {
            wxString cols = wxT("");
            wxString params = wxT("");
            SerializableList::compatibility_iterator node = pTab->GetFirstChildNode();
            while( node ) {
                Column* pCol = wxDynamicCast(node->GetData(),Column);
                if (pCol) {
                    if (!cols.IsEmpty()) cols = cols + wxT(",");
                    cols += pCol->GetName();

                    if (!params.IsEmpty()) params += wxT(",");
                    params += wxT("?");
                }
                node = node->GetNext();
            }
            hFile << wxString::Format(wxT("\t\tPreparedStatement* pStatement = pDbLayer->PrepareStatement(wxT(\"INSERT INTO %s (%s) VALUES (%s)\"));"),pTab->GetName().c_str(), cols.c_str(), params.c_str()) << "\n";

        } else if (str.Contains(wxT("%%classUtilsEditStatement%%"))) {
            wxString cols = wxT("");
            wxString params = wxT("");
            SerializableList::compatibility_iterator node = pTab->GetFirstChildNode();
            while( node ) {
                Column* pCol = wxDynamicCast(node->GetData(),Column);
                if (pCol) {
                    if (!cols.IsEmpty()) cols = cols + wxT(",");
                    cols += pCol->GetName() + wxT(" = ?");
                }
                node = node->GetNext();
            }
            if (pPKCol)	hFile << wxString::Format(wxT("\t\tPreparedStatement* pStatement = pDbLayer->PrepareStatement(wxT(\"UPDATE %s SET %s WHERE %s = ?\"));"),pTab->GetName().c_str(), cols.c_str(), pPKCol->GetName().c_str()) << "\n";
            else hFile << wxT("\t\tPreparedStatement* pStatement = NULL;") << "\n";

        } else if (str.Contains(wxT("%%classUtilsEditDebeaStatement%%"))) {
            SerializableList::compatibility_iterator node = pTab->GetFirstChildNode();
            while( node ) {
                Column* pCol = wxDynamicCast(node->GetData(),Column);
                if (pCol && ( !pPKCol || (pCol->GetName() != pPKCol->GetName()) ) ) {
                    hFile <<  wxT("\t\t\tc->setMember(c->m_") + pCol->GetName() + wxT(", ") + pCol->GetName() + wxT(");") << "\n";
                }
                node = node->GetNext();
            }

        } else if (str.Contains(wxT("%%classUtilsDeleteStatement%%"))) {
            if (pPKCol)	hFile << wxString::Format(wxT("\t\tPreparedStatement* pStatement = pDbLayer->PrepareStatement(wxT(\"DELETE FROM %s WHERE %s = ?\"));"),pTab->GetName().c_str(), pPKCol->GetName().c_str()) << "\n";
            else hFile << wxT("\t\tPreparedStatement* pStatement = NULL;") << "\n";

        } else if (str.Contains(wxT("%%classUtilsPKSetParams%%"))) {
            if (pPKCol) hFile << wxString::Format(wxT("\t\t\tpStatement->%s(%i, %s);"), GetAddParamFunction(pPKCol->GetType()->GetUniversalType()).c_str(),lastEditParam,pPKCol->GetName().c_str()) << "\n";

        } else if (str.Contains(wxT("%%classUtilsCreateStatement%%"))) {
            wxStringTokenizer tknz( m_pDbAdapter->GetCreateTableSql( pTab, true ), wxT("\n"), wxTOKEN_STRTOK );
            while( true ) {
                wxString line = tknz.GetNextToken();
                if( !tknz.HasMoreTokens() ) break; // omit last line
                hFile <<  wxT("\t\t\t\"") + line + wxT("\" \\")  << "\n";
            }

        } else if (str.Contains(wxT("%%classUtilsDropStatement%%"))) {
            wxStringTokenizer tknz( m_pDbAdapter->GetDropTableSql( pTab ), wxT("\n"), wxTOKEN_STRTOK );
            while( tknz.HasMoreTokens() ) {
                hFile <<  wxT("\t\t\t\"") + tknz.GetNextToken() + wxT("\" \\")  << "\n";
            }

        } else {
            str.Replace(wxT("%%classItemName%%"),classItemName);
            str.Replace(wxT("%%classItemDef%%"),classItemDef);
            str.Replace(wxT("%%classColName%%"),classColName);
            str.Replace(wxT("%%classTableName%%"),classTableName);
            str.Replace(wxT("%%classUtilName%%"), classUtilName);
            if( pPKCol ) {
                str.Replace(wxT("%%pkType%%"), GetParamTypeName(pPKCol->GetType()->GetUniversalType()));
                str.Replace(wxT("%%pkName%%"), pPKCol->GetName());
            }
            hFile << str << "\n";
        }
    }

    return true;
}