[JDBC] UpdateableResultSet patch (not finished yet!)
Hello, I have, for some time, now, been working on the updateable resultset class. Please have a look at http://www.miranda.org/~ola/jdbcupr.diff, and let me know what you think. It is only rudimentary at the moment. Things to consider: * Parsing of query. Very hackish at the moment. * Concurrency check. Things that need work: * Documentation * Inserting - nothing done as of yet. * The test case needs to be more elaborate. Ola -- Ola Sundell [EMAIL PROTECTED] - [EMAIL PROTECTED] - [EMAIL PROTECTED] http://miranda.org/~ola ---(end of broadcast)--- TIP 3: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to [EMAIL PROTECTED] so that your message can get through to the mailing list cleanly
Re: [JDBC] UpdateableResultSets and concurrency.
On Sun, 8 Jul 2001, Ola Sundell wrote: On Tue, 26 Jun 2001, Dave Cramer wrote: Ola, How are you planning on determining if the underlying data has been changed by some other process? There is a system column called xmin which can be used, however you will have to add it to the select. Dave At first, I will let the backend handle any and all problems that might occur. I will simply forward any exceptions I get, and let the overlying code handle the problems. I checked the MySQL driver, and that is how they are doing it. I wonder how it works with non-free databases. Does anyone here know? Silly me. When I woke up this morning, I realised that MySQL doesn't support transactions. I re-read the JDBC spec, and I will do a simple optimistic concurrency control by starting a transaction, re-reading the row and checking the values. mvh Ola -- Ola Sundell [EMAIL PROTECTED] - [EMAIL PROTECTED] - [EMAIL PROTECTED] http://miranda.org/~ola ---(end of broadcast)--- TIP 5: Have you checked our extensive FAQ? http://www.postgresql.org/users-lounge/docs/faq.html
[JDBC] UpdateableResultSets and concurrency.
On Tue, 26 Jun 2001, Dave Cramer wrote: Ola, How are you planning on determining if the underlying data has been changed by some other process? There is a system column called xmin which can be used, however you will have to add it to the select. Dave At first, I will let the backend handle any and all problems that might occur. I will simply forward any exceptions I get, and let the overlying code handle the problems. I checked the MySQL driver, and that is how they are doing it. I wonder how it works with non-free databases. Does anyone here know? Ola -- Ola Sundell [EMAIL PROTECTED] - [EMAIL PROTECTED] - [EMAIL PROTECTED] http://miranda.org/~ola ---(end of broadcast)--- TIP 6: Have you searched our list archives? http://www.postgresql.org/search.mpl
[JDBC] getTableName() in ResultSetMetaData
Hello. I've been hacking a bit, and I've come to a conclusion, which may or may not be true; to implement quite a number of things in the ResultSetMetaData class, we'll need to implement getTableName(int colnum), and to implement getTable(), we need additional information from the backend, like the relid from pg_class, where relid is SELECT relid FROM pg_class WHERE relname = 'table_where_col_is_from', added to the Field class. It would, too, be good to include attnum from pg_attribute, too. This will also ease implementation of things like isAutoIncrement(int colnum), if you define auto incrementation as having a DEFAULT value which is read from a sequence that is incremented one step at a time. I really need this feature (and I want it to behave like I described, as you might have guessed :). An idea, to make the definition of a column which "auto increments", is to alter table pg_attribute add attisserial boolean, and then just set that, if the newly-created column is serial, and use the pg_attribute column to check whether it is auto incrementing, or not. Now, I know of two things that you probably will say: a) Feature freeze - not in 7.1 (naturally). I can understand that, and I can also, sorta, wait until 7.2 development starts...but I'd love to see this asap, naturall b) Postgresql doesn't really support auto incrementation. I know that, too, but I want, due to ejb-specific reasons, be able to gather information about whether the column is auto-incrementing, or not. I can, of course, write a small hack in my own app, but this seems much neater. :) OK, did that make sense at all? Ola -- --- Ola Sundell [EMAIL PROTECTED] - [EMAIL PROTECTED] - [EMAIL PROTECTED] http://miranda.org/~ola PGP key information: pub 1024/744E6D8D 2000/02/13 Ola Sundell [EMAIL PROTECTED] Key fingerprint = 8F CA 7C 6F EC 0D C0 23 1E 08 BF 32 FC 37 24 E3 ---(end of broadcast)--- TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]
[JDBC] PATCH to org/postgresql/jdbc2/DatabaseMetaData.java
--- postgresql-7.1beta4/src/interfaces/jdbc/org/postgresql/jdbc2/DatabaseMetaData.java Mon Jan 29 03:53:56 2001 +++ postgresql-7.1beta4-new/src/interfaces/jdbc/org/postgresql/jdbc2/DatabaseMetaData.java Sat Feb 17 10:22:38 2001 @@ -1048,7 +1048,7 @@ /** * Can statements remain open across commits? They may, but * this driver cannot guarentee that. In further reflection. - * we are talking a Statement object jere, so the answer is + * we are talking a Statement object here, so the answer is * yes, since the Statement is only a vehicle to ExecSQL() * * @return true if they always remain open; false otherwise @@ -2185,6 +2185,81 @@ ); } + private Vector importLoop(java.sql.ResultSet keyRelation) throws SQLException { +String s,s2; +String origTable=null, primTable=new String(""), schema; +int i; +Vector v; + +s=keyRelation.getString(1); +s2=s; +System.out.println(s); +v=new Vector(); +for (i=0;;i++) { + s=s.substring(s.indexOf("\\000")+4); + if (s.compareTo("")==0) { + System.out.println(); + break; + } + s2=s.substring(0,s.indexOf("\\000")); + switch (i) { + case 0: + origTable=s2; + break; + case 1: + primTable=s2; + break; + case 2: + schema=s2; + break; + default: + v.add(s2); + } + } + + java.sql.ResultSet rstmp=connection.ExecSQL("select * from "+origTable+" where 1=0"); + java.sql.ResultSetMetaData origCols=rstmp.getMetaData(); + + String stmp; + Vector tuples=new Vector(); + byte tuple[][]; + + // the foreign keys are only on even positions in the Vector. + for (i=0;iv.size();i+=2) { +stmp=(String)v.elementAt(i); + +for (int j=1;j=origCols.getColumnCount();j++) { + if (stmp.compareTo(origCols.getColumnName(j))==0) { + tuple=new byte[14][0]; + + for (int k=0;k14;k++) + tuple[k]=null; + + //PKTABLE_NAME + tuple[2]=primTable.getBytes(); + //PKTABLE_COLUMN + stmp=(String)v.elementAt(i+1); + tuple[3]=stmp.getBytes(); + //FKTABLE_NAME + tuple[6]=origTable.getBytes(); + //FKCOLUMN_NAME + tuple[7]=origCols.getColumnName(j).getBytes(); + //KEY_SEQ + tuple[8]=Integer.toString(j).getBytes(); + + tuples.add(tuple); + + System.out.println(origCols.getColumnName(j)+ + ": "+j+" - "+primTable+": "+ + (String)v.elementAt(i+1)); + break; + } +} + } + + return tuples; + } + /** * Get a description of the primary key columns that are * referenced by a table's foreign key columns (the primary keys @@ -2238,8 +2313,39 @@ */ public java.sql.ResultSet getImportedKeys(String catalog, String schema, String table) throws SQLException { -// XXX-Not Implemented -return null; +// Added by Ola Sundell [EMAIL PROTECTED] +// FIXME: error checking galore! +java.sql.ResultSet rsret; +Field f[]=new Field[14]; +byte tuple[][]; + +f[0]=new Field(connection, "PKTABLE_CAT", iVarcharOid, 32); +f[1]=new Field(connection, "PKTABLE_SCHEM", iVarcharOid, 32); +f[2]=new Field(connection, "PKTABLE_NAME", iVarcharOid, 32); +f[3]=new Field(connection, "PKCOLUMN_NAME", iVarcharOid, 32); +f[4]=new Field(connection, "FKTABLE_CAT", iVarcharOid, 32); +f[5]=new Field(connection, "FKTABLE_SCHEM", iVarcharOid, 32); +f[6]=new Field(connection, "FKTABLE_NAME", iVarcharOid, 32); +f[7]=new Field(connection, "FKCOLUMN_NAME", iVarcharOid, 32); +f[8]=new Field(connection, "KEY_SEQ", iInt2Oid, 2); +f[9]=new Field(connection, "UPDATE_RULE", iInt2Oid, 2); +f[10]=new Field(connection, "DELETE_RULE", iInt2Oid, 2); +f[11]=new Field(connection, "FK_NAME", iVarcharOid, 32); +f[12]=new Field(connection, "PK_NAME", iVarcharOid, 32); +f[13]=new Field(connection, "DEFERRABILITY", iInt2Oid, 2); + +java.sql.ResultSet rs=connection.ExecSQL("select t.tgargs "+ + "from pg_class as c, pg_trigger as t "+ + "where c.relname like '"+table+"' and c.relfilenode=t.tgrelid"); +Vector tuples=new Vector(); + +while (rs.next()) { + tuples.addAll(importLoop(rs)); +} + +rsret=new ResultSet(connection, f, tuples, "OK", 1); + +return rsret; } /**