From: | Dror Matalon <dror(at)matal(dot)com> |
---|---|
To: | Peter T Mount <peter(at)retep(dot)org(dot)uk> |
Cc: | Greg Speegle <Greg(at)10happythings(dot)com>, pgsql-jdbc(at)postgresql(dot)org |
Subject: | Re: Re: [INTERFACES] Q on JDBC's resultset |
Date: | 2001-02-07 17:32:13 |
Message-ID: | Pine.BSF.4.21.0102070913140.70670-100000@dnai-216-15-97-241.cust.dnai.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-interfaces pgsql-jdbc |
Here's the code that I'm currently using. For Postgres, since there's
no tablename I pass it as an argument to the method (you can ignore that
part), for mysql I just check and see that all the table names are the
same.
Once I figure out that they're all in one table I check to see that
the resultset includes the primary key -- no primary key, no update.
I guess, since postgress supports oids, you could just fetch those
with the resultset and let the user update the table even if doesn't
have have a primary key. It does make things quite a bit more
complicated cause you need then to create a new query and somehow
hide the oid in the resultset.
--------------------------------------------------------------------------------
for (ii = 0; ii < numberColumns; ii++)
{
if (!tableNamePassed)
{
//if we're getting it in the result set check to see all
//columns are in one table
if (tableName == "") //first one
{
tableName = selectModel.dbSelect.columns[ii].table;
if(tableName.equals("") && (!tableNamePassed))
{
//tableName not passed and not from resultset. Can't update
return (false);
}
}
else
{
//if more than one table, not updatable
if (!(tableName.equals(selectModel.dbSelect.columns[ii].table)))
{
return (false);
}
}
}
queryColumns.addElement(selectModel.dbSelect.columns[ii].name);
}
try
{
// got the names of all the columns. They're all in one table
dbTable = new DBTable(dbConnect, tableName);
if(dbTable.primaryList.isEmpty())
{
return (false);
}
DBConsole.displayMessage("Checking for primary key");
Enumeration enumeration;
for (enumeration = dbTable.primaryList.elements();
enumeration.hasMoreElements(); )
{
colPos = (Integer) enumeration.nextElement();
if(!queryColumns.contains(dbTable.columns[colPos.intValue()].name))
{
return(false);
}
}
}
catch (Exception excep)
{
DBConsole.messageDialog(excep);
return(false);
}
--------------------------------------------------------------------------------
On Wed, 7 Feb 2001, Peter T Mount wrote:
> Quoting Greg Speegle <Greg(at)10happythings(dot)com>:
>
> >
> >
> > Peter T Mount wrote:
> >
> > > 7.1 has the beginings of an UpdateableResultSet. When I can work out
> > how to
> > > solve a few fundamental problems it shouldn't take long.
> > >
> > > Here's a few questions for people to see if they can figure it out:
> > >
> > > * How to detect what table a column belongs so. Required if the query
> > was a
> > > join of 2 or more tables.
> >
> > As I understand the JDBC spec, you are not supposed to be able to
> > update
> > through a ResultSet unless several criteria are met by the query,
> > including that the
> >
> > query is over exactly one table (to avoid problems like these). I don't
> > recall if
> > the other cases are also prohibited, but that would make the problem
> > easier.
>
> Yes it would make it easier. The problem I have is how to detect when it's just
> a single table.
>
> Peter
>
> --
> Peter Mount peter(at)retep(dot)org(dot)uk
> PostgreSQL JDBC Driver: http://www.retep.org.uk/postgres/
> RetepPDF PDF library for Java: http://www.retep.org.uk/pdf/
>
>
>
Dror Matalon
From | Date | Subject | |
---|---|---|---|
Next Message | JParker | 2001-02-07 17:59:44 | Re: Asychronous Query Processing via Libpq |
Previous Message | Christopher Masto | 2001-02-07 16:00:38 | An strftime function, and function name question |
From | Date | Subject | |
---|---|---|---|
Next Message | Bruce Momjian | 2001-02-07 19:12:26 | PostgreSQL and PHP persistent connections |
Previous Message | Barry Lind | 2001-02-07 17:31:42 | Re: [ADMIN] |