01: //jTDS JDBC Driver for Microsoft SQL Server and Sybase
02: //Copyright (C) 2004 The jTDS Project
03: //
04: //This library is free software; you can redistribute it and/or
05: //modify it under the terms of the GNU Lesser General Public
06: //License as published by the Free Software Foundation; either
07: //version 2.1 of the License, or (at your option) any later version.
08: //
09: //This library is distributed in the hope that it will be useful,
10: //but WITHOUT ANY WARRANTY; without even the implied warranty of
11: //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: //Lesser General Public License for more details.
13: //
14: //You should have received a copy of the GNU Lesser General Public
15: //License along with this library; if not, write to the Free Software
16: //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: //
18: package net.sourceforge.jtds.test;
19:
20: import java.sql.ResultSet;
21: import java.sql.ResultSetMetaData;
22: import java.sql.SQLException;
23:
24: /**
25: * Base class for meta data test cases.
26: *
27: * @author David Eaves
28: * @version $Id: MetaDataTestCase.java,v 1.1 2005/01/05 12:24:14 alin_sinpalean Exp $
29: */
30: public abstract class MetaDataTestCase extends DatabaseTestCase {
31:
32: public MetaDataTestCase(String name) {
33: super (name);
34: }
35:
36: /**
37: * Utility method to check column names and number.
38: *
39: * @param rs the result set to check
40: * @param names the list of column names to compare to result set
41: * @return the <code>boolean</code> value true if the columns match
42: */
43: protected boolean checkColumnNames(ResultSet rs, String[] names)
44: throws SQLException {
45: ResultSetMetaData rsmd = rs.getMetaData();
46: if (rsmd.getColumnCount() < names.length) {
47: System.out.println("Cols=" + rsmd.getColumnCount());
48: return false;
49: }
50:
51: for (int i = 1; i <= names.length; i++) {
52: if (names[i - 1].length() > 0
53: && !rsmd.getColumnLabel(i).equals(names[i - 1])) {
54: System.out.println(names[i - 1] + " = "
55: + rsmd.getColumnLabel(i));
56: return false;
57: }
58: }
59:
60: return true;
61: }
62: }
|