diff --git a/ctl/ctlSQLGrid.cpp b/ctl/ctlSQLGrid.cpp index b1535af..a61da43 100644 --- a/ctl/ctlSQLGrid.cpp +++ b/ctl/ctlSQLGrid.cpp @@ -372,6 +372,43 @@ int ctlSQLGrid::Copy(int gensql) int copied = 0; size_t i; generatesql=gensql; + //sqlResultTable* t = (sqlResultTable*)GetTable(); + wxString sql = sqlquerytext.Lower(); + int j = 0; + wxChar c; + wxString tn=wxEmptyString; + while ((j = sql.find("from", j)) > -1) { + j = j + 4; + c = sql[j]; + i = j; + while (c == ' ' || c == '\t' || c == '\n' || c == '\r') { + i++; + c = sql[i]; + } + j = i; + if (c == '(') { + continue; + } + while (c != ' ' && c != '\t' && c != '\n' && c != '\r' && c != ',' && c != '(' && c != ')') { + j++; + if (sql.Len() == j) break; + c = sql[j]; + } + tn = sql.SubString(i,j-1); // table name + if (sql.Len() == j) break; + j = j+1; + i = j; + if (sql.Len() == j) break; + c = sql[j]; + while (c > ' ' && c != ',' && c != '(' && c != ')') { + j++; + if (sql.Len() == j) break; + c = sql[j]; + } + if (j>i) tn = sql.SubString(i, j - 1); // alias name + break; + } + if (gensql == 2) linedelim = ","; else if(gensql == 3) linedelim = " or "; @@ -385,6 +422,7 @@ int ctlSQLGrid::Copy(int gensql) { tmp=GetExportLine(rows.Item(i)); if (tmp.IsEmpty()) continue; + if (!tn.IsEmpty() && (generatesql == 1)) tmp.Replace("tbl", tn, false); str.Append(tmp); if (i < rows.GetCount() - 1 && (generatesql > 1)) str.Append(linedelim); if (rows.GetCount() > 1) @@ -402,7 +440,9 @@ int ctlSQLGrid::Copy(int gensql) for (i = 0 ; i < numRows ; i++) { - str.Append(GetExportLine(i, cols)); + tmp = GetExportLine(i, cols); + if (!tn.IsEmpty() && (generatesql == 1)) tmp.Replace("tbl", tn, false); + str.Append(tmp); if (i<(numRows-1) && (generatesql > 1)) str.Append(linedelim); if (numRows > 1) str.Append(END_OF_LINE); @@ -434,8 +474,9 @@ int ctlSQLGrid::Copy(int gensql) { for (i = y1; i <= y2; i++) { - - str.Append(GetExportLine(i, x1, x2)); + tmp = GetExportLine(i, x1, x2); + if (!tn.IsEmpty() && (generatesql==1)) tmp.Replace("tbl", tn, false); + str.Append(tmp); if (i < y2 && (generatesql > 1)) str.Append(linedelim); if (y2 > y1) str.Append(END_OF_LINE); @@ -505,8 +546,9 @@ int ctlSQLGrid::Copy(int gensql) col = GetGridCursorCol(); AppendColumnHeader(str, col, col); - - str.Append(GetExportLine(row, col, col)); + tmp = GetExportLine(row, col, col); + if (!tn.IsEmpty() && (generatesql == 1)) tmp.Replace("tbl", tn, false); + str.Append(tmp); copied = 1; } } diff --git a/ctl/ctlSQLResult.cpp b/ctl/ctlSQLResult.cpp index f32aa5c..d75b383 100644 --- a/ctl/ctlSQLResult.cpp +++ b/ctl/ctlSQLResult.cpp @@ -330,7 +330,88 @@ wxString ctlSQLResult::OnGetItemText(long item, long col) const } return wxEmptyString; } +wxString ctlSQLResult::CheckSelColumnDate() +{ + size_t i; + wxString ss = wxEmptyString; + if (GetSelectedCols().GetCount()) { + wxArrayInt cols = GetSelectedCols(); + size_t numRows = GetNumberRows(); + int err = 0; + int noformat = 0; + int dtType = -1; + //AppendColumnHeader(str, cols); + //str.Append(GetExportLine(i, cols)); + for (size_t col = 0; col < cols.Count(); col++) + { + int cl = cols[col]; + bool isDt = false; + switch (colTypClasses.Item(cl)) + { + case PGTYPCLASS_DATE: + isDt= true; + } + wxDateTime dt((time_t)-1); + wxDateTime dt_prev; + wxTimeSpan sp,tmp; + bool parseDT = false; + int k = 0; + for (i = 0; i < numRows; i++) + { + if (!isDt) break; + wxString text = GetCellValue(i, cl); + if (GetRowSize(i) > 0) { + if (dtType == -1) { + if (dt.ParseISOCombined(text, ' ')) { + dtType = 0; + } + else if (dt.ParseDateTime(text)) { + dtType = 1; + } + + + } + if (dtType>=0) { + parseDT = false; + if (dtType == 0 && dt.ParseISOCombined(text, ' ')) parseDT = true; + if (dtType == 1 && dt.ParseDateTime(text)) parseDT = true; + if (parseDT) { + if (k == 0) { dt_prev = dt; k++; continue; } + tmp = dt - dt_prev; + if (k == 1) { sp = tmp; dt_prev = dt; k++; continue; } + if (tmp.GetMilliseconds() != sp.GetMilliseconds()) { + wxGridCellAttr* pAttr = new wxGridCellAttr; + + pAttr->SetBackgroundColour(*wxYELLOW); + SetRowAttr(i, pAttr); + err++; + } + dt_prev = dt; + } + else noformat++; + }; + k++; + }; + if (tmp.GetDays()>0) ss = tmp.Format("delta Days %D Hours:%H Min:%M Sec:%S"); + else if (tmp.GetHours() > 0) ss = tmp.Format("delta Hours:%H Min:%M Sec:%S"); + else if (tmp.GetMinutes() > 0) ss = tmp.Format("delta Min:%M Sec:%S"); + else if (tmp.GetSeconds() > 0) ss = tmp.Format("delta Sec:%S"); + else ss = tmp.Format("delta MSec:%l"); + + + } + } + + if (dtType==-1) ss= wxString::Format("No timestamp(date) column type",err); + else { + ss = wxString::Format("Unsequence rows: %d,bad format rows: %d,%s", err, noformat,ss); + + } + + } + return ss; +} wxString ctlSQLResult::SummaryColumn() { //ce=cells.Item(0); diff --git a/frm/frmQuery.cpp b/frm/frmQuery.cpp index c4827ef..d85a064 100644 --- a/frm/frmQuery.cpp +++ b/frm/frmQuery.cpp @@ -124,6 +124,7 @@ BEGIN_EVENT_TABLE(frmQuery, pgFrame) EVT_MENU(MNU_COPY_INLIST, frmQuery::OnCopy_InList) EVT_MENU(MNU_COPY_WHERELIST, frmQuery::OnCopy_WhereList) EVT_MENU(MNU_CLEAR_FILTER, frmQuery::OnClear_Filter) + EVT_MENU(MNU_CHECK_COLUMN_DATE, frmQuery::OnCheck_Column_Date) EVT_MENU(MNU_FIND, frmQuery::OnSearchReplace) EVT_MENU(MNU_UNDO, frmQuery::OnUndo) EVT_MENU(MNU_REDO, frmQuery::OnRedo) @@ -2092,17 +2093,23 @@ 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_CHECK_COLUMN_DATE, _("Check the sequence of dates"), _("Check the sequence of dates")); xmenu->Append(MNU_COPY_INSERT, _("Copy Insert format"), _("Copy Insert format.")); xmenu->Append(MNU_COPY_INLIST, _("IN LIST format copy"), _("Copy In list format.")); xmenu->Append(MNU_COPY_WHERELIST, _("WHERE LIST format copy"), _("Copy where list format.")); - xmenu->Append(MNU_CLEAR_FILTER, _("Clear filter"), _("Clear filter")); + + xmenu->Enable(MNU_CHECK_COLUMN_DATE, sqlResult->GetSelectedCols().GetCount() > 0); + xmenu->Enable(MNU_SUMMARY_COL, sqlResult->IsSelection()); + xmenu->Enable(MNU_COPY_INLIST, sqlResult->IsSelection()); + xmenu->Enable(MNU_COPY_WHERELIST, sqlResult->IsSelection()); if ((rows.GetCount())) { xmenu->Enable(MNU_COPY, true); xmenu->Enable(MNU_DELETE, true); xmenu->Enable(MNU_PASTE, true); + } else { @@ -2119,7 +2126,7 @@ void frmQuery::OnCopy_Insert(wxCommandEvent &ev) { wxString s=wxT("Insert into format copy buffer."); sqlResult->Copy(1); - SetStatusText(s, STATUSPOS_POS); + SetStatusText(s, STATUSPOS_MSGS); } } void frmQuery::OnCopy_InList(wxCommandEvent& ev) @@ -2128,7 +2135,7 @@ void frmQuery::OnCopy_InList(wxCommandEvent& ev) { wxString s = wxT("In list format copy buffer."); sqlResult->Copy(2); - SetStatusText(s, STATUSPOS_POS); + SetStatusText(s, STATUSPOS_MSGS); } } void frmQuery::OnCopy_WhereList(wxCommandEvent& ev) @@ -2137,7 +2144,7 @@ void frmQuery::OnCopy_WhereList(wxCommandEvent& ev) { wxString s = wxT("Where list format copy buffer."); sqlResult->Copy(3); - SetStatusText(s, STATUSPOS_POS); + SetStatusText(s, STATUSPOS_MSGS); } } void frmQuery::OnCellLeftDClick(wxGridEvent &event) @@ -2162,6 +2169,14 @@ void frmQuery::OnClear_Filter(wxCommandEvent &ev) isfilterresult=false; } } +void frmQuery::OnCheck_Column_Date(wxCommandEvent& ev) +{ + // if (currentControl() == sqlResult) + { + wxString s = sqlResult->CheckSelColumnDate(); + SetStatusText(s, STATUSPOS_MSGS); + } +} void frmQuery::OnSummary_Column(wxCommandEvent &ev) { diff --git a/include/ctl/ctlSQLGrid.h b/include/ctl/ctlSQLGrid.h index b80b366..7419c48 100644 --- a/include/ctl/ctlSQLGrid.h +++ b/include/ctl/ctlSQLGrid.h @@ -56,6 +56,7 @@ public: void SetRowGroup(int row); GroupRows *grp; int generatesql; // 0 -νες, 1 - insert , 2 - in_list + wxString sqlquerytext; WX_DECLARE_STRING_HASH_MAP( int, ColKeySizeHashMap ); DECLARE_DYNAMIC_CLASS(ctlSQLGrid) diff --git a/include/ctl/ctlSQLResult.h b/include/ctl/ctlSQLResult.h index 45e11d9..3e5796c 100644 --- a/include/ctl/ctlSQLResult.h +++ b/include/ctl/ctlSQLResult.h @@ -47,6 +47,7 @@ public: wxString OnGetItemText(long item, long col) const; wxString SummaryColumn(); + wxString CheckSelColumnDate(); void ClearFilter(); bool IsColText(int col); bool hasRowNumber() @@ -75,7 +76,6 @@ public: wxArrayString colNames; wxArrayString colTypes; wxArrayLong colTypClasses; - wxString sqlquerytext; private: pgQueryThread *thread; pgConn *conn; diff --git a/include/frm/frmQuery.h b/include/frm/frmQuery.h index efc8878..1feb48e 100644 --- a/include/frm/frmQuery.h +++ b/include/frm/frmQuery.h @@ -217,6 +217,7 @@ private: void OnCopy_InList(wxCommandEvent& event); void OnCopy_WhereList(wxCommandEvent& event); void OnClear_Filter(wxCommandEvent &event); + void OnCheck_Column_Date(wxCommandEvent& ev); 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 817bc38..e703170 100644 --- a/include/frm/menu.h +++ b/include/frm/menu.h @@ -80,6 +80,7 @@ enum MNU_COPY_INLIST, MNU_COPY_WHERELIST, MNU_CLEAR_FILTER, + MNU_CHECK_COLUMN_DATE, MNU_AUTOROLLBACK, MNU_AUTOCOMMIT, MNU_CLEARHISTORY,