Commits

tbrugz committed 66991a9

sqlrun: importer: added column types 'double' & 'doublec'

Comments (0)

Files changed (2)

sqlrun.template.properties

 # sqlrun.exec.81.importdir=${basedir}
 # sqlrun.exec.81.importfiles=file.*\\.log
 # default recorddelimiter: "\n"
-# column types to be used by prepared statement (currently: only int & string)
+# column types to be used by prepared statement (currently: int, string, double, doublec (parsed as double with comma))
 sqlrun.exec.81.columntypes=int, string, int, ...
 
 # batch updates may be used (defaults is false) 
 # failover/regex: '.pattern' may be used ; /csv: '.columndelimiter' may be used
 sqlrun.exec.81.failover.1.pattern=(.+?) \\[(.+?)\\] "(.+?)" "(.+?)"
 sqlrun.exec.81.failover.1.insertsql=insert into ins_table (col1, col2, col3, col4) values (?, ?, ?, ?)
-sqlrun.exec.81.failover.1.columntypes=int, string, int, string
+sqlrun.exec.81.failover.1.columntypes=int, string, int, string, doublec
 # log or not malformed records/lines (default is true)
 sqlrun.exec.81.logmalformedline=true|false
 

src_run/tbrugz/sqldump/sqlrun/importers/AbstractImporter.java

 			}
 			
 			}
+			catch(NumberFormatException nfe) {
+				stmtSetValue(index, null);
+			}
 			catch(RuntimeException e) {
 				log.debug("error procLineInternal: i="+i+"; index="+index+" ; value='"+parts[i]+"'"
 						+(columnTypes!=null?" ; type="+columnTypes.get(index):"")
 		}
 		return s.replaceAll("\\n", " ");
 	}
-	
+
 	void stmtSetValue(int index, String value) throws SQLException {
+		if(value==null) {
+			stmt.setString(index+1, null);
+			return;
+		}
 		if(columnTypes!=null) {
 			if(columnTypes.size()>index) {
-				if(columnTypes.get(index).equals("int")) {
+				String colType = columnTypes.get(index);
+				if(colType.equals("int")) {
 					stmt.setInt(index+1, Integer.parseInt(value.trim()));
-					return;
 				}
-				//XXX: more column types (double, date, boolean, byte, long, object?, null?, ...)
+				else if(colType.equals("double")) {
+					stmt.setDouble(index+1, Double.parseDouble(value.replaceAll(",", "").trim()));
+				}
+				else if(colType.equals("doublec")) {
+					stmt.setDouble(index+1, Double.parseDouble(value.replaceAll("\\.", "").replaceAll(",", ".").trim()));
+				}
+				else if(colType.equals("string")) {
+					stmt.setString(index+1, value);
+				}
+				else {
+					log.warn("stmtSetValue: unknown columnTypes '"+colType+"' [#"+index+"] (will use 'string' type)");
+					stmt.setString(index+1, value);
+				}
+				//XXX: more column types (date, boolean, byte, long, object?, null?, ...)
+				return;
 			}
 			else {
 				log.warn("stmtSetValue: columnTypes.size() <= index [="+index+"] (will use 'string' type)");
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.