Hi, I did a preliminary part of the functions for copy / paste object and now I expect confirmation that the implementation is correct.
Changed files: frm/frmMain.cpp, nclude/frm/frmMain.h New files: frm/frmPasteObject.cpp, include/frm/frmPasteObject.h Best regards, Vladimir Kokovic, DP senior, Belgrade, Serbia
pgadmin3.diff
Description: Binary data
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin III - PostgreSQL Tools
//
// Copyright (C) 2002 - 2011, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// frmPasteObject.cpp - Copy/Paste object functions
//
//////////////////////////////////////////////////////////////////////////
#include <wx/wx.h>
#include "pgAdmin3.h"
#include "frm/frmPasteObject.h"
#include "schema/pgSchema.h"
#include "schema/pgTable.h"
frmPasteObject::frmPasteObject(frmMain *form, pgObject *sourceobj, pgObject *targetobj)
{
this->mainform = form;
this->sourceobj= sourceobj;
this->targetobj= targetobj;
}
wxArrayString *getSchemaTables(pgSchema *srcschema)
{
wxArrayString *objArray = new wxArrayString();
wxString query = wxT("SELECT relname ")
wxT("FROM pg_namespace n ")
wxT("LEFT JOIN pg_class c ON n.oid=c.relnamespace AND relkind='r' ")
wxT("WHERE nspname='") + srcschema->GetIdentifier() + wxT("'");
query += wxT("ORDER BY relname");
pgSet *objects = srcschema->GetDatabase()->ExecuteSet(query);
if (objects)
{
while (!objects->Eof())
{
if (!objects->GetVal(wxT("relname")).IsNull())
{
objArray->Add(objects->GetVal(wxT("relname")));
}
objects->MoveNext();
}
delete objects;
}
return objArray;
}
void frmPasteObject::process()
{
if (!sourceobj || !targetobj)
{
return;
}
wxArrayString *srcObjArray;
pgSchema *targetschema = (pgSchema *)targetobj;
pgSchema *srcschema = 0;
pgTable *table = (sourceobj->GetMetaType() == PGM_TABLE) ? (pgTable *)sourceobj : 0;
if (table)
{
wxMessageBox(
wxT("Paste source table\n") +
table->GetSchema()->GetDatabase()->GetIdentifier() + wxT(".") + table->GetSchema()->GetIdentifier() + wxT(".") + table->GetIdentifier() + wxT("\n") +
wxT(" into schema\n") + targetschema->GetDatabase()->GetIdentifier() + wxT(".") + targetschema->GetIdentifier());
}
else
{
srcschema = (pgSchema *)sourceobj;
wxMessageBox(
wxT("Paste source schema objects\n") +
srcschema->GetDatabase()->GetIdentifier() + wxT(".") + srcschema->GetIdentifier() + wxT("\n") +
wxT(" into schema\n") +
targetschema->GetDatabase()->GetIdentifier() + wxT(".") + targetschema->GetIdentifier());
}
if (!sourceobj->GetConnection() || !targetobj->GetConnection())
{
wxMessageBox(
_("Both source and target schema connections should be established before paste object operation !"));
return;
}
if (srcschema)
{
srcObjArray = ::getSchemaTables(srcschema);
}
else
{
srcObjArray = new wxArrayString();
srcObjArray->Add(table->GetIdentifier());
srcschema = table->GetSchema();
}
wxString msg;
for(unsigned int i = 0; i < srcObjArray->Count(); i++)
{
msg = wxT("COPY TABLE:") +
srcschema->GetDatabase()->GetIdentifier() + wxT(".") + srcschema->GetIdentifier() + wxT(".") + srcObjArray->Item(i) +
wxT(" INTO:") + targetschema->GetDatabase()->GetIdentifier() + wxT(".") + targetschema->GetIdentifier();
mainform->GetStatusBar()->SetStatusText(msg, 1);
//future implementation
}
msg = wxString::Format(wxT("%d TABLE(s) COPIED FROM %s TO %s"), srcObjArray->Count(),
(srcschema->GetDatabase()->GetIdentifier() + wxT(".") + srcschema->GetIdentifier()).c_str(),
(targetschema->GetDatabase()->GetIdentifier() + wxT(".") + targetschema->GetIdentifier()).c_str());
mainform->GetStatusBar()->SetStatusText(msg, 1);
delete srcObjArray;
}
frmPasteObject::~frmPasteObject()
{
}
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin III - PostgreSQL Tools
//
// Copyright (C) 2002 - 2011, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// frmPasteObject.h - Copy/Paste object functions
//
//////////////////////////////////////////////////////////////////////////
#ifndef FRMPASTEOBJECT_H
#define FRMPASTEOBJECT_H
#include "frm/frmMain.h"
#include "schema/pgObject.h"
class frmPasteObject
{
public:
frmPasteObject(frmMain *form, pgObject *sourceobj, pgObject *targetobj);
void process();
virtual ~frmPasteObject();
private:
frmMain *mainform;
pgObject *sourceobj;
pgObject *targetobj;
};
#endif /* FRMPASTEOBJECT_H */
-- Sent via pgsql-hackers mailing list ([email protected]) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers
