Diff for /FM2SQL/Attic/Convert.java between versions 1.51 and 1.55

version 1.51, 2004/03/23 11:57:06 version 1.55, 2004/06/01 10:29:48
Line 1 Line 1
 /*  /*
  * Convert.java -- Converter class -  Filemaker to SQL Converter    * Convert.java -- Converter class -  Filemaker to SQL Converter 
  * Copyright (C) 2004 Robert Gordesch (rogo@mpiwg-berlin.mpg.de   * Copyright (C) 2003 Robert Gordesch (rogo@mpiwg-berlin.mpg.de
  * This program is free software; you can redistribute it and/or modify it   * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the Free   * under the terms of the GNU General Public License as published by the Free
  * Software Foundation; either version 2 of the License, or (at your option)   * Software Foundation; either version 2 of the License, or (at your option)
Line 78  class Convert Line 78  class Convert
     bean = source;      bean = source;
     beanDest = destination;      beanDest = destination;
     convert(null,null,names,layouts,selects,creates,ids,mode,delimiter);      convert(null,null,names,layouts,selects,creates,ids,mode,delimiter);
     if(true) return;      if (true)
         return;
     StringBuffer command = null;      StringBuffer command = null;
     try      try
     {      {
Line 263  class Convert Line 264  class Convert
     FM2SQL.ProgressDialog dialog = null;      FM2SQL.ProgressDialog dialog = null;
     if (FM2SQL.fmInstance != null)      if (FM2SQL.fmInstance != null)
     {      {
       dialog = new FM2SQL.ProgressDialog(FM2SQL.fmInstance);        dialog = new FM2SQL.ProgressDialog(FM2SQL.fmInstance, bean);
       dialog.setTitle("Conversion running ...");        dialog.setTitle("Conversion running ...");
       dialog.title.setText("Getting table data ...");        dialog.title.setText("Getting table data ...");
       dialog.setLocation(FM2SQL.fmInstance.getLocationOnScreen().x + (FM2SQL.fmInstance.getWidth() - 400) / 2, FM2SQL.fmInstance.getLocationOnScreen().y + (FM2SQL.fmInstance.getHeight() - 250) / 2);        dialog.setLocation(FM2SQL.fmInstance.getLocationOnScreen().x + (FM2SQL.fmInstance.getWidth() - 400) / 2, FM2SQL.fmInstance.getLocationOnScreen().y + (FM2SQL.fmInstance.getHeight() - 250) / 2);
Line 462  class Convert Line 463  class Convert
    * @throws Exception     * @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    public static void convert(String source, String destination, Vector names, Vector layouts, Vector selects, Vector creates, Vector ids, int mode,String delimiter) throws Exception
   {    {
   
Line 470  class Convert Line 470  class Convert
   
     if (FM2SQL.fmInstance != null)      if (FM2SQL.fmInstance != null)
     {      {
       dialog = new FM2SQL.ProgressDialog(FM2SQL.fmInstance);        dialog = new FM2SQL.ProgressDialog(FM2SQL.fmInstance, bean);
       dialog.setTitle("Conversion running ...");        dialog.setTitle("Conversion running ...");
       dialog.title.setText("Getting table data ...");        dialog.title.setText("Getting table data ...");
       dialog.setLocation(FM2SQL.fmInstance.getLocationOnScreen().x + (FM2SQL.fmInstance.getWidth() - 400) / 2, FM2SQL.fmInstance.getLocationOnScreen().y + (FM2SQL.fmInstance.getHeight() - 250) / 2);        dialog.setLocation(FM2SQL.fmInstance.getLocationOnScreen().x + (FM2SQL.fmInstance.getWidth() - 400) / 2, FM2SQL.fmInstance.getLocationOnScreen().y + (FM2SQL.fmInstance.getHeight() - 250) / 2);
Line 483  class Convert Line 483  class Convert
     int deltaID = 1;      int deltaID = 1;
     String idField = "";      String idField = "";
     String destTableName = "";      String destTableName = "";
       String[] fieldNames = null;
     if (source != null && destination != null)      if (source != null && destination != null)
     {      {
       // setting user and passwd         // setting user and passwd 
Line 563  class Convert Line 564  class Convert
           String create =creates.get(tbIndex).toString().toLowerCase();            String create =creates.get(tbIndex).toString().toLowerCase();
           int fromIndex = create.indexOf("table")+5;            int fromIndex = create.indexOf("table")+5;
           int toIndex   = create.indexOf("(");            int toIndex   = create.indexOf("(");
             int endIndex = create.indexOf(")", toIndex);
   
           destTableName = create.substring(fromIndex,toIndex).replaceAll(beanDest.getQC(),"").trim();            destTableName = create.substring(fromIndex,toIndex).replaceAll(beanDest.getQC(),"").trim();
           System.out.println("destTable "+destTableName);            System.out.println("destTable "+destTableName);
             // retrieve field_names from select statement
             if (query.indexOf("*") < 0)
             {
               int selectEndIndex = query.indexOf("from");
               StringTokenizer tokenizer = new StringTokenizer(query.substring(6, selectEndIndex), ",");
               int numFields = tokenizer.countTokens();
               fieldNames = new String[numFields];
               int fieldIndex = 0;
               while (tokenizer.hasMoreTokens())
               {
                 String fieldName = tokenizer.nextToken().trim();
                 fieldNames[fieldIndex] = convertText(fieldName);
                 System.out.println(fieldNames[fieldIndex]);
                 fieldIndex++;
               }
                           
         } else          } else
             {
               // use create statement for field names
               StringTokenizer tokenizer = new StringTokenizer(create.substring(toIndex + 1, endIndex), ",");
               int numFields = tokenizer.countTokens();
               fieldNames = new String[numFields];
               int fieldIndex = 0;
               while (tokenizer.hasMoreTokens())
               {
                 String fieldName = tokenizer.nextToken().trim();
                 int index = fieldName.lastIndexOf(" ");
                 fieldNames[fieldIndex] = fieldName.substring(0, index);
                 System.out.println(fieldNames[fieldIndex]);
                 fieldIndex++;
               }
             }
           } else
           {
           destTableName = convertText(names.get(tbIndex).toString());            destTableName = convertText(names.get(tbIndex).toString());
   
             // retrieve field_names from select statement
             if (query.indexOf("*") < 0)
             {
               int selectEndIndex = query.indexOf("from");
               StringTokenizer tokenizer = new StringTokenizer(query.substring(6, selectEndIndex), ",");
               int numFields = tokenizer.countTokens();
               fieldNames = new String[numFields];
               int fieldIndex = 0;
               while (tokenizer.hasMoreTokens())
               {
                 String fieldName = tokenizer.nextToken().trim();
                 fieldNames[fieldIndex] = convertText(fieldName);
                // System.out.println("field "+ fieldNames[fieldIndex]);
                 fieldIndex++;
               }
   
             } else
             {
               Vector fieldNamesVec = bean.getColumnNames();
               fieldNames = new String[fieldNamesVec.size()];
               int fieldIndex = -1;
               for (Iterator iter = fieldNamesVec.iterator(); iter.hasNext();)
               {
                 String element = (String) iter.next();
                 fieldNames[++fieldIndex] = bean.getQC() + convertText(element) + bean.getQC();
                // System.out.println("field " + fieldNames[fieldIndex]);
               }
             }
           }
         if (mode == Convert.DataBase.CONVERT_MODE)          if (mode == Convert.DataBase.CONVERT_MODE)
         {          {
   
Line 644  class Convert Line 708  class Convert
         command.append(beanDest.getQC());          command.append(beanDest.getQC());
         command.append(destTableName); //convertText((String) names.get(tbIndex)));          command.append(destTableName); //convertText((String) names.get(tbIndex)));
         command.append(beanDest.getQC());          command.append(beanDest.getQC());
           command.append(" (");
           for (int i = 0; i < fieldNames.length; i++)
           {
             command.append(fieldNames[i]);
             if (i < fieldNames.length - 1)
               command.append(",");
           }
           command.append(") ");
                   
         command.append(" values ( ");          command.append(" values ( ");
   
Line 668  class Convert Line 740  class Convert
             ++counter;              ++counter;
             if (counter == 0&&dialog!=null)              if (counter == 0&&dialog!=null)
               dialog.title.setText("Check if data  is available");                dialog.title.setText("Check if data  is available");
             else              else if (dialog != null)
               if(dialog!=null)  
               dialog.title.setText("Check if more  data  is available");                dialog.title.setText("Check if more  data  is available");
             myIds = bean.getIDVector(ids.get(tbIndex).toString(), (String) names.get(tbIndex), tempQuery, numHits);              myIds = bean.getIDVector(ids.get(tbIndex).toString(), (String) names.get(tbIndex), tempQuery, numHits);
             if (myIds.isEmpty())              if (myIds.isEmpty())
Line 824  class Convert Line 895  class Convert
       for (int k = 0; k < row.size(); ++k)        for (int k = 0; k < row.size(); ++k)
       {        {
         obj = row.get(k);          obj = row.get(k);
         if (obj instanceof ArrayList)  
                 if (obj instanceof ArrayList)                  if (obj instanceof ArrayList)
              obj = formatFileMakerArray((List) obj,delimiter);               obj = formatFileMakerArray((List) obj,delimiter);
               
         String str = (obj == null) ? "NULL" : obj.toString();          String str = (obj == null) ? "NULL" : obj.toString();
         if (!str.equals("NULL"))          if (obj instanceof Double)
           {
             pstm.setDouble(k + 1, ((Double) obj).doubleValue());
           } else if (!str.equals("NULL"))
           pstm.setString(k + 1, str);            pstm.setString(k + 1, str);
         else          else
           pstm.setNull(k + 1, Types.NULL);            pstm.setNull(k + 1, Types.NULL);
Line 1144  class Convert Line 1218  class Convert
           throw new Error("parse error user tag missing");            throw new Error("parse error user tag missing");
         if (node2 == null)          if (node2 == null)
           throw new Error("parse error password tag missing");            throw new Error("parse error password tag missing");
         if(delimiterNode!=null) delimiter = delimiterNode.getCharacters();          if (delimiterNode != null)
             delimiter = delimiterNode.getCharacters();
         String url = node.getCharacters();          String url = node.getCharacters();
         String user = node1.getCharacters();          String user = node1.getCharacters();
         String password = node2.getCharacters();          String password = node2.getCharacters();
Line 1604  class Convert Line 1679  class Convert
     FM2SQL.ProgressDialog dialog = null;      FM2SQL.ProgressDialog dialog = null;
     if (FM2SQL.fmInstance != null)      if (FM2SQL.fmInstance != null)
     {      {
       dialog = new FM2SQL.ProgressDialog(FM2SQL.fmInstance);        dialog = new FM2SQL.ProgressDialog(FM2SQL.fmInstance, bean);
       dialog.setTitle("Conversion running ...");        dialog.setTitle("Conversion running ...");
       dialog.title.setText("Getting table data ...");        dialog.title.setText("Getting table data ...");
       dialog.setLocation(FM2SQL.fmInstance.getLocationOnScreen().x + (FM2SQL.fmInstance.getWidth() - 400) / 2, FM2SQL.fmInstance.getLocationOnScreen().y + (FM2SQL.fmInstance.getHeight() - 250) / 2);        dialog.setLocation(FM2SQL.fmInstance.getLocationOnScreen().x + (FM2SQL.fmInstance.getWidth() - 400) / 2, FM2SQL.fmInstance.getLocationOnScreen().y + (FM2SQL.fmInstance.getHeight() - 250) / 2);

Removed from v.1.51  
changed lines
  Added in v.1.55


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>