Menu

#1120 Export of SQL to file trimmed

3.9.0
open
nobody
None
5
2018-12-22
2013-12-18
No

Hi,

the export of a SQL result to file (csv, excel, maybe xml) is trimmed. When exporting data it is essential that the value ' 1234' is not identical to '1234'. It seems that in the source a String.trim() is done for every output written.

Discussion

  • sfst

    sfst - 2014-03-26

    Sometimes it even is practical. Can this be an export option?

     
  • Christian Hölzer

    I'm curious about your need for trimmed output, could you explain that further? I'm using it for export/import and especially key fields should not be trimmed as it is impossible to reimport the data.

     
  • sfst

    sfst - 2014-04-02

    In some databases all datafields were defined as NOT NULL, so when there isn't really any data a space is saved in those string fields. I export a lot into spreadsheets and finding any of those "blank" fields turns out to be easy because SQuirreL already trimmed them. I only import very little data compared to the volume I export.

    I agree that for keyfields it could be misleading, but in those databases I work with the keyfields are trimmed before saving.

    As I wrote, it is sometimes practical, not always, so having it as an option would allow both ways, but if I had to choose from one fixed implementaion I would prefer it untrimmed as well.

     
  • Chris B

    Chris B - 2018-04-26

    The trimming problem still exists if you save CSV or Excel.
    On the other hand leading and trailing spaces are preserved if you save XML.

    I would prefer an untrimmed export as the standard behaviour, too.
    A trimming option in the export window would be nice, though.

    I guess the trimming happens here:

    Class "net.sourceforge.squirrel_sql.fw.gui.action.exportData.DataExportCSVWriter":

    :
       public static String getDataCSV(String sepChar, String value)
       {
          if (value == null)
          {
             return "";
          }
    
          String ret = value.toString().trim();
    
          if (0 <= ret.indexOf(sepChar) || 0 <= ret.indexOf('\n') || 0 <= ret.indexOf('\r') || 0 <= ret.indexOf('"'))
          {
             ret = "\"" + ret.replaceAll("\"", "\"\"") + "\"";
          }
    
          return ret;
       }
    :
    

    And here:

    Class "net.sourceforge.squirrel_sql.fw.gui.action.exportData.DataExportExcelWriter":

    :
       private String getDataXLSAsString(Object cellObj)
       {
          if (cellObj == null)
          {
             return "";
          }
          else
          {
             return cellObj.toString().trim();
          }
       }
    :
    

    Hope that helps.

     

    Last edit: Chris B 2018-04-27

Log in to post a comment.