| 1 |
////////////////////////////////////////////////////////////////////////////// |
| 2 |
////////////////////////////////////////////////////////////////////////////// |
| 3 |
// |
| 4 |
// copyright : (C) 2014 Eran Ifrah |
| 5 |
// file name : database.cpp |
| 6 |
// |
| 7 |
// ------------------------------------------------------------------------- |
| 8 |
// A |
| 9 |
// _____ _ _ _ _ |
| 10 |
// / __ \ | | | | (_) | |
| 11 |
// | / \/ ___ __| | ___| | _| |_ ___ |
| 12 |
// | | / _ \ / _ |/ _ \ | | | __/ _ ) |
| 13 |
// | \__/\ (_) | (_| | __/ |___| | || __/ |
| 14 |
// \____/\___/ \__,_|\___\_____/_|\__\___| |
| 15 |
// |
| 16 |
// F i l e |
| 17 |
// |
| 18 |
// This program is free software; you can redistribute it and/or modify |
| 19 |
// it under the terms of the GNU General Public License as published by |
| 20 |
// the Free Software Foundation; either version 2 of the License, or |
| 21 |
// (at your option) any later version. |
| 22 |
// |
| 23 |
////////////////////////////////////////////////////////////////////////////// |
| 24 |
////////////////////////////////////////////////////////////////////////////// |
| 25 |
|
| 26 |
#include "database.h" |
| 27 |
#include "table.h" |
| 28 |
#include "IDbAdapter.h" |
| 29 |
XS_IMPLEMENT_CLONABLE_CLASS(Database,xsSerializable); |
| 30 |
|
| 31 |
Database::Database() |
| 32 |
{ |
| 33 |
m_name = wxT(""); |
| 34 |
m_pDbAdapter = NULL; |
| 35 |
} |
| 36 |
|
| 37 |
Database::Database(const Database& obj):xsSerializable(obj) |
| 38 |
{ |
| 39 |
m_name = obj.m_name; |
| 40 |
m_pDbAdapter = obj.m_pDbAdapter; |
| 41 |
} |
| 42 |
|
| 43 |
Database::Database(IDbAdapter* dbAdapter,const wxString& dbName) |
| 44 |
{ |
| 45 |
m_name = dbName; |
| 46 |
if (dbAdapter) { |
| 47 |
m_pDbAdapter = dbAdapter; |
| 48 |
m_pDbAdapter->GetTables(this, false); |
| 49 |
|
| 50 |
SerializableList::compatibility_iterator tabNode = GetFirstChildNode(); |
| 51 |
while(tabNode) { |
| 52 |
Table* pTab = wxDynamicCast(tabNode->GetData(), Table); |
| 53 |
if (pTab) { |
| 54 |
m_pDbAdapter->GetColumns(pTab); |
| 55 |
} |
| 56 |
tabNode = tabNode->GetNext(); |
| 57 |
} |
| 58 |
m_pDbAdapter->GetViews(this); |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
Database::~Database() |
| 63 |
{ |
| 64 |
//delete this->tables; |
| 65 |
} |
| 66 |
void Database::RefreshChildren( bool includeViews) |
| 67 |
{ |
| 68 |
GetChildrenList().DeleteContents(true); |
| 69 |
GetChildrenList().Clear(); |
| 70 |
if (m_pDbAdapter) { |
| 71 |
m_pDbAdapter->GetTables(this, includeViews); |
| 72 |
|
| 73 |
SerializableList::compatibility_iterator tabNode = GetFirstChildNode(); |
| 74 |
while(tabNode) { |
| 75 |
Table* pTab = wxDynamicCast(tabNode->GetData(), Table); |
| 76 |
if (pTab) { |
| 77 |
m_pDbAdapter->GetColumns(pTab); |
| 78 |
} |
| 79 |
tabNode = tabNode->GetNext(); |
| 80 |
} |
| 81 |
m_pDbAdapter->GetViews(this); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
void Database::RefreshChildrenDetails() |
| 86 |
{ |
| 87 |
SerializableList::compatibility_iterator tabNode = GetFirstChildNode(); |
| 88 |
while(tabNode) { |
| 89 |
Table* pTab = wxDynamicCast(tabNode->GetData(),Table); |
| 90 |
if (pTab) pTab->RefreshChildren(); |
| 91 |
tabNode = tabNode->GetNext(); |
| 92 |
} |
| 93 |
} |