From: brian z. <bz...@us...> - 2001-12-12 17:19:49
|
Update of /cvsroot/jython/jython/com/ziclix/python/sql In directory usw-pr-cvs1:/tmp/cvs-serv17905/ziclix/python/sql Modified Files: PyConnection.java PyExtendedCursor.java Log Message: improved __methods__ and __members__ Index: PyConnection.java =================================================================== RCS file: /cvsroot/jython/jython/com/ziclix/python/sql/PyConnection.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PyConnection.java 2001/12/10 03:37:40 1.3 --- PyConnection.java 2001/12/12 17:19:45 1.4 *************** *** 41,44 **** --- 41,69 ---- } + /** Field __members__ */ + protected static PyList __members__; + + /** Field __methods__ */ + protected static PyList __methods__; + + static { + PyObject[] m = new PyObject[5]; + + m[0] = new PyString("close"); + m[1] = new PyString("commit"); + m[2] = new PyString("cursor"); + m[3] = new PyString("rollback"); + m[4] = new PyString("nativesql"); + __methods__ = new PyList(m); + m = new PyObject[6]; + m[0] = new PyString("autocommit"); + m[1] = new PyString("dbname"); + m[2] = new PyString("dbversion"); + m[3] = new PyString("driverversion"); + m[4] = new PyString("url"); + m[5] = new PyString("__connection__"); + __members__ = new PyList(m); + } + /** * Create a PyConnection with the open connection. *************** *** 82,85 **** --- 107,111 ---- dict.__setitem__("cursor", new ConnectionFunc("cursor", 2, 0, 1, zxJDBC.getString("cursor"))); dict.__setitem__("rollback", new ConnectionFunc("rollback", 3, 0, 0, zxJDBC.getString("rollback"))); + dict.__setitem__("nativesql", new ConnectionFunc("nativesql", 4, 1, 1, zxJDBC.getString("nativesql"))); // hide from python *************** *** 155,158 **** --- 181,188 ---- } else if ("__connection__".equals(name)) { return Py.java2py(this.connection); + } else if ("__methods__".equals(name)) { + return __methods__; + } else if ("__members__".equals(name)) { + return __members__; } *************** *** 225,228 **** --- 255,282 ---- /** + * Converts the given SQL statement into the system's native SQL grammar. A + * driver may convert the JDBC sql grammar into its system's native SQL grammar + * prior to sending it; this method returns the native form of the statement + * that the driver would have sent. + * + * @param PyObject a SQL statement that may contain one or more '?' parameter placeholders + * + * @return the native form of this statement + * + */ + public PyObject nativesql(PyObject nativeSQL) { + + if (nativeSQL == Py.None) { + return Py.None; + } + + try { + return Py.newString(this.connection.nativeSQL(nativeSQL.__str__().toString())); + } catch (SQLException e) { + throw zxJDBC.newError(e); + } + } + + /** * Return a new Cursor Object using the connection. If the database does not * provide a direct cursor concept, the module will have to emulate cursors *************** *** 324,327 **** --- 378,384 ---- case 2 : return c.cursor(arg.__nonzero__()); + + case 4 : + return c.nativesql(arg); default : Index: PyExtendedCursor.java =================================================================== RCS file: /cvsroot/jython/jython/com/ziclix/python/sql/PyExtendedCursor.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** PyExtendedCursor.java 2001/12/10 03:37:40 1.4 --- PyExtendedCursor.java 2001/12/12 17:19:45 1.5 *************** *** 54,59 **** --- 54,64 ---- m[6] = new PyString("statistics"); __methods__ = new PyList(m); + + __methods__.extend(PyCursor.__methods__); + m = new PyObject[0]; __members__ = new PyList(m); + + __members__.extend(PyCursor.__members__); } *************** *** 110,113 **** --- 115,135 ---- dict.__setitem__("classDictInit", null); dict.__setitem__("toString", null); + } + + /** + * Finds the attribute. + * + * @param name the name of the attribute of interest + * @return the value for the attribute of the specified name + */ + public PyObject __findattr__(String name) { + + if ("__methods__".equals(name)) { + return __methods__; + } else if ("__members__".equals(name)) { + return __members__; + } + + return super.__findattr__(name); } |