Revision 33286

View differences:

trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/ConnectionJDBC.java
58 58
	private String user;
59 59
	private String _pw;
60 60

  
61
	// to cache the quote string to avoid make a query each time
62
	private String identifierQuoteString = null;
63

  
61 64
	public ConnectionJDBC() {
62 65

  
63 66
	}
......
134 137

  
135 138
	}
136 139

  
140
	/**
141
	 *
142
	 * @return the quote string for this gbdms. A empty string is returned if there are any error
143
	 * or if quoting is not supported
144
	 */
145
	public String getIdentifierQuoteString() {
146
		/* if there is not an error the quote string is cached, if there is an error an empty string
147
		 * is returned to avoid obligate the user to check this method.
148
		 */
149

  
150
		String quote = identifierQuoteString;
151
		if (quote == null) {
152
			try {
153
				quote = connection.getMetaData().getIdentifierQuoteString().trim();
154
				identifierQuoteString = quote;
155

  
156
			} catch (SQLException e) {
157
				quote = "";
158
			}
159
		}
160
		return quote;
161
	}
162

  
137 163
	public String getTypeConnection() {
138 164
		return "jdbc";
139 165
	}
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/DBLayerDefinition.java
283 283
		return schema;
284 284
	}
285 285
	/**
286
	 * @return schema.tableName or only tableName if schema is not defined
286
	 * @return "schema"."tableName" or only "tableName" if schema is not defined. schema and tableName are quoted
287 287
	 */
288 288
	public String getComposedTableName() {
289
		String quote = conn.getIdentifierQuoteString();
290

  
289 291
		String compoundTable = "";
290 292
		if (getSchema()!=null && !getSchema().equals("")){
291
			compoundTable = getSchema()+ ".";
293
			compoundTable = quote + getSchema() + quote + ".";
292 294
		}
293
		compoundTable = compoundTable+ getTableName();
295
		compoundTable = compoundTable + quote + getTableName() + quote;
294 296
		return compoundTable;
295 297
	}
296 298
	public void setIdFieldID(int idFieldID) {
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/IConnection.java
16 16

  
17 17
	String getTypeConnection();
18 18

  
19
	String getIdentifierQuoteString();
20

  
19 21
}
trunk/extensions/extJDBC/src/com/iver/cit/gvsig/fmap/drivers/jdbc/postgis/PostGisDriver.java
462 462
					return ValueFactory.createValue(character.trim());
463 463
				}else{
464 464
					return ValueFactory.createValue(character);
465
				}					
465
				}
466 466
			}
467 467
			if (metaData.getColumnType(fieldId) == Types.FLOAT)
468 468
				return ValueFactory.createValue(buf.getFloat());
......
1026 1026
        return strAux.toString();
1027 1027
	}
1028 1028

  
1029

  
1030
    /**
1031
     *       Gets all field names of a given table
1032
     * @param conn connection object
1033
     * @param table_name table name
1034
     * @return all field names of the given table
1035
     * @throws SQLException
1036
     */
1037
    public String[] getAllFields(IConnection conn, String table_name) throws DBException {
1038
    	return super.getAllFields(conn, tableNameToComposedTableName(table_name));
1039
    }
1040

  
1041
    public String[] getAllFieldTypeNames(IConnection conn, String table_name) throws DBException {
1042
    	return super.getAllFieldTypeNames(conn, tableNameToComposedTableName(table_name));
1043
    }
1044

  
1045
    /**
1046
     *
1047
     * @param tableName
1048
     * @return a string with the schema and the tableName quoted
1049
     */
1050
    private String tableNameToComposedTableName(String tableName) {
1051
    	String composedTableName = null;
1052
    	String[] tokens = tableName.trim().replace("\"", "").split("\\u002E");
1053

  
1054
    	if (tokens.length == 1) {
1055
    		composedTableName = "\"" + tokens[0] + "\"";
1056

  
1057
    	} else if (tokens.length == 2) {
1058
    		composedTableName = "\"" + tokens[0] + "\".\"" + tokens[1] + "\"";
1059
    	} else {
1060
    		// this is a not predictable case, so we return the same
1061
    		composedTableName = tableName;
1062
    	}
1063

  
1064
    	return composedTableName;
1065
    }
1066

  
1029 1067
}
trunk/extensions/extJDBC/src/com/iver/cit/gvsig/fmap/drivers/jdbc/postgis/PostGISWriter.java
102 102
			}
103 103
			((ConnectionJDBC) conex).getConnection().setAutoCommit(false);
104 104

  
105
			String schema_tablename =  lyrDef.getTableName();
106
			String schema = lyrDef.getSchema();
107
			if (schema != null || schema.trim().length() > 0 ){
108
				schema_tablename = schema + '.' + schema_tablename;
109
			}
105
			String schema_tablename = lyrDef.getComposedTableName();
110 106
			fieldManager = new JdbcFieldManager(((ConnectionJDBC)conex).getConnection(), schema_tablename);
111 107

  
112 108

  
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/MyFinishAction.java
249 249
	    	            dbLayerDef.setFieldsDesc(newFields);
250 250
	
251 251
	    	        }
252
	
253
	                // all fields to lowerCase
254
	    	     	FieldDescription field;
255
	    	     	for (int i=0;i<dbLayerDef.getFieldsDesc().length;i++){
256
	    	     		field = dbLayerDef.getFieldsDesc()[i];
257
	    	     		field.setFieldName(field.getFieldName().toLowerCase());
258
	    	     	}
259
	    	     	dbLayerDef.setFieldID(dbLayerDef.getFieldID().toLowerCase());
260
	    	     	dbLayerDef.setFieldGeometry(dbLayerDef.getFieldGeometry().toLowerCase());
261
	
252

  
262 253
	    	        dbDriver.setData(conex, dbLayerDef);
263 254
	    	        IProjection proj = null;
264 255
	    	        if (drv instanceof ICanReproject)

Also available in: Unified diff