1 30 31 32 package org.hsqldb.util; 33 34 import java.sql.ResultSet ; 35 import java.sql.ResultSetMetaData ; 36 import java.sql.SQLException ; 37 import java.util.Hashtable ; 38 39 45 class TransferHelper { 46 47 protected TransferDb db; 48 protected Traceable tracer; 49 protected String sSchema; 50 protected JDBCTypes JDBCT; 51 private String quote; 52 53 TransferHelper() { 54 55 db = null; 56 tracer = null; 57 quote = "\'"; 58 JDBCT = new JDBCTypes(); 59 } 60 61 TransferHelper(TransferDb database, Traceable t, String q) { 62 63 db = database; 64 tracer = t; 65 quote = q; 66 JDBCT = new JDBCTypes(); 67 } 68 69 void set(TransferDb database, Traceable t, String q) { 70 71 db = database; 72 tracer = t; 73 quote = q; 74 } 75 76 String formatIdentifier(String id) { 77 78 if (id == null) { 79 return id; 80 } 81 82 if (id.equals("")) { 83 return id; 84 } 85 86 if (!Character.isLetter(id.charAt(0)) || (id.indexOf(' ') != -1)) { 87 return (quote + id + quote); 88 } 89 90 return id; 91 } 92 93 void setSchema(String _Schema) { 94 sSchema = _Schema; 95 } 96 97 String formatName(String t) { 98 99 String Name = ""; 100 101 if ((sSchema != null) && (sSchema.length() > 0)) { 102 Name = sSchema + "."; 103 } 104 105 Name += formatIdentifier(t); 106 107 return Name; 108 } 109 110 int convertFromType(int type) { 111 return (type); 112 } 113 114 int convertToType(int type) { 115 return (type); 116 } 117 118 Hashtable getSupportedTypes() { 119 120 Hashtable hTypes = new Hashtable (); 121 122 if (db != null) { 123 try { 124 ResultSet result = db.meta.getTypeInfo(); 125 126 while (result.next()) { 127 Integer intobj = new Integer (result.getShort(2)); 128 129 if (hTypes.get(intobj) == null) { 130 try { 131 hTypes.put(intobj, 132 JDBCT.toString(result.getShort(2))); 133 } catch (Exception e) {} 134 } 135 } 136 137 result.close(); 138 } catch (SQLException e) {} 139 } 140 141 if (hTypes.isEmpty()) { 142 hTypes = JDBCT.getHashtable(); 143 } 144 145 return hTypes; 146 } 147 148 String fixupColumnDefRead(TransferTable t, ResultSetMetaData meta, 149 String columnType, ResultSet columnDesc, 150 int columnIndex) throws SQLException { 151 return (columnType); 152 } 153 154 String fixupColumnDefWrite(TransferTable t, ResultSetMetaData meta, 155 String columnType, ResultSet columnDesc, 156 int columnIndex) throws SQLException { 157 return (columnType); 158 } 159 160 boolean needTransferTransaction() { 161 return (false); 162 } 163 164 Object convertColumnValue(Object value, int column, int type) { 165 return (value); 166 } 167 168 void beginDataTransfer() {} 169 170 void endDataTransfer() {} 171 172 String fixupColumnDefRead(String aTableName, ResultSetMetaData meta, 173 String columnType, ResultSet columnDesc, 174 int columnIndex) throws SQLException { 175 return columnType; 176 } 177 178 String fixupColumnDefWrite(String aTableName, ResultSetMetaData meta, 179 String columnType, ResultSet columnDesc, 180 int columnIndex) throws SQLException { 181 return columnType; 182 } 183 } 184 | Popular Tags |