2
Copyright (C) 2009 Volker Berlin (i-net software)
4
This software is provided 'as-is', without any express or implied
5
warranty. In no event will the authors be held liable for any damages
6
arising from the use of this software.
8
Permission is granted to anyone to use this software for any purpose,
9
including commercial applications, and to alter it and redistribute it
10
freely, subject to the following restrictions:
12
1. The origin of this software must not be misrepresented; you must not
13
claim that you wrote the original software. If you use this software
14
in a product, an acknowledgment in the product documentation would be
15
appreciated but is not required.
16
2. Altered source versions must be plainly marked as such, and must not be
17
misrepresented as being the original software.
18
3. This notice may not be removed or altered from any source distribution.
24
package sun.jdbc.odbc;
28
import cli.System.Data.*;
29
import cli.System.Data.Odbc.*;
32
* @author Volker Berlin
34
public class JdbcOdbcUpdateableResultSet extends JdbcOdbcDTResultSet{
36
private final OdbcDataAdapter da;
38
private final DataTable data;
40
private DataRow insertRow;
43
public JdbcOdbcUpdateableResultSet(OdbcCommand cmd){
44
this(new DataTable(), cmd);
48
private JdbcOdbcUpdateableResultSet(DataTable data, OdbcCommand cmd){
49
super(data, CONCUR_UPDATABLE);
51
da = new OdbcDataAdapter(cmd);
53
OdbcCommandBuilder cmdBldr = new OdbcCommandBuilder(da);
54
cmdBldr.GetUpdateCommand(); // throw an exception if update is not possible, we want a very early exception
59
protected DataRow getDataRow() throws SQLException{
60
if(insertRow != null){
63
return super.getDataRow();
68
protected void setDataRow() throws SQLException{
75
public void updateObject(int columnIndex, Object x, int scaleOrLength) throws SQLException{
77
x = JdbcOdbcUtils.convertJava2Net(x, scaleOrLength);
78
getDataRow().set_Item(columnIndex - 1, x);
79
}catch(ArrayIndexOutOfBoundsException ex){
80
throw new SQLException("Invalid column number (" + columnIndex + "). A number between 1 and "
81
+ data.get_Columns().get_Count() + " is valid.", "S1002", ex);
87
public void updateRow() throws SQLException{
88
if(insertRow != null){
89
throw new SQLException("Cursor is on the insert row.");
94
throw JdbcOdbcUtils.createSQLException(th);
100
public void deleteRow() throws SQLException{
101
if(insertRow != null){
102
throw new SQLException("Cursor is on the insert row.");
105
getDataRow().Delete(); // Delete the current row
107
setDataRow(); // set a new Current Row
108
}catch(Throwable th){
109
throw JdbcOdbcUtils.createSQLException(th);
115
public void insertRow() throws SQLException{
116
if(insertRow == null){
117
throw new SQLException("Cursor is not on the insert row.");
120
getRows().Add(insertRow);
124
}catch(Throwable th){
125
throw JdbcOdbcUtils.createSQLException(th);
132
public void moveToInsertRow(){
133
insertRow = data.NewRow();
138
public void moveToCurrentRow(){
144
public void cancelRowUpdates() throws SQLException{
145
getDataRow().CancelEdit();
150
public boolean rowDeleted(){
156
public boolean rowInserted(){
162
public boolean rowUpdated(){