| Page 32 of 38 Prev | Index | Next |
public void __setattr__(String name, PyObject value) {
if ("arraysize".equals(name)) {
this.arraysize = value.__int__().getValue();
} else if ("softspace".equals(name)) {
this.softspace = value.__int__().getValue();
} else if ("datahandler".equals(name)) {
this.datahandler = (DataHandler)value.__tojava__(DataHandler.class);
} else {
super.__setattr__(name, value);
}
}
/**
* Gets the value of the attribute name.
*
* @param name
* @return the attribute for the given name
*/
public PyObject __findattr__(String name) {
if ("arraysize".equals(name)) {
return Py.newInteger(arraysize);
} else if ("softspace".equals(name)) {
return Py.newInteger(softspace);
} else if ("__methods__".equals(name)) {
return __methods__;
} else if ("__members__".equals(name)) {
return __members__;
} else if ("description".equals(name)) {
return this.fetch.description;
} else if ("rowcount".equals(name)) {
return Py.newInteger(this.fetch.rowcount);
} else if ("rownumber".equals(name)) {
int rn = this.fetch.rownumber;
return (rn < 0) ? Py.None : Py.newInteger(rn);
} else if ("warnings".equals(name)) {
return warnings;
} else if ("lastrowid".equals(name)) {
return lastrowid;
} else if ("updatecount".equals(name)) {
return updatecount;
} else if ("datahandler".equals(name)) {
return Py.java2py(this.datahandler);
} else if ("dynamic".equals(name)) {
return this.dynamicFetch ? Py.One : Py.Zero;
} else if ("connection".equals(name)) {
return this.connection;
} else if ("closed".equals(name)) {
return Py.newBoolean(closed);
} else if ("callproc".equals(name)) {
try {
// dynamically decide on the the attribute based on the driver
if (!getMetaData().supportsStoredProcedures()) {
return null;
}
} catch (Throwable t) {}
}
return super.__findattr__(name);
}
/**
* Returns an iteratable object.
*
* @return PyObject
*
* @since Jython 2.2, DB API 2.0+
*/
public PyObject __iter__() {
return this;
}
/**
* Returns the next row from the currently executing SQL statement
* using the same semantics as .fetchone(). A StopIteration
* exception is raised when the result set is exhausted for Python
* versions 2.2 and later.
*
* @return PyObject
*
* @since Jython 2.2, DB API 2.0+
*/
public PyObject next() {
PyObject row = __iternext__();
if (row == null) {
throw Py.StopIteration("");
}
return row;
}
/**
* Return the next element of the sequence that this is an iterator
* for. Returns null when the end of the sequence is reached.
*
* @since Jython 2.2
*
* @return PyObject
*/
public PyObject __iternext__() {
PyObject row = fetchone();
return row.__nonzero__() ? row : null;
}
| Page 32 of 38 Prev | Index | Next |