diff --git a/Release_(3.0)/pgAdmin3.exe b/Release_(3.0)/pgAdmin3.exe index 01b4a9e..54d50f7 100644 Binary files a/Release_(3.0)/pgAdmin3.exe and b/Release_(3.0)/pgAdmin3.exe differ diff --git a/ctl/ctlSQLGrid.cpp b/ctl/ctlSQLGrid.cpp index b404926..70a15c1 100644 --- a/ctl/ctlSQLGrid.cpp +++ b/ctl/ctlSQLGrid.cpp @@ -69,7 +69,7 @@ void ctlSQLGrid::OnGridColSize(wxGridSizeEvent &event) } void ctlSQLGrid::OnCopy(wxCommandEvent &ev) { - Copy(); + Copy(false); } void ctlSQLGrid::OnMouseWheel(wxMouseEvent &event) @@ -131,14 +131,18 @@ wxString ctlSQLGrid::GetExportLine(int row, wxArrayInt cols) if (GetNumberCols() == 0) return str; - + wxString colsep=settings->GetCopyColSeparator(); + if (generatesql) colsep=wxT(","); + wxString qtsimbol=settings->GetCopyQuoteChar(); + if (generatesql) qtsimbol=wxT("'"); + wxString head=wxT("insert into tbl("); for (col = 0 ; col < cols.Count() ; col++) { if (col > 0) - str.Append(settings->GetCopyColSeparator()); - + str.Append(colsep); + if (col > 0) head.Append(colsep); + head=head+GetColumnName(cols[col]); wxString text = GetCellValue(row, cols[col]); - bool needQuote = false; if (settings->GetCopyQuoting() == 1) { @@ -147,13 +151,21 @@ wxString ctlSQLGrid::GetExportLine(int row, wxArrayInt cols) else if (settings->GetCopyQuoting() == 2) /* Quote everything */ needQuote = true; - + if (text.Length()==0&&generatesql) {needQuote = false;} if (needQuote) - str.Append(settings->GetCopyQuoteChar()); + str.Append(qtsimbol); + + if (generatesql) { + if (text.Length()!=0) { + text.Replace(wxT("'"),wxT("''")); + } else text=wxT("null"); + + } str.Append(text); if (needQuote) - str.Append(settings->GetCopyQuoteChar()); + str.Append(qtsimbol); } + if (generatesql) str=head+wxT(") values (")+str+");"; return str; } @@ -180,7 +192,7 @@ void ctlSQLGrid::AppendColumnHeader(wxString &str, int start, int end) void ctlSQLGrid::AppendColumnHeader(wxString &str, wxArrayInt columns) { - if(settings->GetColumnNames()) + if(settings->GetColumnNames()&&!generatesql) { bool CopyQuoting = (settings->GetCopyQuoting() == 1 || settings->GetCopyQuoting() == 2); size_t i; @@ -202,12 +214,12 @@ void ctlSQLGrid::AppendColumnHeader(wxString &str, wxArrayInt columns) } } -int ctlSQLGrid::Copy() +int ctlSQLGrid::Copy(bool gensql) { wxString str; int copied = 0; size_t i; - + generatesql=gensql; if (GetSelectedRows().GetCount()) diff --git a/frm/frmEditGrid.cpp b/frm/frmEditGrid.cpp index a16b01a..043ee07 100644 --- a/frm/frmEditGrid.cpp +++ b/frm/frmEditGrid.cpp @@ -772,7 +772,7 @@ void frmEditGrid::OnCopy(wxCommandEvent &ev) else if(sqlGrid->GetNumberRows() > 0) { int copied; - copied = sqlGrid->Copy(); + copied = sqlGrid->Copy(false); SetStatusText(wxString::Format( wxPLURAL("Data from %d row copied to clipboard.", "Data from %d rows copied to clipboard.", copied), copied)); diff --git a/frm/frmQuery.cpp b/frm/frmQuery.cpp index bb1f3f5..22766e0 100644 --- a/frm/frmQuery.cpp +++ b/frm/frmQuery.cpp @@ -119,6 +119,7 @@ BEGIN_EVENT_TABLE(frmQuery, pgFrame) EVT_MENU(MNU_PASTE, frmQuery::OnPaste) EVT_MENU(MNU_CLEAR, frmQuery::OnClear) EVT_MENU(MNU_SUMMARY_COL, frmQuery::OnSummary_Column) + EVT_MENU(MNU_COPY_INSERT, frmQuery::OnCopy_Insert) EVT_MENU(MNU_FIND, frmQuery::OnSearchReplace) EVT_MENU(MNU_UNDO, frmQuery::OnUndo) EVT_MENU(MNU_REDO, frmQuery::OnRedo) @@ -667,7 +668,7 @@ frmQuery::frmQuery(frmMain *form, const wxString &_title, pgConn *_conn, const w wxString str; wxString filename; - wxString tempDir=wxStandardPaths::Get().GetTempDir()+wxT("\\pgadmin3\\"); + wxString tempDir=wxStandardPaths::Get().GetUserConfigDir()+wxT("\\postgresql\\recovery\\"); if (!wxDirExists(tempDir)) { wxFileName dn = tempDir; @@ -1472,7 +1473,7 @@ void frmQuery::OnCopy(wxCommandEvent &ev) { if (obj == sqlResult) { - sqlResult->Copy(); + sqlResult->Copy(false); break; } obj = obj->GetParent(); @@ -1933,6 +1934,7 @@ void frmQuery::OnLabelRightClick(wxGridEvent &event) xmenu->Append(MNU_PASTE, _("&Paste"), _("Paste data from the clipboard.")); xmenu->Append(MNU_DELETE, _("&Delete"), _("Delete selected rows.")); xmenu->Append(MNU_SUMMARY_COL, _("Summary"), _("Summary selected cells.")); + xmenu->Append(MNU_COPY_INSERT, _("Copy Insert format"), _("Copy Insert format.")); if ((rows.GetCount())) { @@ -1948,6 +1950,15 @@ void frmQuery::OnLabelRightClick(wxGridEvent &event) } sqlResult->PopupMenu(xmenu); } +void frmQuery::OnCopy_Insert(wxCommandEvent &ev) +{ +// if (currentControl() == sqlResult) + { + wxString s=wxT("Insert into format copy buffer."); + sqlResult->Copy(true); + SetStatusText(s, STATUSPOS_POS); + } +} void frmQuery::OnSummary_Column(wxCommandEvent &ev) { @@ -2058,7 +2069,7 @@ void frmQuery::SaveTempFile() wxString pref=conn->GetDbname(); //if (filename.StartsWith(pref)) filename+=wxT(".a"); - wxString tempDir=wxStandardPaths::Get().GetTempDir()+wxT("\\pgadmin3"); + wxString tempDir=wxStandardPaths::Get().GetUserConfigDir()+wxT("\\postgresql\\recovery"); wxUtfFile file(tempDir+wxT("\\")+filename, wxFile::write, modeUnicode ? wxFONTENCODING_UTF8 : wxFONTENCODING_DEFAULT); if (file.IsOpened()) { @@ -3937,7 +3948,7 @@ void frmQuery::OnSqlBookTabRDown (wxAuiNotebookEvent &event) { pref, wxOK | wxCANCEL); //setName( dlg.GetValue().wc_str() ); if (dialog.ShowModal() == wxID_OK) { - wxString tempDir=wxStandardPaths::Get().GetTempDir()+wxT("\\pgadmin3\\"); + wxString tempDir=wxStandardPaths::Get().GetUserConfigDir()+wxT("\\postgresql\\recovery\\"); wxString filename=sqlQuery->GetTitle(false); wxRemoveFile(tempDir+filename+wxT(".a")); wxString nt=dialog.GetValue(); @@ -3982,7 +3993,7 @@ void frmQuery::OnSqlBookPageClose(wxAuiNotebookEvent &event) SqlBookDisconnectPage(); //drop temp file - wxString tempDir=wxStandardPaths::Get().GetTempDir()+wxT("\\pgadmin3\\"); + wxString tempDir=wxStandardPaths::Get().GetUserConfigDir()+wxT("\\postgresql\\recovery\\"); wxString filename=sqlQuery->GetTitle(false)+wxT(".a"); if (wxFileName::FileExists(tempDir+filename)) wxRemoveFile(tempDir+filename); @@ -4063,7 +4074,7 @@ bool frmQuery::SqlBookRemovePage() SqlBookDisconnectPage(); pageidx = sqlQueryBook->GetSelection(); - wxString tempDir=wxStandardPaths::Get().GetTempDir()+wxT("\\pgadmin3\\"); + wxString tempDir=wxStandardPaths::Get().GetUserConfigDir()+wxT("\\postgresql\\recovery\\"); ctlSQLBox *box; box = wxDynamicCast(sqlQueryBook->GetPage(pageidx), ctlSQLBox); wxString filename=box->GetTitle(false); diff --git a/include/ctl/ctlSQLGrid.h b/include/ctl/ctlSQLGrid.h index 65b93e7..6c4f21a 100644 --- a/include/ctl/ctlSQLGrid.h +++ b/include/ctl/ctlSQLGrid.h @@ -30,7 +30,7 @@ public: { return false; } - int Copy(); + int Copy(bool gensql); virtual bool CheckRowPresent(int row) { @@ -46,7 +46,7 @@ public: wxString GetRowLabelValue( int row ); void SetRowGroup(int row); GroupRows *grp; - + bool generatesql; WX_DECLARE_STRING_HASH_MAP( int, ColKeySizeHashMap ); DECLARE_DYNAMIC_CLASS(ctlSQLGrid) diff --git a/include/frm/frmQuery.h b/include/frm/frmQuery.h index 5d5fb8e..c2d24ba 100644 --- a/include/frm/frmQuery.h +++ b/include/frm/frmQuery.h @@ -205,6 +205,7 @@ private: void OnPaste(wxCommandEvent &event); void OnClear(wxCommandEvent &event); void OnSummary_Column(wxCommandEvent &event); + void OnCopy_Insert(wxCommandEvent &event); void OnSearchReplace(wxCommandEvent &event); void OnUndo(wxCommandEvent &event); void OnRedo(wxCommandEvent &event); diff --git a/include/frm/menu.h b/include/frm/menu.h index 9c8be6f..cc8e9ec 100644 --- a/include/frm/menu.h +++ b/include/frm/menu.h @@ -75,6 +75,7 @@ enum MNU_TIMING, MNU_AUTOSELECTQUERY, MNU_SUMMARY_COL, + MNU_COPY_INSERT, MNU_AUTOROLLBACK, MNU_AUTOCOMMIT, MNU_CLEARHISTORY,