test integration changes
[csql.git] / src / jdbc / JdbcSqlResultSetMetaData.java
blob398166dd15d7be73fbe0325cbb270e6a3b9f6655
2 package csql.jdbc;
4 import java.sql.SQLException;
5 import java.sql.ResultSetMetaData;
7 /**
9 * @author bijaya
11 public final class JdbcSqlResultSetMetaData
12 extends JSqlError implements ResultSetMetaData, JSqlErrorType
14 private boolean isClosed;
15 JdbcSqlStatement stmt; // This guy creates me
16 private boolean shouldDriverHandles;
17 private FieldInfo[] fieldMeta;
19 JdbcSqlResultSetMetaData()
21 isClosed = false;
22 shouldDriverHandles = false;
25 void setStmt( JdbcSqlStatement s )
27 stmt = s;
28 isClosed = false;
31 JdbcSqlResultSetMetaData(FieldInfo[] fields)
33 isClosed = false;
34 shouldDriverHandles = true;
35 fieldMeta = fields;
38 public void close() throws SQLException
40 if( ! isClosed )
41 isClosed = true;
42 return;
45 public int getColumnCount () throws SQLException
47 if( isClosed ) throw getException( CSQL_INVALID_STATE );
48 if (shouldDriverHandles){
49 return this.fieldMeta.length;
51 return( stmt.jniStmt.getTotalProjFld() );
55 public int getColumnIndex (String name) throws SQLException
57 if( isClosed ) throw getException( CSQL_INVALID_STATE );
58 if(shouldDriverHandles){
59 for ( int i=0; i< this.fieldMeta.length; i++)
61 if(fieldMeta[i].getColname().equals(name))
62 return (i+1);
65 return( stmt.jniStmt.findColumn( name ) );//TO DO
68 public String getColumnName (int colNum) throws SQLException
70 if( isClosed ) throw getException( CSQL_INVALID_STATE );
71 if(shouldDriverHandles){
72 if(this.fieldMeta.length < colNum)
73 return null;
74 else
75 return this.fieldMeta[colNum-1].getColname();
77 String name= stmt.jniStmt.getProjFldName(colNum);
78 return( name );
80 public String getColumnLabel (int colNum) throws SQLException
82 return getColumnName( colNum );
85 public boolean isReadOnly (int colNum) throws SQLException
87 if( isClosed ) throw getException( CSQL_INVALID_STATE );
88 return( false );
90 public boolean isWritable (int colNum) throws SQLException
92 if( isClosed ) throw getException( CSQL_INVALID_STATE );
93 if(shouldDriverHandles) {
94 return false;
96 return( true );
98 public boolean isDefinitelyWritable (int colNum) throws SQLException
100 if( isClosed ) throw getException( CSQL_INVALID_STATE );
101 if(shouldDriverHandles) {
102 return false;
104 return( true );
108 public String getColumnClassName(int colNum) throws SQLException
110 if( isClosed ) throw getException( CSQL_INVALID_STATE );
111 if(shouldDriverHandles) {
112 return Util.getClassName(this.fieldMeta[colNum-1].getCsqlType());
114 return Util.getClassName(this.stmt.jniStmt.getProjFldType(colNum));
117 public int getColumnType (int colNum) throws SQLException
119 if( isClosed ) throw getException( CSQL_INVALID_STATE );
120 if(shouldDriverHandles) {
121 return Util.getType(this.fieldMeta[colNum-1].getCsqlType());
123 return Util.getType(this.stmt.jniStmt.getProjFldType(colNum));
125 public String getColumnTypeName (int colNum) throws SQLException
127 if( isClosed ) throw getException( CSQL_INVALID_STATE );
128 if(shouldDriverHandles) {
129 return Util.getTypeName(this.fieldMeta[colNum-1].getCsqlType());
131 return Util.getTypeName(this.stmt.jniStmt.getProjFldType(colNum));
133 public boolean isCaseSensitive (int colNum) throws SQLException
135 if( isClosed ) throw getException( CSQL_INVALID_STATE );
136 return( false );
139 public int isNullable (int colNum) throws SQLException
141 if( isClosed ) throw getException( CSQL_INVALID_STATE );
142 if(shouldDriverHandles) {
143 if(this.fieldMeta[colNum-1].isNullable())
144 return JdbcSqlResultSetMetaData.columnNoNulls ;
145 else
146 return JdbcSqlResultSetMetaData.columnNullable ;
149 if (this.stmt.jniStmt.isFldNullable(colNum))
150 return JdbcSqlResultSetMetaData.columnNoNulls ;
151 else
152 return JdbcSqlResultSetMetaData.columnNullable ;
155 public String getTableName (int colNum) throws SQLException
157 if( isClosed ) throw getException( CSQL_INVALID_STATE );
158 if(shouldDriverHandles){
159 return "";
161 //TODO
162 return( null );
164 public boolean isSigned (int colNum) throws SQLException
166 if( isClosed ) throw getException( CSQL_INVALID_STATE );
167 return false;
169 public int getPrecision (int colNum) throws SQLException //TODO
171 if( isClosed ) throw getException( CSQL_INVALID_STATE );
172 return 0;
174 public int getScale (int colNum) throws SQLException //TODO
176 if( isClosed ) throw getException( CSQL_INVALID_STATE );
177 return 0;
179 public String getSchemaName (int colNum) throws SQLException
181 return "";
185 // UN-SUPPORTED API's
186 public int getColumnDisplaySize (int colNum) throws SQLException
188 return( 1 );
190 //TODO:
191 public boolean isAutoIncrement (int colNum) throws SQLException
193 return( false );
195 public boolean isCurrency (int colNum) throws SQLException
197 return( false );
199 public String getCatalogName (int colNum) throws SQLException
201 return "csql";
203 public boolean isSearchable (int colNum) throws SQLException
205 if(shouldDriverHandles) return false;
206 return( true );
208 //java 1.6 methods
209 public boolean isWrapperFor(Class ifact) throws SQLException
211 throw getException(CSQL_NOT_SUPPORTED);
213 public Class unwrap(Class iface) throws SQLException
215 throw getException(CSQL_NOT_SUPPORTED);