''Open Wiki link'' and ''Create Files for Wiki link'' every new created file creates...
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / sql / SQLStandardResultSetResults.java
index 1a21e00..6d0976d 100644 (file)
@@ -3,6 +3,7 @@ package com.quantum.sql;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.io.Reader;
 import java.io.UnsupportedEncodingException;
 import java.sql.Connection;
@@ -91,22 +92,24 @@ public class SQLStandardResultSetResults extends SQLResultSetResults implements
                                List row = new ArrayList();
                                for (int i = 1, length = columns.size(); i <= length; i++) {
                                        String value = null;
-                                       if (getColumn(i).getSize() < MAX_COLUMN_WIDTH) {
-                                               value = getEncodedString(set, getEncoding(), i);
-                                       } else {
-                                               try {
+                                       try {
+                                               if (set.getMetaData().getColumnType(i) == java.sql.Types.LONGVARBINARY) {
+                                                       value = getEncodedStringFromBinaryStream(set, getEncoding(), i);
+                                               } else  if (getColumn(i).getSize() < MAX_COLUMN_WIDTH) {
+                                                       value = getEncodedString(set, getEncoding(), i);
+                                               } else {                
                                                        if ("".equals(getEncoding())) { //$NON-NLS-1$
                                                                value = getStringFromCharacterSteam(set, i);
                                                        } else {
                                                                value = getEncodedStringFromBinaryStream(set, getEncoding(), i);
                                                        }
-                                               } catch (IOException e) {
-                                                       value = set.getString(i);
-                                               } catch (RuntimeException e) {
-                                                       // hack for mysql which doesn't implement
-                                                       // character streams
-                                                       value = set.getString(i);
                                                }
+                                       } catch (IOException e) {
+                                               value = set.getString(i);
+                                       } catch (RuntimeException e) {
+                                               // hack for mysql which doesn't implement
+                                               // character streams
+                                               value = set.getString(i);
                                        }
                                        if (value == null && !set.wasNull()) {
                                                value = set.getString(i);
@@ -153,7 +156,10 @@ public class SQLStandardResultSetResults extends SQLResultSetResults implements
                        } finally {
                                binaryStream.close();
                        }
-                       return new String(baos.toByteArray(), encoding);
+                       if ("".equals(encoding))
+                               return new String(baos.toByteArray());
+                       else
+                               return new String(baos.toByteArray(), encoding);
                } else {
                        return null;
                }
@@ -189,7 +195,6 @@ public class SQLStandardResultSetResults extends SQLResultSetResults implements
                }
        }
 
-
        /**
         * @param set
         * @param encoding
@@ -200,9 +205,12 @@ public class SQLStandardResultSetResults extends SQLResultSetResults implements
        private String getEncodedString(ResultSet set, String encoding, int index) 
                        throws SQLException {
                try {
-                       return encoding == null || encoding.trim().length() == 0 
-                               ? set.getString(index) 
-                               : new String(set.getBytes(index), encoding);
+                       if (encoding == null || encoding.trim().length() == 0) {
+                               return set.getString(index); 
+                       }
+                       byte[] colBytes = set.getBytes(index);
+                       if (colBytes == null) return null;
+                       else return new String(colBytes, encoding);
                } catch (UnsupportedEncodingException e) {
                        return set.getString(index);
                }