--- FM2SQL/src/Convert.java 2005/04/11 13:27:12 1.7 +++ FM2SQL/src/Convert.java 2005/04/19 10:49:05 1.10 @@ -119,7 +119,7 @@ class Convert final static int numIntervalls = 4; - static boolean debug =! false; + static boolean debug = !false; static boolean isGUI = true; @@ -133,7 +133,9 @@ class Convert static Vector postSQLCommands = new Vector(); - static final String versionID = new String("FM2SQL Version 0.9.0b\n"); + static final String versionID = new String("FM2SQL Version 0.9.1b\n"); + + private static boolean noError = false; public static void main(String args[]) throws IOException { @@ -144,6 +146,7 @@ class Convert * //System.out.println(new String(b,"UTF-8")); } catch * (UnsupportedEncodingException e) { e.printStackTrace(); } */ + File tmpPath = new File(System.getProperty("java.io.tmpdir")); isGUI = false; FileOutputStream file = null; if (args.length != 1) @@ -152,21 +155,34 @@ class Convert System.out.println("Usage: java Convert "); System.exit(-1); } + File temp = null; try { - File temp = File.createTempFile("fm2sql", ".txt"); + temp = new File(tmpPath, "fm2sql.txt"); + int count = 1; + while (temp.exists()) + { + temp = new File(tmpPath, "fm2sql" + generateSuffix(count++) + ".txt"); + } file = new FileOutputStream(temp); } catch (FileNotFoundException e1) { e1.printStackTrace(); } PrintStream stream = new PrintStream(file, true); + // write info for user to stdout + System.out.println(versionID); + System.out.println("Loading " + args[0] + "...."); + System.out.println("Log will be written to " + temp.getCanonicalPath()); + if (!debug) { System.setOut(stream); System.setErr(stream); } System.out.println(versionID); + System.out.println("Using config file : " + args[0] + "...."); + StringBuffer sb = readXMLFile(args[0]); parseXMLConfig(sb); if (!(new File(args[0]).exists())) @@ -248,8 +264,9 @@ class Convert String layout = (layouts.isEmpty()) ? "" : layouts.get(tbIndex).toString(); query = (selects != null) ? selects.get(tbIndex).toString() : query; // if vectors[1].get(i) != null) - if (layout != "") + if (!layout.equals("")) { + query = addLayoutToQuery(names, query, tbIndex, layout); } @@ -472,7 +489,7 @@ class Convert String layout = (layouts.isEmpty()) ? "" : layouts.get(tbIndex).toString(); query = (selects != null) ? selects.get(tbIndex).toString() : "select * from " + bean.getQC() + names.get(tbIndex).toString() + bean.getQC(); - if (layout != "") + if (layout.intern() != "") { query = addLayoutToQuery(names, query, tbIndex, layout); @@ -590,7 +607,6 @@ class Convert command.append(") "); command.append(" values ( "); - // add a question marks for every field for (int i = 0; i < bean.getColumnNames().size() - 1; ++i) command.append("?,"); @@ -687,6 +703,7 @@ class Convert long startTime = System.currentTimeMillis(); bean.makeQuery(query, 0); + System.err.println("query for whole table done"); command = writeDatainDestTable(dialog, command, j, pstm, rowCount, delimiter); long endTime = System.currentTimeMillis(); System.out.println("Time for old convert elapsed " + (endTime - startTime)); @@ -694,10 +711,12 @@ class Convert } if (isGUI) resetGUI(dialog); + noError = true; } } catch (Exception e) { - System.out.println("Error while connecting to database " + e); + System.out.println("Error while connecting to database " + e.getMessage()); + noError = false; if (isGUI) { showExceptionDialog(dialog, command, e); @@ -707,6 +726,10 @@ class Convert e.printStackTrace(); } + } catch (Error e) + { + System.out.println(e); + e.printStackTrace(); } } @@ -1017,8 +1040,25 @@ class Convert sqlCommand.executeCommand(); } int mode = db.mode; - if (mode == DataBase.CONVERT_MODE || mode == DataBase.APPEND_MODE - || mode == DataBase.CONVERT_TEMP_MODE) + if (mode == DataBase.CONVERT_TEMP_MODE) + { + convertBatch(db.bean, database, db.tables, db.layouts, db.selects, db.creates, db.ids, + mode, db.delimiter); + if (noError) + { + System.out.println("no Error occured "); + // db.bean.setURL(database.url); + // db.bean.setUserAndPasswd(database.user,database.passwd); + // + // Convert.user = db.bean.user; + // Convert.passwd = db.bean.passwd; + // userDest = database.user; + // passwdDest = database.passwd; + // synchronize(db.bean.url, database.url, db.tables, db.layouts, db.selects, db.creates, + // db.ids, mode, db.delimiter, new Vector(db.htIndex.values())); + } + } + if (mode == DataBase.CONVERT_MODE || mode == DataBase.APPEND_MODE) convertBatch(db.bean, database, db.tables, db.layouts, db.selects, db.creates, db.ids, mode, db.delimiter); else if (mode == DataBase.UPDATE_MODE) @@ -1216,9 +1256,9 @@ class Convert id = ""; if (name.equals("")) throw new Error("parse error table tag attribute must not be empty"); - tables.add(name); - layouts.add(layout); - ids.add(id); + tables.add(name.intern()); + layouts.add(layout.intern()); + ids.add(id.intern()); String query = (node5 == null) ? "" : node5.getCharacters(); if (query.equals("")) System.err.println("Warning empty select tag or select tag missing !!"); @@ -3713,7 +3753,7 @@ class Convert // retrieve field_names from select statement if (query.indexOf("*") < 0) { - int selectEndIndex = query.indexOf("from"); + int selectEndIndex = query.lastIndexOf("from"); StringTokenizer tokenizer = new StringTokenizer(query.substring(6, selectEndIndex), ","); int numFields = tokenizer.countTokens(); fieldNames = new String[numFields]; @@ -3721,7 +3761,11 @@ class Convert while (tokenizer.hasMoreTokens()) { String fieldName = tokenizer.nextToken().trim(); - fieldNames[fieldIndex] = beanDest.getQC() + convertText(fieldName) + beanDest.getQC(); + String text = convertText(fieldName); + if (text.indexOf("\"") >= 0) + fieldNames[fieldIndex] = convertText(fieldName); + else + fieldNames[fieldIndex] = beanDest.getQC() + convertText(fieldName) + beanDest.getQC(); // System.out.println("field "+ fieldNames[fieldIndex]); fieldIndex++; } @@ -3866,4 +3910,17 @@ class Convert // ****** end Test ****** } + + public final static String generateSuffix(final int step) + { + String fileString = null; + if (step < 10) + fileString = "00" + step; + else if (step < 100) + fileString = "0" + step; + else + fileString = step + ""; + return fileString; + } + } \ No newline at end of file