Annotation of FM2SQL/DBBean.java, revision 1.25

1.11      rogo        1: /*
                      2:  * DBBean.java -- Class that ecapsulates all database actions 
                      3:  * Filemake to SQL Converter 
                      4:  * Copyright (C) 2004 Robert Gordesch (rogo@mpiwg-berlin.mpg.de) 
                      5:  * This program is free software; you can redistribute it and/or modify it
                      6:  * under the terms of the GNU General Public License as published by the Free
                      7:  * Software Foundation; either version 2 of the License, or (at your option)
                      8:  * any later version.  Please read license.txt for the full details. A copy of
                      9:  * the GPL may be found at http://www.gnu.org/copyleft/lgpl.html  You should
                     10:  * have received a copy of the GNU General Public License along with this
                     11:  * program; if not, write to the Free Software Foundation, Inc., 59 Temple
                     12:  * Place, Suite 330, Boston, MA 02111-1307 USA  Created on 15.09.2003 by
                     13:  * rogo  
                     14:  */
1.3       rogo       15: 
1.1       rogo       16: import java.sql.*;
1.15      rogo       17: import java.text.DateFormat;
1.20      rogo       18: import java.text.ParseException;
1.1       rogo       19: import java.util.*;
1.15      rogo       20: 
1.1       rogo       21: import com.fmi.jdbc.*;
                     22: 
                     23: /**
                     24:  *
                     25:  *
                     26:  * DBBean - Database bean
                     27:  *
                     28:  *<p> a Javabean  to perform queries on a JDBC Database,
                     29:  * or excute any other SQL statement
                     30:  * </p>
                     31:  * <p>
                     32:  * Usage:
                     33:  * <pre>
                     34:  *   DBBean bean = new DBBean();
                     35:  * // setting user and passwd
                     36:  *  bean.setUserAndPasswd("bla","bla");
                     37:  *  try
                     38:  *  {
                     39:  *    bean.setConnection("jdbc:fmpro:http://localhost");
                     40:  *    Vector names=bean.getTableNames();
                     41:  *    Vector[] result=bean.getQueryData(names.get(0).toString());
                     42:  *  // print results to screen
                     43:  *     for(int i=0;i&lt;result[1].size();++i)
                     44:  *     {
                     45:  *       //print Header
                     46:  *       System.out.print(" "+result[1].get(i));
                     47:  *     }
                     48:  *  System.out.println();
                     49:  *  for(int j=0;j&lt;result[0].size();++j)
                     50:  *  {
                     51:  *     Vector row=(Vector)result[0].get(j);
                     52:  *     //print rows
                     53:  *     for(int k=0;k&lt;row.size();++k)
                     54:  *     System.out.print(" "+row.get(k));
                     55:  *     System.out.println();
                     56:  *  }
                     57:  * } catch(Exception e)
                     58:  *   {
                     59:  *     System.out.println("Error while connecting to database"+ e);
                     60:  *   }
                     61:  * </pre>
                     62:  *
                     63:  * </p>
                     64:  * @author rogo
                     65:  */
                     66: public class DBBean
                     67: {
1.25    ! rogo       68:   private boolean useNormanToUnicodeMapper = false;
1.1       rogo       69:   Connection connection;
                     70:   String url = "";
                     71:   DatabaseMetaData dbMetaData;
                     72:   Vector columnNames;
1.4       rogo       73:   Vector ids = new Vector();
1.1       rogo       74:   String user = (System.getProperty("user.name") == null) ? "" : System.getProperty("user.name"); //"postgres";
                     75:   String passwd = ""; //"3333";//"rogo";
                     76:   public int maxHits = 10;
                     77:   ResultSet result;
                     78:   String quoteChar = "";
                     79:   Hashtable connectionPool = new Hashtable();
                     80:   public ResultSetMetaData metaData;
                     81:   // register DataBase Drivers
                     82:   static {
                     83:     try
                     84:     {
                     85:       DriverManager.registerDriver(new com.fmi.jdbc.JdbcDriver());
                     86:       DriverManager.registerDriver((Driver) Class.forName("org.postgresql.Driver").newInstance());
1.9       rogo       87:       DriverManager.registerDriver((Driver) Class.forName("com.mysql.jdbc.Driver").newInstance());
1.1       rogo       88:       DriverManager.registerDriver((Driver) Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance());
1.19      rogo       89:       DriverManager.registerDriver((Driver) Class.forName("acs.jdbc.Driver").newInstance());
1.25    ! rogo       90: 
1.1       rogo       91:       // wait a maximum of 10 seconds when attempting to establish a connection
                     92:       DriverManager.setLoginTimeout(10);
                     93:     } catch (Exception e)
                     94:     {
                     95:       System.out.println(e);
                     96:     }
                     97:   }
                     98:   /**
                     99:    * Constructs a database bean
                    100:    */
                    101:   public DBBean()
                    102:   {
                    103: 
                    104:   }
                    105:   /**
                    106:    *Constructs a database bean
                    107:    * and tries to connect to database
                    108:    *specified in the jdbcConnectionURL
                    109:    * @param jdbcConnectionURL url to connect to database
                    110:     */
                    111: 
                    112:   public DBBean(String jdbcConnectionURL) throws Exception
                    113:   {
                    114: 
                    115:     this.url = jdbcConnectionURL;
                    116: 
                    117:     connection = getConnection();
                    118:     if (connection == null)
                    119:       return;
                    120:     // get the meta data for the current connection
                    121:     DatabaseMetaData dbMetaData = (DatabaseMetaData) connection.getMetaData();
                    122:     quoteChar = dbMetaData.getIdentifierQuoteString();
                    123:     if (quoteChar == null)
                    124:       quoteChar = "\""; // needed for postgres
                    125: 
                    126:     // create the root node of the tree
                    127:     // get the open tables from the current connection; the FileMaker Pro
                    128:     // JDBC driver ignores all of the parameters to this method
                    129: 
                    130:     // iterate over the table names and add them to the root node of the tree
                    131: 
                    132:   }
                    133:   /**
                    134:    * sets the maximum number of hits
                    135:    */
                    136:   public void setMaxHits(int maxHits)
                    137:   {
                    138:     this.maxHits = maxHits;
                    139:   }
                    140:   /**
                    141:     * gets the maximum number of hits
                    142:     */
                    143:   public int getMaxHits()
                    144:   {
                    145:     return maxHits;
                    146:   }
                    147: 
                    148:   /**
                    149:    * returns the Connection if null creates a new one from the url property.
                    150:    *
                    151:    */
                    152:   public Connection getConnection() throws Exception
                    153:   {
                    154:     ConnectionPool conPool = (ConnectionPool) connectionPool.get(url);
                    155:     if (conPool == null)
                    156:     {
1.25    ! rogo      157:       createConnection();
        !           158: 
1.1       rogo      159:     } else
                    160:     {
                    161:       if (!conPool.user.equals(user) || !conPool.passwd.equals(passwd))
                    162:       {
                    163:         conPool.con.close();
                    164:         conPool.user = user;
                    165:         conPool.passwd = passwd;
                    166: 
                    167:       }
                    168:       connection = conPool.con;
                    169:       if (connection.isClosed())
                    170:       {
                    171:         System.out.println("Made new connection!!!");
1.25    ! rogo      172:         createConnection();
        !           173: 
        !           174:         // connection = DriverManager.getConnection(conPool.url, conPool.user, conPool.passwd);
1.1       rogo      175:         conPool.con = connection;
                    176:       }
                    177:     }
                    178:     if (url != "" && connection == null)
1.18      rogo      179:       createConnection();
1.25    ! rogo      180:     //connection = DriverManager.getConnection(url, user, passwd);
1.1       rogo      181:     dbMetaData = connection.getMetaData();
                    182:     quoteChar = dbMetaData.getIdentifierQuoteString();
                    183:     if (quoteChar == null)
                    184:       quoteChar = "\""; // needed for postgres
                    185: 
                    186:     return connection;
                    187:   }
1.18      rogo      188:   private void createConnection() throws SQLException
                    189:   {
1.25    ! rogo      190:     // setup the properties 
        !           191:     java.util.Properties prop = new java.util.Properties();
        !           192:     // prop.put("charSet", "MacCentralEurope");
        !           193:     prop.put("user", user);
        !           194:     prop.put("password", passwd);
        !           195:     System.out.println("url " + url);
        !           196:     if (url.indexOf("fmpro") >= 0)
1.18      rogo      197:     {
1.25    ! rogo      198:       // Connect to the database
1.18      rogo      199:       connection = DriverManager.getConnection(url, prop);
                    200:       System.out.println("odbc with properties inited");
1.25    ! rogo      201:     } else
        !           202:       connection = DriverManager.getConnection(url, user, passwd);
1.18      rogo      203:     connectionPool.put(url, new ConnectionPool(url, user, passwd, connection));
1.25    ! rogo      204: 
1.18      rogo      205:   }
1.1       rogo      206:   /**
                    207:    * sets the connection of this DBBean to the database specified in the url
                    208:    *  property
                    209:    */
                    210:   public void setConnection(String url) throws Exception
                    211:   {
                    212:     this.url = url;
                    213:     if (url != "")
1.18      rogo      214:       //connection = DriverManager.getConnection(url, user, passwd);
1.25    ! rogo      215:       createConnection();
1.1       rogo      216:     dbMetaData = connection.getMetaData();
                    217:     quoteChar = dbMetaData.getIdentifierQuoteString();
                    218:     if (quoteChar == null)
                    219:       quoteChar = "\""; // needed for postgres
                    220:   }
                    221:   /**
                    222:    * sets the connection of this DBBean to the database specified in the url
                    223:    * and the url,user and passwd property of this DBBean instance
                    224:    */
                    225:   public void setConnection(String url, String user, String passwd) throws Exception
                    226:   {
                    227:     this.user = user;
                    228:     this.passwd = passwd;
                    229:     this.url = url;
                    230:     if (url != "")
1.25    ! rogo      231:       createConnection();
        !           232:     // connection = DriverManager.getConnection(url, user, passwd);
1.1       rogo      233:     dbMetaData = connection.getMetaData();
                    234:     quoteChar = dbMetaData.getIdentifierQuoteString();
                    235:     if (quoteChar == null)
                    236:       quoteChar = "\""; // needed for postgres
                    237:   }
                    238: 
1.4       rogo      239:   public void setIDVector(Vector ids)
                    240:   {
                    241:     this.ids = ids;
                    242:   }
                    243: 
                    244:   /** 
                    245:    * returns a Vector containing the ID Row Name 
                    246:    **/
                    247:   public Vector getIDVector()
                    248:   {
                    249:     return ids;
                    250:   }
1.1       rogo      251:   /**
                    252:    * returns a Vector containing the Tablenames or an error message in the Vector
                    253:    */
                    254:   public Vector getTableNames()
                    255:   {
                    256:     Vector tableNameVec = new Vector();
                    257:     try
                    258:     {
                    259:       if (connection == null)
                    260:       {
                    261:         Vector vec = new Vector();
                    262:         vec.add("no database connection");
                    263:         return vec;
                    264:       }
                    265:       if (dbMetaData == null)
                    266:         dbMetaData = connection.getMetaData();
                    267:       ResultSet tableNames = dbMetaData.getTables(null, null, null, null);
                    268:       // System.out.println(dbMetaData.supportsAlterTableWithAddColumn());
                    269:       // iterate over the table names and add them to the root node of the tree
                    270: 
                    271:       while (tableNames.next())
                    272:       {
                    273:         String tableName = tableNames.getString("TABLE_NAME");
                    274:         tableNameVec.add(tableName);
                    275: 
                    276:       }
                    277:     } catch (Exception e)
                    278:     {
                    279:       e.printStackTrace();
                    280:     }
                    281:     return tableNameVec;
                    282:   }
                    283:   /**
                    284:    * returns a Vector containing the Tablenames or an error message in the Vector
                    285:    */
                    286:   public Vector getTableNames(String catalog)
                    287:   {
                    288:     Vector tableNameVec = new Vector();
                    289:     try
                    290:     {
                    291:       if (connection == null)
                    292:       {
                    293:         Vector vec = new Vector();
                    294:         vec.add("no database connection");
                    295:         return vec;
                    296:       }
                    297:       setConnection(url.substring(0, url.lastIndexOf("/") + 1) + catalog);
                    298:       if (dbMetaData == null)
                    299:         dbMetaData = connection.getMetaData();
                    300:       System.out.println("catalog " + catalog + " " + dbMetaData.getCatalogSeparator() + " " + url.substring(0, url.lastIndexOf("/") + 1));
                    301:       ResultSet tableNames = dbMetaData.getTables(null, null, null, null);
                    302:       // System.out.println(dbMetaData.supportsAlterTableWithAddColumn());
                    303:       // iterate over the table names and add them to the root node of the tree
                    304: 
                    305:       while (tableNames.next())
                    306:       {
                    307:         String tableName = tableNames.getString("TABLE_NAME");
                    308:         tableNameVec.add(tableName);
                    309: 
                    310:       }
                    311:     } catch (Exception e)
                    312:     {
                    313:       e.printStackTrace();
                    314:     }
                    315:     return tableNameVec;
                    316:   }
                    317: 
                    318:   /**
                    319:    * returns a Vector containing the Catalog or an error message in the Vector
                    320:    */
                    321:   public Vector getCatalogs()
                    322:   {
                    323:     Vector tableNameVec = new Vector();
                    324:     try
                    325:     {
                    326:       if (connection == null)
                    327:       {
                    328:         Vector vec = new Vector();
                    329:         vec.add("no database connection");
                    330:         return vec;
                    331:       }
                    332:       if (dbMetaData == null)
                    333:         dbMetaData = connection.getMetaData();
                    334:       ResultSet tableNames = dbMetaData.getCatalogs();
                    335:       // System.out.println(dbMetaData.supportsAlterTableWithAddColumn());
                    336:       // iterate over the table names and add them to the root node of the tree
                    337:       System.out.println(tableNames.getMetaData().getColumnName(1));
                    338:       while (tableNames.next())
                    339:       {
                    340:         String tableName = tableNames.getString(1);
                    341:         tableNameVec.add(tableName);
                    342:         //tableName = tableNames.getString(1);
                    343:         //tableNameVec.add(tableName);
                    344: 
                    345:       }
                    346:     } catch (Exception e)
                    347:     {
                    348:       e.printStackTrace();
                    349:     }
                    350:     return tableNameVec;
                    351:   }
                    352: 
                    353:   /**
                    354:   * returns a Vector containing the layoutNames for the specified Table
                    355:   * if the database supports this otherwise Vector containing an empty String
                    356:   */
                    357: 
                    358:   public Vector getLayoutNames(String tableName) throws SQLException
                    359:   {
                    360:     Vector layouts = new Vector();
                    361:     if (dbMetaData instanceof DatabaseMetaDataExt)
                    362:       layouts.add("");
                    363:     if (dbMetaData == null)
                    364:       dbMetaData = connection.getMetaData();
                    365: 
                    366:     if (dbMetaData instanceof DatabaseMetaDataExt)
                    367:     {
                    368:       ResultSet layoutNames = ((DatabaseMetaDataExt) dbMetaData).getLayouts(null, null, tableName, null);
                    369: 
                    370:       // iterate over the layout names and add them to the "Layouts" node
                    371:       while (layoutNames.next())
                    372:         layouts.add(layoutNames.getString("LAYOUT_NAME"));
                    373:     }
                    374:     return layouts;
                    375:   }
                    376:   /**
                    377:    *   Returns the result for select * from table
                    378:    *   with maxHits = 500 default value
                    379:    */
1.25    ! rogo      380:   public Vector[] getQueryData(String table) throws SQLException, ParseException
1.1       rogo      381:   {
                    382: 
                    383:     return getQueryData("SELECT * from " + quoteChar + table + quoteChar, maxHits);
                    384: 
                    385:   }
                    386: 
                    387:   /**
                    388:    *    Returns the result of the query
                    389:    *    or an Vector array of Vectors containing error messages
                    390:    */
                    391:   public Vector[] getQueryData(String query, FM2SQL.ProgressDialog dialog, int maxHits) throws SQLException
                    392:   {
                    393:     long timeStart = System.currentTimeMillis();
                    394:     ResultSet resultSet = null;
                    395:     if (connection == null)
                    396:     {
                    397:       Vector[] noData = new Vector[2];
                    398:       //System.out.println("Exception occured");
                    399:       noData[1] = new Vector();
                    400:       Vector vec2 = new Vector();
                    401:       noData[0] = new Vector();
                    402:       vec2.add("no Connection available");
                    403:       noData[0].add(vec2);
                    404:       noData[1].add("Exception occured! No results available");
                    405:       //noData[1].add("no Results were produced");
                    406: 
                    407:       return noData;
                    408:     }
                    409:     if (dialog != null)
                    410:       dialog.progress.setValue(0);
                    411: 
                    412:     resultSet = makeQuery(query, maxHits);
                    413: 
                    414:     metaData = resultSet.getMetaData();
                    415:     int columnCount = metaData.getColumnCount();
                    416:     int rowCount = 0;
                    417:     if (maxHits == 0)
                    418:       rowCount = (metaData instanceof ResultSetMetaDataExt) ? 1000 : getRowCount(query);
                    419:     else
                    420:       rowCount = maxHits;
                    421:     int counter = 0;
                    422:     Vector tableData = new Vector();
                    423:     Vector tableRow = new Vector();
                    424:     //  System.out.println("rowCount "+rowCount+" "+maxHits);
                    425:     try
                    426:     {
                    427:       while ((tableRow = getNextRow()) != null)
                    428:       {
                    429:         counter++;
                    430:         if (dialog != null)
                    431:           dialog.progress.setValue((int) ((double) counter / (double) rowCount * 100.0));
                    432: 
                    433:         tableData.add(tableRow);
                    434: 
                    435:       }
                    436:     } catch (Exception e)
                    437:     {
                    438:       // TODO Auto-generated catch block
                    439:       e.printStackTrace();
                    440:     }
                    441: 
                    442:     // retrieve the column names from the result set; the column names
                    443:     // are used for the table header
                    444:     columnNames = new Vector();
                    445: 
                    446:     for (int i = 1; i <= columnCount; i++)
                    447:       columnNames.addElement(metaData.getColumnName(i));
                    448:     Vector data[] = new Vector[2];
                    449:     data[0] = tableData;
                    450:     data[1] = columnNames;
                    451:     System.out.println("Rows " + tableData.size() + " " + ((Vector) tableData.get(0)).size());
                    452:     long timeEnd = System.currentTimeMillis();
                    453:     System.out.println("Time needed for query and data retrieval " + (timeEnd - timeStart) + " ms");
                    454:     return data;
                    455:   }
                    456:   /**
                    457:    *    Returns the result of the query
                    458:    *    or an Vector array of Vectors containing error messages
                    459:    */
1.20      rogo      460:   public Vector[] getQueryData(String query, int maxHits) throws SQLException, ParseException
1.1       rogo      461:   {
                    462:     long timeStart = System.currentTimeMillis();
                    463:     ResultSet resultSet = null;
                    464:     if (connection == null)
                    465:     {
                    466:       Vector[] noData = new Vector[2];
                    467:       //System.out.println("Exception occured");
                    468:       noData[1] = new Vector();
                    469:       Vector vec2 = new Vector();
                    470:       noData[0] = new Vector();
                    471:       vec2.add("no Connection available");
                    472:       noData[0].add(vec2);
                    473:       noData[1].add("Exception occured! No results available");
                    474:       //noData[1].add("no Results were produced");
                    475: 
                    476:       return noData;
                    477:     }
                    478:     resultSet = makeQuery(query, maxHits);
                    479:     metaData = resultSet.getMetaData();
                    480:     int columnCount = metaData.getColumnCount();
                    481: 
                    482:     Vector tableData = new Vector();
                    483:     while (resultSet.next())
                    484:     {
                    485:       //System.out.println("datatype "+(Types.LONGVARCHAR ==metaData.getColumnType(3)));
                    486:       Vector tableRow = new Vector(), m_columnClasses = new Vector();
                    487:       for (int i = 1; i <= columnCount; i++)
                    488:       {
                    489:         // repeating fields and fields from related databases may contain
                    490:         // multliple data values; the data values are stored using
                    491:         // a Vector which is then added to the tableRow
                    492:         //      if (metaData instanceof ResultSetMetaDataExt)
                    493:         if ((metaData instanceof ResultSetMetaDataExt) && (((ResultSetMetaDataExt) metaData).isRelated(i) || ((ResultSetMetaDataExt) metaData).isRepeating(i)))
                    494:         {
                    495:           //System.out.println("Related fields");
                    496:           // retrieve the repeating or related field contents as a
                    497:           // com.fmi.jdbc.Array via the ResultSet.getObject method
                    498:           com.fmi.jdbc.Array array = (com.fmi.jdbc.Array) resultSet.getObject(i);
                    499:           //            create a Vector for storing all of the data values
                    500:           ArrayList columnData = new ArrayList();
                    501: 
                    502:           try
                    503:           {
                    504: 
                    505:             // call the Array.getStringArray method since the data will
                    506:             // only be displayed
                    507:             Object[] fieldData = (Object[]) array.getArray();
                    508: 
                    509:             if (fieldData != null)
                    510:             {
                    511:               // add each value to the Vector
                    512:               for (int j = 0; j < fieldData.length; j++)
                    513:               {
                    514:                 if (fieldData[j] != null)
                    515:                   columnData.add(fieldData[j]);
                    516:               }
                    517: 
                    518:             }
                    519:           } catch (Exception e)
                    520:           {
                    521:             //System.out.println(e);
                    522:           }
                    523:           if (columnData.isEmpty())
                    524:             tableRow.add(null);
                    525:           else
                    526:             tableRow.addElement(columnData);
                    527:           //System.out.println(columnData);
                    528:           //System.out.println("Related fields"+columnData.size()+" "+tableRow.size());
                    529: 
                    530:           m_columnClasses.addElement(java.util.Vector.class);
                    531:         } else if (metaData.getColumnType(i) == Types.LONGVARBINARY)
                    532:         {
                    533:           // use the ResultSet.getObject method for retrieving images
                    534:           // from FileMaker Pro container fields; the ResultSet.getObject
                    535:           // method returns a java.awt.Image object for FileMaker Pro
                    536:           // container fields
                    537:           try
                    538:           {
                    539: 
                    540:             tableRow.addElement(resultSet.getObject(i));
                    541:           } catch (Exception e)
                    542:           {
                    543:             // TODO Auto-generated catch block
                    544:             //e.printStackTrace();
                    545:             tableRow.addElement(null);
                    546:           }
                    547:           //tableRow.addElement("Picture ignored");
                    548:           m_columnClasses.addElement(java.awt.Image.class);
                    549:         } else if (metaData.getColumnType(i) == Types.TIME)
                    550:         {
                    551:           // use the ResultSet.getObject method for retieving images
                    552:           // from FileMaker Pro container fields; the ResultSet.getObject
                    553:           // method returns a java.awt.Image object for FileMaker Pro
                    554:           // container fields
                    555:           try
                    556:           {
                    557:             tableRow.addElement(resultSet.getTime(i).toString());
                    558:             m_columnClasses.addElement(java.sql.Time.class);
                    559:           } catch (Exception e)
                    560:           {
                    561: 
                    562:             String value = resultSet.getString(i);
                    563:             if (value != null)
                    564:             {
                    565:               //System.out.println("SQLTime new "+Time.valueOf("17:00:00").toString());
                    566:               int index = 0;
                    567:               for (int j = 0; j < value.length(); ++j)
                    568:               {
                    569:                 if (!Character.isLetter(value.charAt(j)))
                    570:                   index = j + 1;
                    571:                 else
                    572:                   break;
                    573:               }
                    574: 
                    575:               tableRow.addElement(value.substring(0, index));
                    576:               //m_columnClasses.addElement(java.sql.Time.class);
                    577:             } else
                    578:               tableRow.add(null);
                    579:             m_columnClasses.addElement(String.class);
                    580:           } // to catch
                    581: 
                    582:         } else if (metaData.getColumnType(i) == Types.DATE)
                    583:         {
                    584:           // use the ResultSet.getObject method for retieving images
                    585:           // from FileMaker Pro container fields; the ResultSet.getObject
                    586:           // method returns a java.awt.Image object for FileMaker Pro
                    587:           // container fields
                    588: 
1.25    ! rogo      589:           try
        !           590:           {
        !           591:             tableRow.addElement(resultSet.getDate(i));
        !           592: 
        !           593:           } catch (Exception e)
        !           594:           {
        !           595:             // work around for parse bug in FM JDBC Driver 
        !           596:             // for dates of format dd-mm-yyyy
        !           597:             String date = resultSet.getString(i);
        !           598:             date = date.replace('-', '.');
        !           599:             java.text.DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, Locale.GERMAN);
        !           600:             java.util.Date d = dateFormat.parse(date);
        !           601:             // Calendar cal=Calendar.getInstance(Locale.GERMAN);
        !           602:             // cal.setTime(d);
        !           603:             // date=(cal.get(Calendar.YEAR))+"-"+(cal.get(Calendar.MONTH)+1)+"-"+cal.get(Calendar.DATE);
        !           604:             tableRow.addElement(new java.sql.Date(d.getTime()));
        !           605:             System.out.println("Date " + date);
        !           606:           }
        !           607:         } else if (metaData.getColumnTypeName(i) == "NUMBER")
1.1       rogo      608:         {
                    609:           // use the ResultSet.getObject method for retieving images
                    610:           // from FileMaker Pro container fields; the ResultSet.getObject
                    611:           // method returns a java.awt.Image object for FileMaker Pro
                    612:           // container fields
                    613:           try
                    614:           {
1.13      rogo      615:             tableRow.addElement(new Double(resultSet.getDouble(i)));
                    616:             m_columnClasses.addElement(Double.class);
1.1       rogo      617: 
                    618:           } catch (Exception e)
                    619:           {
                    620: 
                    621:             StringBuffer number = new StringBuffer();
                    622:             String value = resultSet.getString(i);
                    623:             System.out.println(value);
                    624:             for (int c = 0; c < value.length(); ++c)
                    625:             {
                    626:               if (Character.isDigit(value.charAt(c)))
                    627:               {
                    628:                 number.append(value.charAt(c));
                    629:               }
                    630:             }
                    631:             if (number.length() > 0)
                    632:             {
                    633:               tableRow.addElement(null);
1.13      rogo      634:               m_columnClasses.addElement(Double.class);
1.1       rogo      635:             } else
                    636:               tableRow.addElement(null);
                    637:           }
                    638:         } else
                    639:         {
                    640:           // all other field values are retrieved as strings and
                    641:           // added to the tableRow Vector
                    642:           // if(resultSet.getObject(i)!=null) System.out.println(resultSet.getObject(i));
                    643:           try
                    644:           {
                    645:             byte[] b = resultSet.getBytes(i);
                    646:             String utf8 = null;
                    647:             if (metaData instanceof ResultSetMetaDataExt)
                    648:               utf8 = (b == null) ? null : new String(b);
                    649:             else
                    650:               utf8 = (b == null) ? null : new String(b, "UTF-8");
                    651:             utf8 = (utf8 == null) ? null : new String(utf8.getBytes("UTF-8"), "UTF-8");
                    652:             tableRow.addElement(utf8);
                    653:           } catch (Exception e)
                    654:           {
                    655:             System.out.println("Hey I Got an error" + e);
                    656:           }
                    657:           m_columnClasses.addElement(java.lang.String.class);
                    658:         }
                    659:       }
                    660: 
                    661:       // add the tableRow Vector to the tableData Vector
                    662:       tableData.addElement(tableRow);
                    663:     }
                    664: 
                    665:     // retrieve the column names from the result set; the column names
                    666:     // are used for the table header
                    667:     columnNames = new Vector();
                    668: 
                    669:     for (int i = 1; i <= columnCount; i++)
                    670:       columnNames.addElement(metaData.getColumnName(i));
                    671:     Vector data[] = new Vector[2];
                    672:     data[0] = tableData;
                    673:     data[1] = columnNames;
                    674:     System.out.println("Rows " + tableData.size() + " " + ((Vector) tableData.get(0)).size());
                    675:     long timeEnd = System.currentTimeMillis();
                    676:     System.out.println("Time needed for query and data retrieval " + (timeEnd - timeStart) + " ms");
                    677:     return data;
                    678:   }
                    679: 
                    680:   public Vector getColumnNames()
                    681:   {
                    682:     if (result == null)
                    683:       return null;
                    684:     try
                    685:     {
                    686:       ResultSetMetaData metaData = result.getMetaData();
                    687:       int columnCount = metaData.getColumnCount();
                    688:       columnNames = new Vector();
                    689: 
                    690:       for (int i = 1; i <= columnCount; i++)
                    691:         columnNames.addElement(metaData.getColumnName(i));
                    692:     } catch (Exception e)
                    693:     {
                    694:     }
                    695:     return columnNames;
                    696:   }
                    697:   /**
                    698:    * makes the database Query
                    699:    *   with the numberOfHits as maximum
                    700:    * @return the result as an ResultSet object
                    701:   */
                    702:   public ResultSet makeQuery(String query, int numberOfHits) throws SQLException
                    703:   {
                    704:     result = null;
                    705:     Statement stm = null;
1.25    ! rogo      706: 
1.1       rogo      707:     //  System.out.println("Query " + query);
                    708: 
                    709:     if (!connection.isClosed())
                    710:       stm = connection.createStatement();
1.25    ! rogo      711:     else
        !           712:     {
        !           713: 
1.12      rogo      714:       try
                    715:       {
                    716:         connection = getConnection();
1.25    ! rogo      717:         stm = connection.createStatement();
1.12      rogo      718:       } catch (Exception e)
                    719:       {
                    720:         // TODO Auto-generated catch block
                    721:         e.printStackTrace();
                    722:       }
                    723:     }
1.1       rogo      724:     stm.setMaxRows(numberOfHits);
1.2       rogo      725:     long time = System.currentTimeMillis();
1.25    ! rogo      726:     try
        !           727:     {
        !           728:       stm.execute(query);
        !           729:       long time2 = System.currentTimeMillis();
        !           730: 
        !           731:       System.out.println("time to execute " + (time2 - time));
        !           732:       // stm.setMaxRows(numberOfHits);
        !           733: 
        !           734:       result = stm.getResultSet();
        !           735:       // System.out.println(result+" "+stm.getUpdateCount());
        !           736:       metaData = result.getMetaData();
        !           737:     } catch (Exception e)
        !           738:     {
1.19      rogo      739:       // TODO remove
1.25    ! rogo      740:       if (FM2SQL.fmInstance != null)
        !           741:         FM2SQL.showErrorDialog("Error caught!! \n Query was  " + query + " \n", "Debug Info");
        !           742:     }
        !           743: 
1.1       rogo      744:     return result;
                    745:   }
                    746:   /**
                    747:    *  sets the database user
                    748:    */
                    749:   public void setUser(String user)
                    750:   {
                    751:     this.user = user;
                    752:   }
                    753:   /**
                    754:    *     sets the database passwd
                    755:    */
                    756:   public void setPasswd(String passwd)
                    757:   {
                    758:     this.passwd = passwd;
                    759:   }
                    760: 
                    761:   /**
                    762:    * sets the database user and passwd
                    763:    */
                    764:   public void setUserAndPasswd(String user, String passwd)
                    765:   {
                    766:     this.user = user;
                    767:     this.passwd = passwd;
                    768: 
                    769:   }
                    770:   /**
                    771:    *  just  sets the connection URL
                    772:    */
                    773:   public void setURL(String url)
                    774:   {
                    775:     this.url = url;
                    776:   }
                    777: 
                    778:   /**
                    779:    *    Test the database drivers features given by the DatabaseMetaData object
                    780:    */
                    781:   public Vector[] TestDB(DatabaseMetaData d) throws SQLException
                    782:   {
                    783: 
                    784:     Vector data[] = new Vector[2];
                    785:     Vector[] rows = new Vector[120];
                    786:     for (int i = 0; i < rows.length; ++i)
                    787:       rows[i] = new Vector();
                    788:     Vector columnNames = new Vector();
                    789:     columnNames.add("Feature");
                    790:     columnNames.add("Supported");
                    791: 
                    792:     Vector cols = new Vector();
                    793:     rows[0].add("allProceduresAreCallable");
                    794:     rows[0].add(new Boolean(d.allProceduresAreCallable()));
                    795:     //boolean allProceduresAreCallable() throws SQLException;
                    796:     rows[1].add("allTablesAreSelectable");
                    797:     rows[1].add(new Boolean(d.allTablesAreSelectable()));
                    798:     //    boolean allTablesAreSelectable() throws SQLException;
                    799:     rows[2].add("isReadOnly");
                    800:     rows[2].add(new Boolean(d.isReadOnly()));
                    801:     //    boolean isReadOnly() throws SQLException;
                    802:     rows[3].add("nullsAreSortedHigh");
                    803:     rows[3].add(new Boolean(d.nullsAreSortedHigh()));
                    804:     //    boolean nullsAreSortedHigh() throws SQLException;
                    805:     rows[4].add("nullsAreSortedLow");
                    806:     rows[4].add(new Boolean(d.nullsAreSortedLow()));
                    807:     // boolean nullsAreSortedLow() throws SQLException;
                    808:     rows[5].add("nullsAreSortedAtStart");
                    809:     rows[5].add(new Boolean(d.nullsAreSortedAtStart()));
                    810:     //  boolean nullsAreSortedAtStart() throws SQLException;
                    811:     rows[6].add("nullsAreSortedAtEnd");
                    812:     rows[6].add(new Boolean(d.nullsAreSortedAtEnd()));
                    813:     //  boolean nullsAreSortedAtEnd() throws SQLException;
                    814:     rows[7].add("usesLocalFiles");
                    815:     rows[7].add(new Boolean(d.usesLocalFiles()));
                    816:     //    boolean usesLocalFiles() throws SQLException;
                    817:     rows[8].add("usesLocalFilePerTable");
                    818:     rows[8].add(new Boolean(d.usesLocalFilePerTable()));
                    819:     // boolean usesLocalFilePerTable() throws SQLException;
                    820:     rows[9].add("supportsMixedCaseIdentifiers");
                    821:     rows[9].add(new Boolean(d.supportsMixedCaseIdentifiers()));
                    822:     //boolean supportsMixedCaseIdentifiers() throws SQLException;
                    823:     rows[10].add("storesUpperCaseIdentifiers");
                    824:     rows[10].add(new Boolean(d.storesUpperCaseIdentifiers()));
                    825:     // boolean storesUpperCaseIdentifiers() throws SQLException;
                    826:     rows[11].add("storesLowerCaseIdentifiers");
                    827:     rows[11].add(new Boolean(d.storesLowerCaseIdentifiers()));
                    828:     //    boolean storesLowerCaseIdentifiers() throws SQLException;
                    829:     rows[12].add("storesMixedCaseIdentifiers");
                    830:     rows[12].add(new Boolean(d.storesMixedCaseIdentifiers()));
                    831:     //    boolean storesMixedCaseIdentifiers() throws SQLException;
                    832:     rows[13].add("supportsMixedCaseQuotedIdentifiers");
                    833:     rows[13].add(new Boolean(d.supportsMixedCaseQuotedIdentifiers()));
                    834:     //    boolean supportsMixedCaseQuotedIdentifiers() throws SQLException;
                    835:     rows[14].add("storesUpperCaseQuotedIdentifiers");
                    836:     rows[14].add(new Boolean(d.storesUpperCaseQuotedIdentifiers()));
                    837:     //   boolean storesUpperCaseQuotedIdentifiers() throws SQLException;
                    838:     rows[15].add("storesLowerCaseQuotedIdentifiers");
                    839:     rows[15].add(new Boolean(d.storesLowerCaseQuotedIdentifiers()));
                    840:     //boolean storesLowerCaseQuotedIdentifiers() throws SQLException;
                    841:     rows[16].add("storesMixedCaseQuotedIdentifiers");
                    842:     rows[16].add(new Boolean(d.storesMixedCaseQuotedIdentifiers()));
                    843:     // boolean storesMixedCaseQuotedIdentifiers() throws SQLException;
                    844:     rows[17].add("supportsAlterTableWithAddColumn");
                    845:     rows[17].add(new Boolean(d.supportsAlterTableWithAddColumn()));
                    846:     //    boolean supportsAlterTableWithAddColumn() throws SQLException;
                    847:     rows[18].add("supportsAlterTableWithDropColumn");
                    848:     rows[18].add(new Boolean(d.supportsAlterTableWithDropColumn()));
                    849:     //  boolean supportsAlterTableWithDropColumn() throws SQLException;
                    850:     rows[19].add("nullPlusNonNullIsNull");
                    851:     rows[19].add(new Boolean(d.nullPlusNonNullIsNull()));
                    852:     //   boolean nullPlusNonNullIsNull() throws SQLException;
                    853:     rows[20].add("supportsConvert");
                    854:     rows[20].add(new Boolean(d.supportsConvert()));
                    855:     // boolean supportsConvert() throws SQLException;
                    856: 
                    857:     // boolean supportsConvert(int fromType, int toType) throws SQLException;
                    858:     rows[21].add("supportsTableCorrelationNames");
                    859:     rows[21].add(new Boolean(d.supportsTableCorrelationNames()));
                    860:     //  boolean supportsTableCorrelationNames() throws SQLException;
                    861:     rows[22].add("supportsDifferentTableCorrelationNames");
                    862:     rows[22].add(new Boolean(d.supportsDifferentTableCorrelationNames()));
                    863:     // boolean supportsDifferentTableCorrelationNames() throws SQLException;
                    864:     rows[23].add("supportsExpressionsInOrderBy");
                    865:     rows[23].add(new Boolean(d.supportsExpressionsInOrderBy()));
                    866:     // boolean supportsExpressionsInOrderBy() throws SQLException;
                    867:     rows[24].add("supportsOrderByUnrelated");
                    868:     rows[24].add(new Boolean(d.supportsOrderByUnrelated()));
                    869:     //   boolean supportsOrderByUnrelated() throws SQLException;
                    870:     rows[25].add("supportsGroupBy");
                    871:     rows[25].add(new Boolean(d.supportsGroupBy()));
                    872:     //  boolean supportsGroupBy() throws SQLException;
                    873:     rows[26].add("supportsGroupByUnrelated");
                    874:     rows[26].add(new Boolean(d.supportsGroupByUnrelated()));
                    875:     // boolean supportsGroupByUnrelated() throws SQLException;
                    876:     rows[27].add("supportsGroupByBeyondSelect");
                    877:     rows[27].add(new Boolean(d.supportsGroupByBeyondSelect()));
                    878:     //  boolean supportsGroupByBeyondSelect() throws SQLException;
                    879:     rows[28].add("supportsLikeEscapeClause");
                    880:     rows[28].add(new Boolean(d.supportsLikeEscapeClause()));
                    881:     // boolean supportsLikeEscapeClause() throws SQLException;
                    882:     rows[29].add("supportsMultipleResultSets");
                    883:     rows[29].add(new Boolean(d.supportsMultipleResultSets()));
                    884:     // boolean supportsMultipleResultSets() throws SQLException;
                    885:     rows[30].add("supportsMultipleTransactions");
                    886:     rows[30].add(new Boolean(d.supportsMultipleTransactions()));
                    887:     //  boolean supportsMultipleTransactions() throws SQLException;
                    888:     rows[31].add("supportsNonNullableColumns");
                    889:     rows[31].add(new Boolean(d.supportsNonNullableColumns()));
                    890:     //    boolean supportsNonNullableColumns() throws SQLException;
                    891:     rows[32].add("supportsMinimumSQLGrammar");
                    892:     rows[32].add(new Boolean(d.supportsMinimumSQLGrammar()));
                    893:     // boolean supportsMinimumSQLGrammar() throws SQLException;
                    894:     rows[33].add("supportsCoreSQLGrammar");
                    895:     rows[33].add(new Boolean(d.supportsCoreSQLGrammar()));
                    896:     // boolean supportsCoreSQLGrammar() throws SQLException;
                    897:     rows[34].add("supportsExtendedSQLGrammar");
                    898:     rows[34].add(new Boolean(d.supportsExtendedSQLGrammar()));
                    899:     // boolean supportsExtendedSQLGrammar() throws SQLException;
                    900:     rows[35].add("supportsANSI92EntryLevelSQL");
                    901:     rows[35].add(new Boolean(d.supportsANSI92EntryLevelSQL()));
                    902:     // boolean supportsANSI92EntryLevelSQL() throws SQLException;
                    903:     rows[36].add("supportsANSI92IntermediateSQL");
                    904:     rows[36].add(new Boolean(d.supportsANSI92IntermediateSQL()));
                    905:     //boolean supportsANSI92IntermediateSQL() throws SQLException;
                    906:     rows[37].add("supportsANSI92FullSQL");
                    907:     rows[37].add(new Boolean(d.supportsANSI92FullSQL()));
                    908:     //boolean supportsANSI92FullSQL() throws SQLException;
                    909:     rows[38].add("supportsIntegrityEnhancementFacility");
                    910:     rows[38].add(new Boolean(d.supportsIntegrityEnhancementFacility()));
                    911:     //boolean supportsIntegrityEnhancementFacility() throws SQLException;
                    912:     rows[39].add("supportsOuterJoins");
                    913:     rows[39].add(new Boolean(d.supportsOuterJoins()));
                    914:     //boolean supportsOuterJoins() throws SQLException;
                    915:     rows[40].add("supportsFullOuterJoins");
                    916:     rows[40].add(new Boolean(d.supportsFullOuterJoins()));
                    917:     //boolean supportsFullOuterJoins() throws SQLException;
                    918:     rows[41].add("supportsLimitedOuterJoins");
                    919:     rows[41].add(new Boolean(d.supportsLimitedOuterJoins()));
                    920:     //boolean supportsLimitedOuterJoins() throws SQLException;
                    921:     rows[42].add("isCatalogAtStart");
                    922:     rows[42].add(new Boolean(d.isCatalogAtStart()));
                    923:     //boolean isCatalogAtStart() throws SQLException;
                    924:     rows[43].add("supportsSchemasInDataManipulation");
                    925:     rows[43].add(new Boolean(d.supportsSchemasInDataManipulation()));
                    926:     //boolean supportsSchemasInDataManipulation() throws SQLException;
                    927:     rows[44].add("supportsSchemasInProcedureCalls");
                    928:     rows[44].add(new Boolean(d.supportsSchemasInProcedureCalls()));
                    929:     //boolean supportsSchemasInProcedureCalls() throws SQLException;
                    930:     rows[45].add("supportsSchemasInTableDefinitions");
                    931:     rows[45].add(new Boolean(d.supportsSchemasInTableDefinitions()));
                    932:     //boolean supportsSchemasInTableDefinitions() throws SQLException;
                    933:     rows[46].add("supportsSchemasInIndexDefinitions");
                    934:     rows[46].add(new Boolean(d.supportsSchemasInIndexDefinitions()));
                    935:     //boolean supportsSchemasInIndexDefinitions() throws SQLException;
                    936:     rows[47].add("supportsSchemasInPrivilegeDefinitions");
                    937:     rows[47].add(new Boolean(d.supportsSchemasInPrivilegeDefinitions()));
                    938:     //boolean supportsSchemasInPrivilegeDefinitions() throws SQLException;
                    939:     rows[48].add("supportsCatalogsInDataManipulation");
                    940:     rows[48].add(new Boolean(d.supportsCatalogsInDataManipulation()));
                    941:     //boolean supportsCatalogsInDataManipulation() throws SQLException;
                    942:     rows[49].add("supportsCatalogsInProcedureCalls");
                    943:     rows[49].add(new Boolean(d.supportsCatalogsInProcedureCalls()));
                    944:     //boolean supportsCatalogsInProcedureCalls() throws SQLException;
                    945:     rows[50].add("supportsCatalogsInTableDefinitions");
                    946:     rows[50].add(new Boolean(d.supportsCatalogsInTableDefinitions()));
                    947:     //boolean supportsCatalogsInTableDefinitions() throws SQLException;
                    948:     rows[51].add("supportsCatalogsInIndexDefinitions");
                    949:     rows[51].add(new Boolean(d.supportsCatalogsInIndexDefinitions()));
                    950:     //boolean supportsCatalogsInIndexDefinitions() throws SQLException;
                    951:     rows[52].add("supportsCatalogsInPrivilegeDefinitions");
                    952:     rows[52].add(new Boolean(d.supportsCatalogsInPrivilegeDefinitions()));
                    953:     //boolean supportsCatalogsInPrivilegeDefinitions() throws SQLException;
                    954:     rows[53].add("supportsPositionedDelete");
                    955:     rows[53].add(new Boolean(d.supportsPositionedDelete()));
                    956:     //boolean supportsPositionedDelete() throws SQLException;
                    957:     rows[54].add("supportsPositionedUpdate");
                    958:     rows[54].add(new Boolean(d.supportsPositionedUpdate()));
                    959:     //boolean supportsPositionedUpdate() throws SQLException;
                    960:     rows[55].add("supportsSelectForUpdate");
                    961:     rows[55].add(new Boolean(d.supportsSelectForUpdate()));
                    962:     //boolean supportsSelectForUpdate() throws SQLException;
                    963:     rows[56].add("supportsStoredProcedures");
                    964:     rows[56].add(new Boolean(d.supportsStoredProcedures()));
                    965:     //boolean supportsStoredProcedures() throws SQLException;
                    966:     rows[57].add("supportsSubqueriesInComparisons");
                    967:     rows[57].add(new Boolean(d.supportsSubqueriesInComparisons()));
                    968:     //boolean supportsSubqueriesInComparisons() throws SQLException;
                    969:     rows[58].add("supportsSubqueriesInExists");
                    970:     rows[58].add(new Boolean(d.supportsSubqueriesInExists()));
                    971:     //boolean supportsSubqueriesInExists() throws SQLException;
                    972:     rows[59].add("supportsSubqueriesInIns");
                    973:     rows[59].add(new Boolean(d.supportsSubqueriesInIns()));
                    974:     //boolean supportsSubqueriesInIns() throws SQLException;
                    975:     rows[60].add("supportsSubqueriesInQuantifieds");
                    976:     rows[60].add(new Boolean(d.supportsSubqueriesInQuantifieds()));
                    977:     //boolean supportsSubqueriesInQuantifieds() throws SQLException;
                    978:     rows[61].add("supportsCorrelatedSubqueries");
                    979:     rows[61].add(new Boolean(d.supportsCorrelatedSubqueries()));
                    980:     //boolean supportsCorrelatedSubqueries() throws SQLException;
                    981:     rows[62].add("supportsUnion");
                    982:     rows[62].add(new Boolean(d.supportsUnion()));
                    983:     //boolean supportsUnion() throws SQLException;
                    984:     rows[63].add("supportsUnionAll");
                    985:     rows[63].add(new Boolean(d.supportsUnionAll()));
                    986:     //boolean supportsUnionAll() throws SQLException;
                    987:     rows[64].add("supportsOpenCursorsAcrossCommit");
                    988:     rows[64].add(new Boolean(d.supportsOpenCursorsAcrossCommit()));
                    989:     //boolean supportsOpenCursorsAcrossCommit() throws SQLException;
                    990:     rows[65].add("supportsOpenCursorsAcrossRollback");
                    991:     rows[65].add(new Boolean(d.supportsOpenCursorsAcrossRollback()));
                    992:     //boolean supportsOpenCursorsAcrossRollback() throws SQLException;
                    993:     rows[66].add("supportsOpenStatementsAcrossCommit");
                    994:     rows[66].add(new Boolean(d.supportsOpenStatementsAcrossCommit()));
                    995:     //boolean supportsOpenStatementsAcrossCommit() throws SQLException;
                    996:     rows[67].add("supportsOpenStatementsAcrossRollback");
                    997:     rows[67].add(new Boolean(d.supportsOpenStatementsAcrossRollback()));
                    998:     //boolean supportsOpenStatementsAcrossRollback() throws SQLException;
                    999:     rows[68].add("doesMaxRowSizeIncludeBlobs");
                   1000:     rows[68].add(new Boolean(d.doesMaxRowSizeIncludeBlobs()));
                   1001:     //boolean doesMaxRowSizeIncludeBlobs() throws SQLException;
                   1002:     rows[69].add("supportsTransactions");
                   1003:     rows[69].add(new Boolean(d.supportsTransactions()));
                   1004:     //boolean supportsTransactions() throws SQLException;
                   1005:     rows[70].add("supportsTransactionIsolationLevel");
                   1006:     rows[70].add(new Boolean(d.supportsTransactionIsolationLevel(1)));
                   1007:     //boolean supportsTransactionIsolationLevel(int level) throws SQLException;
                   1008:     rows[71].add("supportsDataDefinitionAndDataManipulationTransactions");
                   1009:     rows[71].add(new Boolean(d.supportsDataDefinitionAndDataManipulationTransactions()));
                   1010:     //boolean supportsDataDefinitionAndDataManipulationTransactions() throws SQLException;
                   1011:     rows[72].add("supportsDataManipulationTransactionsOnly");
                   1012:     rows[72].add(new Boolean(d.supportsDataManipulationTransactionsOnly()));
                   1013:     //boolean supportsDataManipulationTransactionsOnly() throws SQLException;
                   1014:     rows[73].add("dataDefinitionCausesTransactionCommit");
                   1015:     rows[73].add(new Boolean(d.dataDefinitionCausesTransactionCommit()));
                   1016:     //boolean dataDefinitionCausesTransactionCommit() throws SQLException;
                   1017:     rows[74].add("dataDefinitionIgnoredInTransactions");
                   1018:     rows[74].add(new Boolean(d.dataDefinitionIgnoredInTransactions()));
                   1019:     //boolean dataDefinitionIgnoredInTransactions() throws SQLException;
                   1020:     rows[75].add("getMaxBinaryLiteralLength");
                   1021:     rows[75].add(new Integer(d.getMaxBinaryLiteralLength()));
                   1022:     // int getMaxBinaryLiteralLength() throws SQLException;
                   1023:     rows[76].add("getMaxCharLiteralLength");
                   1024:     rows[76].add(new Integer(d.getMaxCharLiteralLength()));
                   1025:     //int getMaxCharLiteralLength() throws SQLException;
                   1026:     rows[77].add("getMaxColumnNameLength");
                   1027:     rows[77].add(new Integer(d.getMaxColumnNameLength()));
                   1028:     // int getMaxColumnNameLength() throws SQLException;
                   1029:     rows[78].add("getMaxColumnsInGroupBy");
                   1030:     rows[78].add(new Integer(d.getMaxColumnsInGroupBy()));
                   1031:     //int getMaxColumnsInGroupBy() throws SQLException;
                   1032:     rows[79].add("getMaxColumnsInIndex");
                   1033:     rows[79].add(new Integer(d.getMaxColumnsInIndex()));
                   1034:     //int getMaxColumnsInIndex() throws SQLException;
                   1035:     rows[80].add("getMaxColumnsInOrderBy");
                   1036:     rows[80].add(new Integer(d.getMaxColumnsInOrderBy()));
                   1037:     //int getMaxColumnsInOrderBy() throws SQLException;
                   1038:     rows[81].add("getMaxColumnsInSelect");
                   1039:     rows[81].add(new Integer(d.getMaxColumnsInSelect()));
                   1040:     //int getMaxColumnsInSelect() throws SQLException;
                   1041:     rows[82].add("getMaxColumnsInTable");
                   1042:     rows[82].add(new Integer(d.getMaxColumnsInTable()));
                   1043:     //int getMaxColumnsInTable() throws SQLException;
                   1044:     rows[83].add("getMaxConnections");
                   1045:     rows[83].add(new Integer(d.getMaxConnections()));
                   1046:     //int getMaxConnections() throws SQLException;
                   1047:     rows[84].add("getMaxCursorNameLength");
                   1048:     rows[84].add(new Integer(d.getMaxCursorNameLength()));
                   1049:     //    int getMaxCursorNameLength() throws SQLException;
                   1050:     rows[85].add("getMaxIndexLength");
                   1051:     rows[85].add(new Integer(d.getMaxIndexLength()));
                   1052:     //int getMaxIndexLength() throws SQLException;
                   1053:     rows[86].add("getMaxSchemaNameLength");
                   1054:     rows[86].add(new Integer(d.getMaxSchemaNameLength()));
                   1055:     //int getMaxSchemaNameLength() throws SQLException;
                   1056:     rows[87].add("getMaxProcedureNameLength");
                   1057:     rows[87].add(new Integer(d.getMaxProcedureNameLength()));
                   1058:     //int getMaxProcedureNameLength() throws SQLException;
                   1059:     rows[88].add("getMaxCatalogNameLength");
                   1060:     rows[88].add(new Integer(d.getMaxCatalogNameLength()));
                   1061:     //int getMaxCatalogNameLength() throws SQLException;
                   1062:     rows[89].add("getMaxRowSize");
                   1063:     rows[89].add(new Integer(d.getMaxRowSize()));
                   1064:     //int getMaxRowSize() throws SQLException;
                   1065:     rows[90].add("getMaxStatementLength");
                   1066:     rows[90].add(new Integer(d.getMaxStatementLength()));
                   1067:     //int getMaxStatementLength() throws SQLException;
                   1068:     rows[91].add("getMaxStatements");
                   1069:     rows[91].add(new Integer(d.getMaxStatements()));
                   1070:     //int getMaxStatements() throws SQLException;
                   1071:     rows[92].add("getMaxTableNameLength");
                   1072:     rows[92].add(new Integer(d.getMaxTableNameLength()));
                   1073:     //int getMaxTableNameLength() throws SQLException;
                   1074:     rows[93].add("getMaxTablesInSelect");
                   1075:     rows[93].add(new Integer(d.getMaxTablesInSelect()));
                   1076:     //int getMaxTablesInSelect() throws SQLException;
                   1077:     rows[94].add("getMaxUserNameLength");
                   1078:     rows[94].add(new Integer(d.getMaxUserNameLength()));
                   1079:     // int getMaxUserNameLength() throws SQLException;
                   1080:     rows[95].add("getDefaultTransactionIsolation");
                   1081:     rows[95].add(new Integer(d.getDefaultTransactionIsolation()));
                   1082:     //int getDefaultTransactionIsolation() throws SQLException;
                   1083: 
                   1084:     rows[96].add("getDatabaseProductName");
                   1085:     rows[96].add(d.getDatabaseProductName());
                   1086:     // String getDatabaseProductName() throws SQLException;
                   1087:     rows[97].add("getDatabaseProductVersion");
                   1088:     rows[97].add(d.getDatabaseProductVersion());
                   1089:     //String getDatabaseProductVersion() throws SQLException;
                   1090: 
                   1091:     rows[98].add("getURL");
                   1092:     rows[98].add(d.getURL());
                   1093:     //String getURL() throws SQLException;
                   1094:     rows[99].add("getUserName");
                   1095:     rows[99].add(d.getUserName());
                   1096:     //String getUserName() throws SQLException;
                   1097:     rows[100].add("getDriverName");
                   1098:     rows[100].add(d.getDriverName());
                   1099:     //    String getDriverName() throws SQLException;
                   1100:     rows[101].add("getIdentifierQuoteString");
                   1101:     rows[101].add(d.getIdentifierQuoteString());
                   1102:     //String getIdentifierQuoteString() throws SQLException;
                   1103: 
                   1104:     rows[102].add("getDriverVersion");
                   1105:     rows[102].add(d.getDriverVersion());
                   1106:     //String getDriverVersion() throws SQLException;
                   1107:     rows[103].add("getDriverMajorVersion");
                   1108:     rows[103].add(new Integer(d.getDriverMajorVersion()));
                   1109:     //int getDriverMajorVersion();
                   1110:     rows[104].add("getDriverMinorVersion");
                   1111:     rows[104].add(new Integer(d.getDriverMinorVersion()));
                   1112:     //int getDriverMinorVersion();
                   1113:     rows[105].add("getSQLKeywords");
                   1114:     rows[105].add(d.getSQLKeywords());
                   1115:     //String getSQLKeywords() throws SQLException;
                   1116:     rows[106].add("getNumericFunctions");
                   1117:     rows[106].add(d.getNumericFunctions());
                   1118:     //String getNumericFunctions() throws SQLException;
                   1119:     rows[107].add("getStringFunctions");
                   1120:     rows[107].add(d.getStringFunctions());
                   1121:     // String getStringFunctions() throws SQLException;
                   1122:     rows[108].add("getSystemFunctions");
                   1123:     rows[108].add(d.getSystemFunctions());
                   1124:     //String getSystemFunctions() throws SQLException;
                   1125:     rows[109].add("getTimeDateFunctions");
                   1126:     rows[109].add(d.getTimeDateFunctions());
                   1127:     //String getTimeDateFunctions() throws SQLException;
                   1128:     rows[110].add("getSearchStringEscape");
                   1129:     rows[110].add(d.getSearchStringEscape());
                   1130:     //String getSearchStringEscape() throws SQLException;
                   1131:     rows[111].add("getExtraNameCharacters");
                   1132:     rows[111].add(d.getExtraNameCharacters());
                   1133:     //String getExtraNameCharacters() throws SQLException;
                   1134:     rows[112].add("getSchemaTerm");
                   1135:     rows[112].add(d.getSchemaTerm());
                   1136:     //String getSchemaTerm() throws SQLException;
                   1137:     rows[113].add("getProcedureTerm");
                   1138:     rows[113].add(d.getProcedureTerm());
                   1139:     //String getProcedureTerm() throws SQLException;
                   1140:     rows[114].add("getCatalogTerm");
                   1141:     rows[114].add(d.getCatalogTerm());
                   1142:     // String getCatalogTerm() throws SQLException;
                   1143:     rows[115].add("getCatalogSeparator");
                   1144:     rows[115].add(d.getCatalogSeparator());
                   1145:     //String getCatalogSeparator() throws SQLException;
                   1146: 
                   1147:     /*
                   1148:      boolean supportsResultSetType(int type) throws SQLException;
                   1149:     
                   1150:      boolean supportsResultSetConcurrency(int type, int concurrency) throws SQLException;
                   1151:     
                   1152:      boolean ownUpdatesAreVisible(int type) throws SQLException;
                   1153:     
                   1154:      boolean ownDeletesAreVisible(int type) throws SQLException;
                   1155:     
                   1156:      boolean ownInsertsAreVisible(int type) throws SQLException;
                   1157:     
                   1158:      boolean othersUpdatesAreVisible(int type) throws SQLException;
                   1159:     
                   1160:      boolean othersDeletesAreVisible(int type) throws SQLException;
                   1161:     
                   1162:      boolean othersInsertsAreVisible(int type) throws SQLException;
                   1163:      boolean updatesAreDetected(int type) throws SQLException;
                   1164:      boolean deletesAreDetected(int type) throws SQLException;
                   1165:     
                   1166:      boolean insertsAreDetected(int type) throws SQLException;
                   1167:     */
                   1168:     // not in filemaker
                   1169:     // rows[96].add("supportsBatchUpdates");
                   1170:     // rows[96].add(new Boolean(d.supportsBatchUpdates()));
                   1171:     //boolean supportsBatchUpdates() throws SQLException;
                   1172: 
                   1173:     /*
                   1174:     ResultSet getProcedures(String catalog, String schemaPattern, String procedureNamePattern) throws SQLException;
                   1175:     
                   1176:     ResultSet getProcedureColumns(String catalog, String schemaPattern, String procedureNamePattern, String columnNamePattern) throws SQLException;
                   1177:     ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String types[]) throws SQLException;
                   1178:     ResultSet getSchemas() throws SQLException;
                   1179:     ResultSet getCatalogs() throws SQLException;
                   1180:     ResultSet getTableTypes() throws SQLException;
                   1181:     ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException;
                   1182:     ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException;
                   1183:     ResultSet getImportedKeys(String catalog, String schema, String table) throws SQLException;
                   1184:     ResultSet getExportedKeys(String catalog, String schema, String table) throws SQLException;
                   1185:     ResultSet getCrossReference(String primaryCatalog, String primarySchema, String primaryTable, String foreignCatalog, String foreignSchema, String foreignTable) throws SQLException;
                   1186:     ResultSet getTypeInfo() throws SQLException;
                   1187:     ResultSet getIndexInfo(String catalog, String schema, String table, boolean unique, boolean approximate) throws SQLException;
                   1188:     
                   1189:     ResultSet getUDTs(String catalog, String schemaPattern, String typeNamePattern, int[] types) throws SQLException;
                   1190:     
                   1191:     Connection getConnection() throws SQLException;
                   1192:     
                   1193:     */
                   1194:     for (int i = 0; i < rows.length; ++i)
                   1195:       cols.add(rows[i]);
                   1196:     data[0] = cols;
                   1197:     data[1] = columnNames;
                   1198:     return data;
                   1199:   }
                   1200:   public Vector getNextRow() throws Exception
                   1201:   {
                   1202: 
                   1203:     if (result == null)
                   1204:       return null;
                   1205:     boolean check = false;
                   1206:     ResultSet resultSet = result;
                   1207:     ResultSetMetaData metaData = resultSet.getMetaData();
                   1208:     int columnCount = metaData.getColumnCount();
                   1209:     Vector tableData = new Vector();
                   1210:     check = resultSet.next();
                   1211:     //  System.out.println("hallo check "+check);
                   1212:     if (!check)
                   1213:       return null;
                   1214:     Vector tableRow = new Vector(), m_columnClasses = new Vector();
                   1215:     for (int i = 1; i <= columnCount; i++)
                   1216:     {
                   1217:       // repeating fields and fields from related databases may contain
                   1218:       // multliple data values; the data values are stored using
                   1219:       // a Vector which is then added to the tableRow
                   1220:       //      if (metaData instanceof ResultSetMetaDataExt)
                   1221:       if ((metaData instanceof ResultSetMetaDataExt) && (((ResultSetMetaDataExt) metaData).isRelated(i) || ((ResultSetMetaDataExt) metaData).isRepeating(i)))
                   1222:       {
                   1223:         //System.out.println("Related fields");
                   1224:         // retrieve the repeating or related field contents as a
                   1225:         // com.fmi.jdbc.Array via the ResultSet.getObject method
                   1226:         com.fmi.jdbc.Array array = (com.fmi.jdbc.Array) resultSet.getObject(i);
                   1227:         //            create a Vector for storing all of the data values
                   1228:         ArrayList columnData = new ArrayList();
                   1229:         try
                   1230:         {
                   1231: 
                   1232:           // call the Array.getStringArray method since the data will
                   1233:           // only be displayed
                   1234:           Object[] fieldData = (Object[]) array.getArray();
                   1235: 
                   1236:           if (fieldData != null)
                   1237:           {
                   1238:             // add each value to the Vector
                   1239:             for (int j = 0; j < fieldData.length; j++)
                   1240:             {
                   1241:               if (fieldData[j] != null)
                   1242:                 columnData.add(fieldData[j]);
                   1243:             }
                   1244:           }
                   1245:         } catch (Exception e)
                   1246:         {
                   1247:           //System.out.println(e);
                   1248:         }
                   1249: 
                   1250:         if (columnData.isEmpty())
                   1251:           tableRow.add(null);
                   1252:         else
                   1253:           tableRow.addElement(columnData);
                   1254:         //System.out.println(columnData);
                   1255:         //System.out.println("Related fields"+columnData.size()+" "+tableRow.size());
                   1256: 
                   1257:         // m_columnClasses.addElement(java.util.Vector.class);
                   1258:       } else if (metaData.getColumnType(i) == Types.LONGVARBINARY)
                   1259:       {
                   1260:         // use the ResultSet.getObject method for retrieving images
                   1261:         // from FileMaker Pro container fields; the ResultSet.getObject
                   1262:         // method returns a java.awt.Image object for FileMaker Pro
                   1263:         // container fields
                   1264: 
                   1265:         try
                   1266:         {
                   1267:           tableRow.addElement(resultSet.getObject(i));
                   1268:         } catch (Exception e)
                   1269:         {
                   1270:           // TODO Auto-generated catch block
                   1271:           // e.printStackTrace();
                   1272:           tableRow.addElement(null);
                   1273:         }
                   1274:         //    m_columnClasses.addElement(java.awt.Image.class);
                   1275:       } else if (metaData.getColumnType(i) == Types.TIME)
                   1276:       {
                   1277:         // use the ResultSet.getObject method for retieving images
                   1278:         // from FileMaker Pro container fields; the ResultSet.getObject
                   1279:         // method returns a java.awt.Image object for FileMaker Pro
                   1280:         // container fields
                   1281:         try
                   1282:         {
                   1283:           tableRow.addElement(resultSet.getTime(i).toString());
                   1284:           //    m_columnClasses.addElement(java.sql.Time.class);
                   1285:         } catch (Exception e)
                   1286:         {
                   1287: 
                   1288:           String value = resultSet.getString(i);
                   1289:           if (value != null)
                   1290:           {
                   1291:             //System.out.println("SQLTime new "+Time.valueOf("17:00:00").toString());
                   1292:             int index = 0;
                   1293:             for (int j = 0; j < value.length(); ++j)
                   1294:             {
                   1295:               if (!Character.isLetter(value.charAt(j)))
                   1296:                 index = j + 1;
                   1297:               else
                   1298:                 break;
                   1299:             }
                   1300: 
                   1301:             tableRow.addElement(value.substring(0, index));
                   1302:             //m_columnClasses.addElement(java.sql.Time.class);
                   1303:           } else
                   1304:             tableRow.add(null);
                   1305:           //  m_columnClasses.addElement(String.class);
                   1306:         } // to catch
                   1307: 
1.10      rogo     1308:       } else if (metaData.getColumnType(i) == Types.INTEGER)
1.25    ! rogo     1309:       {
        !          1310:         // use the ResultSet.getObject method for retieving images
        !          1311:         // from FileMaker Pro container fields; the ResultSet.getObject
        !          1312:         // method returns a java.awt.Image object for FileMaker Pro
        !          1313:         // container fields
1.10      rogo     1314: 
1.25    ! rogo     1315:         tableRow.addElement(new Integer(resultSet.getInt(i)));
        !          1316:         //  m_columnClasses.addElement(java.sql.Date.class);
        !          1317:       } else if (metaData.getColumnType(i) == Types.DATE)
        !          1318:       {
1.1       rogo     1319:         // use the ResultSet.getObject method for retieving images
                   1320:         // from FileMaker Pro container fields; the ResultSet.getObject
                   1321:         // method returns a java.awt.Image object for FileMaker Pro
                   1322:         // container fields
1.25    ! rogo     1323:         try
        !          1324:         {
        !          1325:           tableRow.addElement(resultSet.getDate(i));
1.1       rogo     1326: 
1.25    ! rogo     1327:         } catch (Exception e)
        !          1328:         {
        !          1329:           // work around for parse bug in FM JDBC Driver 
        !          1330:           // for dates of format dd-mm-yyyy
        !          1331:           String date = resultSet.getString(i);
        !          1332:           date = date.replace('-', '.');
        !          1333:           java.text.DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, Locale.GERMAN);
        !          1334:           java.util.Date d = dateFormat.parse(date);
        !          1335:           // Calendar cal=Calendar.getInstance(Locale.GERMAN);
        !          1336:           // cal.setTime(d);
        !          1337:           // date=(cal.get(Calendar.YEAR))+"-"+(cal.get(Calendar.MONTH)+1)+"-"+cal.get(Calendar.DATE);
        !          1338:           tableRow.addElement(new java.sql.Date(d.getTime()));
        !          1339:           System.out.println("Date " + date);
        !          1340:         }
1.1       rogo     1341:         //  m_columnClasses.addElement(java.sql.Date.class);
                   1342:       } else if (metaData.getColumnTypeName(i) == "NUMBER")
                   1343:       {
                   1344:         // use the ResultSet.getObject method for retieving images
                   1345:         // from FileMaker Pro container fields; the ResultSet.getObject
                   1346:         // method returns a java.awt.Image object for FileMaker Pro
                   1347:         // container fields
                   1348:         try
                   1349:         {
1.13      rogo     1350:           tableRow.addElement(new Double(resultSet.getDouble(i)));
1.1       rogo     1351:           // m_columnClasses.addElement(Integer.class);
                   1352: 
                   1353:         } catch (Exception e)
                   1354:         {
                   1355: 
                   1356:           StringBuffer number = new StringBuffer();
                   1357:           String value = resultSet.getString(i);
                   1358:           System.out.println(value);
                   1359:           for (int c = 0; c < value.length(); ++c)
                   1360:           {
                   1361:             if (Character.isDigit(value.charAt(c)))
                   1362:             {
                   1363:               number.append(value.charAt(c));
                   1364:             }
                   1365:           }
                   1366:           if (number.length() > 0)
                   1367:           {
                   1368:             tableRow.addElement(null);
                   1369:             //   m_columnClasses.addElement(Integer.class);
                   1370:           } else
                   1371:             tableRow.addElement(null);
                   1372:         }
                   1373:       } else
                   1374:       {
                   1375:         // all other field values are retrieved as strings and
                   1376:         // added to the tableRow Vector
                   1377:         //   System.out.println("row "+resultSet.getString(i));
                   1378:         try
                   1379:         {
                   1380:           byte[] b = null;
                   1381:           if (metaData instanceof ResultSetMetaDataExt)
                   1382:             b = resultSet.getBytes(i);
1.25    ! rogo     1383:           /*   if (b != null)
        !          1384:              {
        !          1385:                java.io.ByteArrayInputStream stream = (java.io.ByteArrayInputStream) resultSet.getBinaryStream(i);
        !          1386:                //    System.out.println(" stream "+resultSet.getBinaryStream(i));
        !          1387:                byte[] c = new byte[stream.available()];
        !          1388:                int length = stream.read(c, 0, c.length);
        !          1389:                int count = 0;
        !          1390:                b = new byte[c.length];
        !          1391:                for (int n = 0; n < length; ++n)
        !          1392:                {
        !          1393:           
        !          1394:                  if (c[n] != 0)
        !          1395:                  {
        !          1396:                    //     System.out.println(c[n]+" "+(int)'?'+" "+(char)c[n]+" "+count+" "+b.length);
        !          1397:                    b[count++] = c[n];
        !          1398:                  }
        !          1399:                }
        !          1400:                byte[] bCopy = new byte[count];
        !          1401:                System.arraycopy(b, 0, bCopy, 0, count);
        !          1402:                b = bCopy;
        !          1403:              }*/
1.1       rogo     1404:           String utf8 = null;
1.24      rogo     1405:           utf8 = (b == null) ? null : new String(b);
1.1       rogo     1406:           if (metaData instanceof ResultSetMetaDataExt)
1.24      rogo     1407:           {
                   1408:             String rowElement = "";
                   1409:             if (b != null)
                   1410:             {
                   1411:               rowElement = resultSet.getString(i);
1.25    ! rogo     1412:               if (useNormanToUnicodeMapper)
        !          1413:                 rowElement = Convert.normanToUnicode(rowElement);
1.24      rogo     1414:               tableRow.addElement(rowElement);
                   1415: 
                   1416:             } else
                   1417:               tableRow.addElement(null);
1.25    ! rogo     1418:           } else
1.1       rogo     1419:           {
1.25    ! rogo     1420:             if (url.toLowerCase().indexOf("odbc") >= 0)
        !          1421:             {
        !          1422:               byte[] val = resultSet.getBytes(i);
        !          1423:               for (int j = 0; j < val.length; ++j)
        !          1424:                 System.out.println(Integer.toHexString(val[j]));
        !          1425:               tableRow.addElement((val == null) ? null : new String(val));
        !          1426: 
        !          1427:             } else
        !          1428:               //  byte[] val = resultSet.getBytes(i);
        !          1429:               tableRow.add(resultSet.getString(i));
1.1       rogo     1430:             //tableRow.addElement((val==null) ? null:new String(val,"UTF-8"));
                   1431:           }
                   1432:         } catch (Exception e)
                   1433:         {
1.24      rogo     1434:           System.out.println("Hey I got an error" + e);
1.1       rogo     1435:           e.printStackTrace();
                   1436:         }
                   1437:         // m_columnClasses.addElement(java.lang.String.class);
                   1438:       }
                   1439:     }
                   1440:     //  tableData.addElement(tableRow);
                   1441:     if (check)
                   1442:       return tableRow;
                   1443:     else
                   1444:       return null;
                   1445:   }
                   1446:   class ConnectionPool
                   1447:   {
                   1448:     String user = "", passwd = "", url = "";
                   1449:     Connection con;
                   1450:     public ConnectionPool(String url, String user, String passwd, Connection con)
                   1451:     {
                   1452:       this.con = con;
                   1453:       this.user = user;
                   1454:       this.passwd = passwd;
                   1455:       this.url = url;
                   1456:     }
                   1457: 
                   1458:   }
                   1459:   public String getQC()
                   1460:   {
                   1461:     // if (connection == null)
                   1462:     // return "";
                   1463: 
                   1464:     // check if connection null if null try to get one
                   1465:     if (connection == null)
                   1466:       try
                   1467:       {
                   1468:         getConnection();
                   1469:       } catch (Exception e)
                   1470:       {
                   1471:         if (FM2SQL.debug)
                   1472:           System.out.println("cannot get a connection");
                   1473:       }
                   1474:     if (connection == null)
                   1475:     {
                   1476:       if (url.toLowerCase().indexOf("fmpro") >= 0 || url.toLowerCase().indexOf("postgres") >= 0)
                   1477:         quoteChar = "\"";
                   1478:       else if (url.toLowerCase().indexOf("mysql") >= 0)
                   1479:         quoteChar = "`";
                   1480:     }
                   1481:     if (quoteChar == null)
                   1482:       quoteChar = "\""; // needed for postgres
                   1483:     return quoteChar;
                   1484:   }
                   1485:   public int getRowCount(String query) throws SQLException
                   1486:   {
                   1487:     String table = query.substring(query.indexOf("from") + 4).trim();
                   1488:     int index = table.indexOf(" ");
                   1489:     table = table.substring(0, (index >= 0) ? index : table.length());
                   1490:     System.out.println(table);
                   1491:     Statement stm = null;
                   1492: 
                   1493:     if (metaData instanceof ResultSetMetaDataExt)
                   1494:       return 1000;
                   1495:     if (!connection.isClosed())
                   1496:       stm = connection.createStatement();
                   1497:     stm.setMaxRows(1);
                   1498:     ResultSet resultSet = stm.executeQuery("select count(*) from " + table);
                   1499:     resultSet.next();
                   1500:     return resultSet.getInt(1);
                   1501:   }
