--- FM2SQL/Attic/Convert.java 2004/01/16 11:23:49 1.13 +++ FM2SQL/Attic/Convert.java 2004/01/26 11:29:41 1.20 @@ -1,5 +1,4 @@ - import java.util.*; import java.sql.*; import java.awt.Cursor; @@ -59,7 +58,7 @@ 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,int mode) throws Exception + public static void convertBatch(DBBean source,DBBean destination,Vector names,Vector layouts,Vector selects,Vector creates,int mode) throws Exception { /*FM2SQL.ProgressDialog dialog = new FM2SQL.ProgressDialog(FM2SQL.fmInstance); dialog.setTitle("Conversion running ..."); @@ -69,7 +68,7 @@ class Convert */ // FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); //dialog.thread=Thread.currentThread(); - bean=source; + bean = source; beanDest = destination; /* // setting user and passwd bean.setUserAndPasswd(user,passwd); @@ -382,6 +381,8 @@ class Convert dialog.title.setText("Writing table data ..."); int j = -1; + System.out.println(bean.getIDVector(ids.get(tbIndex).toString(),(String) names.get(tbIndex)).size()); + Vector row = null; command = new StringBuffer(); @@ -393,12 +394,13 @@ class Convert int size = bean.getColumnNames().size(); for (int i = 0; i < size - 1; ++i) - command.append(convertText((String)bean.getColumnNames().get(i))+" = ? "); + command.append(beanDest.getQC()+convertText((String)bean.getColumnNames().get(i))+beanDest.getQC()+" = ? ,"); command.append(convertText((String)bean.getColumnNames().get(size-1))+" = ? "); + command.append("WHERE "+convertText(ids.get(tbIndex).toString())+ " = ?"); PreparedStatement pstm = beanDest.getConnection().prepareStatement(command.toString()); - System.out.println(command); - System.exit(0); - int rowCount = bean.getRowCount(query); + System.out.println(command+" "+tbIndex); + int rowCount = bean.getRowCount(query); + int idIndex = bean.getColumnNames().indexOf(ids.get(tbIndex) ); while ((row = bean.getNextRow()) != null) { j++; @@ -440,6 +442,9 @@ class Convert else pstm.setNull(k + 1, Types.NULL); } + pstm.setString(row.size()+1,row.get(idIndex).toString()); + //System.out.println(pstm.toString()); + // System.exit(0); pstm.execute(); //stm.executeUpdate(command.toString()); if(dialog!=null) @@ -452,9 +457,12 @@ class Convert } catch (Exception e) { System.out.println("Error while connecting to database " + e); - dialog.setVisible(false); - dialog.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + if (dialog != null) + { + dialog.setVisible(false); + dialog.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + } java.io.ByteArrayOutputStream b = new java.io.ByteArrayOutputStream(); java.io.PrintStream stream = new java.io.PrintStream(b); stream.print(command + "\n\n"); @@ -462,10 +470,14 @@ class Convert FM2SQL.showErrorDialog(b.toString(), "Error occured !"); } - dialog.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + if (dialog != null) + { + dialog.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + FM2SQL.fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + + dialog.setVisible(false); + } - dialog.setVisible(false); } @@ -782,7 +794,15 @@ class Convert { alterMe.setCharAt(j, '_'); - } + } else if (alterMe.charAt(j) == '?') + { + // changed ? to _ because of update statement + alterMe.setCharAt(j,'_'); + // length = length + 1; + // j=j+1; + System.out.println(alterMe); + } + else if (alterMe.charAt(j) == '.') { if(j==length-1) @@ -974,7 +994,7 @@ class Convert Node node1 = root.find("convert/source/database/user", new int[] { 1, 1, i, 1, 1 }); 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 nodeMode = root.find("convert/source/database/mode", new int[] {1, 1, i, 1,1}); if(node3== null) throw new Error("parse error database tag missing"); if(node==null) throw new Error("parse error url tag missing"); @@ -1059,8 +1079,11 @@ class Convert for (Iterator iter = databases.iterator(); iter.hasNext();) { DataBase db = (DataBase) iter.next(); + if(mode!=DataBase.UPDATE_MODE) convertBatch(db.bean,database,db.tables,db.layouts,db.selects,db.creates,mode); - + else + update(db.bean.url,database.url,db.tables,db.layouts,db.selects,db.creates,db.ids,mode); + } // printContents(node3); // FM2SQL.fmInstance=new FM2SQL(); @@ -1390,9 +1413,11 @@ public static class DataBase this.creates = creates; this.ids = ids; this.mode = mode; + this.bean.setIDVector(ids); } public void exportToXML(BufferedWriter buffr) throws Exception { + // ids=bean.getIDVector(); buffr.write(" \n"); buffr.write(" "+bean.url+"\n"); buffr.write(" "+bean.user+"\n"); @@ -1417,7 +1442,7 @@ public static class DataBase String create=(String)creates.get(index); String id=(String)ids.get(index); - buffr.write(" \n"); + buffr.write("
\n"); buffr.write(" \n"); if(!create.equals("")) buffr.write(" "+create+" \n");