--- FM2SQL/Attic/Convert.java 2004/03/01 12:37:10 1.41 +++ FM2SQL/Attic/Convert.java 2004/03/03 12:10:33 1.43 @@ -59,11 +59,11 @@ class Convert System.out.println("Finished!"); //convert("jdbc:fmpro:http://141.14.237.74:8050","jdbc:postgresql://erebos/test",null,null); } - public static void convertBatch(DBBean source, DBBean destination, Vector names, Vector layouts, Vector selects, Vector creates, Vector ids,int mode) throws Exception + public static void convertBatch(DBBean source, DBBean destination, Vector names, Vector layouts, Vector selects, Vector creates, Vector ids,int mode,String delimiter) throws Exception { bean = source; beanDest = destination; - convert(null,null,names,layouts,selects,creates,ids,mode); + convert(null,null,names,layouts,selects,creates,ids,mode,delimiter); if(true) return; StringBuffer command = null; try @@ -435,7 +435,7 @@ class Convert */ - public static void convert(String source, String destination, Vector names, Vector layouts, Vector selects, Vector creates, Vector ids, int mode) throws Exception + public static void convert(String source, String destination, Vector names, Vector layouts, Vector selects, Vector creates, Vector ids, int mode,String delimiter) throws Exception { FM2SQL.ProgressDialog dialog = null; @@ -667,7 +667,7 @@ class Convert if(dialog!=null) dialog.title.setText("Writing table data ..."); - command = writeDatainDestTable(dialog, command, k, pstm, rowCount); + command = writeDatainDestTable(dialog, command, k, pstm, rowCount,delimiter); endIndex = k + deltaID; } System.out.println(endIndex); @@ -688,7 +688,7 @@ class Convert bean.makeQuery(tempQuery, 0); if(dialog!=null) dialog.title.setText("Writing table data ..."); - command = writeDatainDestTable(dialog, command, endIndex, pstm, rowCount); + command = writeDatainDestTable(dialog, command, endIndex, pstm, rowCount,delimiter); } // prepare new query for next chunk if (query.indexOf("where") > 0) @@ -705,7 +705,7 @@ class Convert long startTime = System.currentTimeMillis(); bean.makeQuery(query, 0); - command = writeDatainDestTable(dialog, command, j, pstm, rowCount); + command = writeDatainDestTable(dialog, command, j, pstm, rowCount,delimiter); long endTime = System.currentTimeMillis(); System.out.println("Time for old convert elapsed " + (endTime - startTime)); @@ -748,7 +748,7 @@ class Convert * @throws Exception * @throws SQLException */ - private static StringBuffer writeDatainDestTable(FM2SQL.ProgressDialog dialog, StringBuffer command, int j, PreparedStatement pstm, int rowCount) throws Exception, SQLException + private static StringBuffer writeDatainDestTable(FM2SQL.ProgressDialog dialog, StringBuffer command, int j, PreparedStatement pstm, int rowCount,String delimiter) throws Exception, SQLException { Vector row; while ((row = bean.getNextRow()) != null) @@ -795,7 +795,7 @@ class Convert obj = row.get(k); if (obj instanceof ArrayList) if (obj instanceof ArrayList) - obj = formatFileMakerArray((List) obj," | "); + obj = formatFileMakerArray((List) obj,delimiter); String str = (obj == null) ? "NULL" : obj.toString(); if (!str.equals("NULL")) @@ -1079,6 +1079,7 @@ class Convert Vector selects = new Vector(); Vector creates = new Vector(); Vector ids = new Vector(); + String delimiter = "|"; int mode = -1; try @@ -1103,7 +1104,7 @@ class Convert Node node2 = root.find("convert/source/database/password", new int[] { 1, 1, i, 1, 1 }); Node node3 = root.find("convert/source/database", new int[] { 1, 1, i }); Node nodeMode = root.find("convert/source/database/mode", new int[] { 1, 1, i, 1, 1 }); - + Node delimiterNode =root.find("convert/source/database/delimiter", new int[] { 1, 1, i, 1, 1 }); if (node3 == null) throw new Error("parse error database tag missing"); if (node == null) @@ -1112,6 +1113,7 @@ class Convert throw new Error("parse error user tag missing"); if (node2 == null) throw new Error("parse error password tag missing"); + if(delimiterNode!=null) delimiter = delimiterNode.getCharacters(); String url = node.getCharacters(); String user = node1.getCharacters(); String password = node2.getCharacters(); @@ -1179,7 +1181,9 @@ class Convert creates.add(""); } - databases.add(new DataBase(database, tables, layouts, selects, creates, ids, mode)); + DataBase dataBase = new DataBase(database, tables, layouts, selects, creates, ids, mode); + dataBase.delimiter = delimiter; + databases.add(dataBase); } DBBean database = new DBBean(); // parse dataBase @@ -1197,7 +1201,7 @@ class Convert { DataBase db = (DataBase) iter.next(); if (mode != DataBase.UPDATE_MODE) - convertBatch(db.bean, database, db.tables, db.layouts, db.selects, db.creates, db.ids,mode); + convertBatch(db.bean, database, db.tables, db.layouts, db.selects, db.creates, db.ids,mode,db.delimiter); else update(db.bean.url, database.url, db.tables, db.layouts, db.selects, db.creates, db.ids, mode); @@ -1245,7 +1249,7 @@ class Convert Vector selects = new Vector(); Vector creates = new Vector(); Vector ids = new Vector(); - + String delimiter = "|"; int mode = -1; try { @@ -1269,7 +1273,10 @@ class Convert Node node2 = root.find("convert/source/database/password", new int[] { 1, 1, i, 1, 1 }); Node node3 = root.find("convert/source/database", new int[] { 1, 1, i }); Node nodeMode = root.find("convert/source/database/mode", new int[] { 1, 1, i, 1, 1 }); - + Node delimiterNode =root.find("convert/source/database/delimiter", new int[] { 1, 1, i, 1, 1 }); + + if(delimiterNode!=null) delimiter = delimiterNode.getCharacters(); + System.out.println("delimiter "+delimiterNode.getCharacters()); if (node3 == null) throw new Error("parse error database tag missing"); if (node == null) @@ -1297,7 +1304,6 @@ class Convert mode = DataBase.APPEND_MODE; else if (modeString.equals("update")) mode = DataBase.UPDATE_MODE; - // if(node3!=null) // System.out.println(node3.name); @@ -1347,7 +1353,9 @@ class Convert creates.add(""); } - databases.add(new DataBase(database, tables, layouts, selects, creates, ids, mode)); + DataBase dataBase=new DataBase(database, tables, layouts, selects, creates, ids, mode); + dataBase.delimiter=delimiter; + databases.add(dataBase); } DBBean database = new DBBean(); // parse dataBase @@ -1454,6 +1462,7 @@ class Convert Vector layouts; Vector tables; Vector ids; + String delimiter = "//"; final static int CONVERT_MODE = 1; final static int APPEND_MODE = 2; final static int UPDATE_MODE = 3; @@ -1473,7 +1482,7 @@ class Convert this.bean.setIDVector(ids); } /** - * writes the data contained in this object th the buffered writer + * writes the data contained in this object to the buffered writer * * @param buffr * @throws Exception */ @@ -1484,6 +1493,7 @@ class Convert buffr.write(" " + bean.url + "\n"); buffr.write(" " + bean.user + "\n"); buffr.write(" " + bean.passwd + "\n"); + buffr.write(" "+delimiter+"\n"); String modeString = ""; if (mode == CONVERT_MODE) modeString = "convert";