1.25    ! rogo     1502:   public TreeSet getIDVector(String id, String table, String query, int numHits) throws Exception
        !          1503:   {
        !          1504:     TreeSet t = new TreeSet();
        !          1505:     getConnection();
        !          1506:     ResultSet result = this.result;
        !          1507:     String subQuery = query.substring(query.lastIndexOf(table) + table.length() + 1);
        !          1508:     System.out.println("subQuery " + subQuery);
        !          1509:     makeQuery("select " + id + " from " + getQC() + table + getQC() + subQuery, numHits);
        !          1510:     while (true)
        !          1511:     {
1.6       rogo     1512:       Vector vec = getNextRow();
                   1513:       if (vec == null)
                   1514:         break;
                   1515:       t.add(vec.get(0));
1.25    ! rogo     1516:     }
        !          1517:     this.result = result;
        !          1518:     metaData = (this.result == null) ? null : this.result.getMetaData();
1.6       rogo     1519:     return t;
1.25    ! rogo     1520:   }
1.24      rogo     1521:   /**
                   1522:    * @return
                   1523:    */
                   1524:   public boolean isUseNormanToUnicodeMapper()
                   1525:   {
                   1526:     return useNormanToUnicodeMapper;
                   1527:   }
                   1528: 
                   1529:   /**
                   1530:    * @param b
                   1531:    */
                   1532:   public void setUseNormanToUnicodeMapper(boolean b)
                   1533:   {
                   1534:     useNormanToUnicodeMapper = b;
                   1535:   }
                   1536: 
1.5       rogo     1537: }

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