From 753a14ff5a764a2b4175b56652c28389bd5f279c Mon Sep 17 00:00:00 2001 From: root Date: Sun, 17 Jan 2010 13:27:21 +0800 Subject: [PATCH] patch from Guillaume Lelarge --- pgadmin/frm/frmImport.cpp | 15 ++-- pgadmin/include/utils/pgcsvfile.h | 10 +-- pgadmin/ui/module.mk | 1 + pgadmin/utils/pgcsvfile.cpp | 115 +++++++++++++++--------------- 4 files changed, 73 insertions(+), 68 deletions(-) diff --git a/pgadmin/frm/frmImport.cpp b/pgadmin/frm/frmImport.cpp index e37f50068..702a6b529 100755 --- a/pgadmin/frm/frmImport.cpp +++ b/pgadmin/frm/frmImport.cpp @@ -1252,7 +1252,6 @@ void frmImport::OnColSettingFormatStyle(wxCommandEvent &ev) void frmImport::OnColSettingCellChange(wxGridEvent &ev) { int evrownr = ev.GetRow(); - int evcolnr = ev.GetCol(); if (m_colsettingerrnum==-1) return; @@ -1468,7 +1467,7 @@ void frmImport::ImportData() { txtLogMessages->Clear(); - if (!m_destfile && impdest==IMPDESTFCOPY || impdest==IMPDESTFINS || impdest==IMPDESTFTEST || impdest==IMPDESTFILE) + if ((!m_destfile && impdest==IMPDESTFCOPY) || impdest==IMPDESTFINS || impdest==IMPDESTFTEST || impdest==IMPDESTFILE) { wxString destfilename = txtDestFilePath->GetValue(); if (wxFile::Exists(destfilename) && !wxFile::Access(destfilename, wxFile::write)) @@ -4305,7 +4304,7 @@ bool frmImport::GenCSVSQLData(wxString& rowdatalist, wxString& rowlog, wxString* { if (haserror) rowlog.Append(END_OF_LINE); - rowlog.Append(wxString::Format(_("Column: %s can not be NULL."), *m_tgtcolsnames[dbcolidx])); + rowlog.Append(_("Column: ") + *m_tgtcolsnames[dbcolidx] + _("%s can not be NULL.")); haserror = true; rowdatalist.Append(wxT("")); } @@ -6216,7 +6215,8 @@ void frmImport::ParseColsImpSetting(int dbcolnr) else { txtColsSettingLog->AppendText(_("(Target column")); - txtColsSettingLog->AppendText(wxString::Format(wxT(" #%d: %s)"), dbcolnr, *m_tgtcolsnames[dbcolnr])); + txtColsSettingLog->AppendText(wxString::Format(wxT(" #%d: "), + dbcolnr) + *m_tgtcolsnames[dbcolnr] + wxT(")")); origsrccolnr = m_colsrccolnr[dbcolnr]; origcolerr = m_colsettingiserr[dbcolnr]; @@ -6328,11 +6328,11 @@ void frmImport::ParseColsImpSetting(int dbcolnr) m_coltrimmode[dbcolidx] = TRIMNONE; if ((formatstyle==FORMATSTYLEANSIC || (impmode==IMPORTMODEINSERT && formatstyle==FORMATSTYLEPGSQL)) && - tgtcoltype == wxT("date") || tgtcoltype == wxT("interval") || + (tgtcoltype == wxT("date") || tgtcoltype == wxT("interval") || tgtcoltype == wxT("time") || tgtcoltype == wxT("time without time zone") || tgtcoltype == wxT("timetz") || tgtcoltype == wxT("time with time zone") || tgtcoltype == wxT("timestamp") || tgtcoltype == wxT("timestamp without time zone") || - tgtcoltype == wxT("timestamptz") || tgtcoltype == wxT("timestamp with time zone")) + tgtcoltype == wxT("timestamptz") || tgtcoltype == wxT("timestamp with time zone"))) { colfmt = gridColSetting->GetCellValue(dbcolidx, FILEFMTCOLNUM); if (colfmt.IsEmpty()) @@ -6643,7 +6643,8 @@ void frmImport::ParseColsImpSetting(int dbcolnr) } else { - txtColsSettingLog->AppendText(wxString::Format(_("The setting of target column #%d: %s"), dbcolnr, *m_tgtcolsnames[dbcolnr])); + txtColsSettingLog->AppendText(wxString::Format(_("The setting of target column #%d: "), + dbcolnr) + *m_tgtcolsnames[dbcolnr]); txtColsSettingLog->AppendText(_(" has been changed.")); if (origsrccolnr!=m_colsrccolnr[dbcolnr]) diff --git a/pgadmin/include/utils/pgcsvfile.h b/pgadmin/include/utils/pgcsvfile.h index dc11ce40d..7507dc9a8 100755 --- a/pgadmin/include/utils/pgcsvfile.h +++ b/pgadmin/include/utils/pgcsvfile.h @@ -14,7 +14,7 @@ class pgCSVFile public: // Archive format enum ArchiveFormat { ARCHUNKNOWN=0, ARCHZIP=0x1, ARCHTAR=0x2, ARCHGZIP=0x4, ARCHBZIP2=0x8 }; - static const int MAXENTRYNUM = 127; + static const uint MAXENTRYNUM = 127; // Unix: LF, Dos: CR LF, Mac: CR static const wxChar LF = wxT('\n');//'LF' = 0xA = 10 static const wxChar CR = wxT('\r');//'CR' = 0xD = 13 @@ -137,7 +137,7 @@ public: bool WidthDlmIsOk() { return m_delimitedbychar || m_widthdlmisok; } void Close(); - size_t GenMoreFilePreview(wxString *pvstr = NULL); + wxFileOffset GenMoreFilePreview(wxString *pvstr = NULL); const wxString& GetFilePreview() { return m_pvfilecont; } @@ -162,14 +162,14 @@ private: bool ValidateSetting(); size_t GenCSVPreview(const bool isinit = false); - size_t MB2str(wxCSConv *txtconv, wxString *bufstr, char* inbuf, const size_t bufos, size_t& datlen); + wxFileOffset MB2str(wxCSConv *txtconv, wxString *bufstr, char* inbuf, const size_t bufos, size_t& datlen); wxString **ParseLine(const wxChar *csvdata, size_t *parsedoffset, const bool hasmore, wxString **parsedvals, size_t *curcolnr, - size_t *rsval, wxString *linedata); + wxFileOffset *rsval, wxString *linedata); wxString **ParseLine(const wxChar *csvdata, size_t *parsedoffset, const bool hasmore, wxString **parsedvals, size_t *curcolnr, bool *incolparsing, bool *inquotedblk, - size_t *rsval, size_t *filelinenum, wxString *linedata); + wxFileOffset *rsval, size_t *filelinenum, wxString *linedata); void ClearParsedLine(); void ClearPreview(); diff --git a/pgadmin/ui/module.mk b/pgadmin/ui/module.mk index ff1f272f5..50abe7606 100644 --- a/pgadmin/ui/module.mk +++ b/pgadmin/ui/module.mk @@ -77,6 +77,7 @@ TMP_ui += \ $(srcdir)/ui/frmExport.xrc \ $(srcdir)/ui/frmGrantWizard.xrc \ $(srcdir)/ui/frmHint.xrc \ + $(srcdir)/ui/frmImport.xrc \ $(srcdir)/ui/frmMaintenance.xrc \ $(srcdir)/ui/frmOptions.xrc \ $(srcdir)/ui/frmPassword.xrc \ diff --git a/pgadmin/utils/pgcsvfile.cpp b/pgadmin/utils/pgcsvfile.cpp index 86f56089e..321270997 100755 --- a/pgadmin/utils/pgcsvfile.cpp +++ b/pgadmin/utils/pgcsvfile.cpp @@ -10,7 +10,7 @@ const wxRegEx pgCSVFile::m_widthdlmregex(wxT("^([0-9]{1,6}|[Nn][Un][Ll][Ll])?(,( pgCSVFile::pgCSVFile() { m_fileencoding = wxFONTENCODING_SYSTEM; - m_fileconv = new wxCSConv(wxFONTENCODING_SYSTEM); + m_fileconv = new wxCSConv(wxFONTENCODING_SYSTEM); m_fencisok = false; m_rawfile = NULL; @@ -18,16 +18,16 @@ pgCSVFile::pgCSVFile() m_ferrmsg = _("Please specify a file."); m_settingisok = false; - m_delimitedbychar = true; - m_chardlm = DEFAULTCHARDELIMITER; + m_delimitedbychar = true; + m_chardlm = DEFAULTCHARDELIMITER; m_chardlmvals = m_chardlm.GetData(); - m_widthdlm = NULL; + m_widthdlm = NULL; m_widthdlmsnum = (size_t)0; m_widthdlmisok = false; - m_quotedby = DEFAULTQUOTEDBY; + m_quotedby = DEFAULTQUOTEDBY; m_firstrowisheader = false; - m_backslashquote = false; + m_backslashquote = false; m_pvrowsnum = DEFAULTPREVIEWROWSNUM; m_forcelinebreak = true; @@ -77,18 +77,18 @@ pgCSVFile::pgCSVFile(const wxString fpath, wxFontEncoding fileencoding, const wxString chardlm, const wxChar quotedby) { m_fileencoding = fileencoding; - m_fileconv = new wxCSConv(fileencoding); + m_fileconv = new wxCSConv(fileencoding); m_fencisok = false; - m_delimitedbychar = true; - m_chardlm = chardlm; + m_delimitedbychar = true; + m_chardlm = chardlm; m_chardlmvals = m_chardlm.GetData(); - m_widthdlm = NULL; + m_widthdlm = NULL; m_widthdlmsnum = (size_t)0; m_widthdlmisok = false; - m_firstrowisheader = false; - m_backslashquote = false; - m_quotedby = quotedby; + m_firstrowisheader = false; + m_backslashquote = false; + m_quotedby = quotedby; m_pvrowsnum = DEFAULTPREVIEWROWSNUM; m_forcelinebreak = true; @@ -106,7 +106,7 @@ pgCSVFile::pgCSVFile(const wxString fpath, wxFontEncoding fileencoding, */ pgCSVFile::~pgCSVFile() { - Close(); + Close(); if (m_widthdlm) delete []m_widthdlm; @@ -175,21 +175,21 @@ bool pgCSVFile::Open(const wxString fpath, bool isarch) { m_fileisok = false; m_ferrmsg = _("Please specify a file."); - return false; + return false; } if (!wxFile::Exists(fpath)) { m_fileisok = false; m_ferrmsg = _("File not exists."); - return false; + return false; } if (!wxFile::Access(fpath, wxFile::read)) { m_fileisok = false; m_ferrmsg = _("Failed to open the file."); - return false; + return false; } #if wxUSE_STREAMS && wxUSE_ARCHIVE_STREAMS && (wxUSE_ZIPSTREAM || wxUSE_TARSTREAM) @@ -302,7 +302,7 @@ bool pgCSVFile::Open(const wxString fpath, bool isarch) { m_fileisok = false; m_ferrmsg = _("Failed to open the file."); - return false; + return false; } m_filesize = m_rawfile->Length(); @@ -403,7 +403,7 @@ void pgCSVFile::LoadEntryList(const wxString* origentryname) entriesnum = 0; wxTarEntry *tmptarentry; m_tarentrylist = new wxTarEntry*[MAXENTRYNUM+1]; - while (tmptarentry = m_tarinstrm->GetNextEntry()) + while ((tmptarentry=m_tarinstrm->GetNextEntry())) { if (tmptarentry->IsDir()) { @@ -452,7 +452,7 @@ void pgCSVFile::LoadEntryList(const wxString* origentryname) entriesnum = 0; wxZipEntry *tmpzipentry; - while (tmpzipentry = m_zipinstrm->GetNextEntry()) + while ((tmpzipentry=m_zipinstrm->GetNextEntry())) { if (tmpzipentry->IsDir()) { @@ -703,8 +703,8 @@ void pgCSVFile::Close() if (m_rawfile) { - if (m_rawfile->IsOpened()) - m_rawfile->Close(); + if (m_rawfile->IsOpened()) + m_rawfile->Close(); delete m_rawfile; m_rawfile = NULL; @@ -908,45 +908,45 @@ void pgCSVFile::SetCharDelimiter(wxString chardlm) const wxString pgCSVFile::GetWidthDelimiterStr() { - if (!m_widthdlm) - return wxEmptyString; + if (!m_widthdlm) + return wxEmptyString; - wxString widthdlm; + wxString widthdlm; size_t dlmidx; - for (dlmidx=0; dlmidx