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