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 <[EMAIL PROTECTED]>:
>
> >
> >
> > 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 [EMAIL PROTECTED]
> PostgreSQL JDBC Driver: http://www.retep.org.uk/postgres/
> RetepPDF PDF library for Java: http://www.retep.org.uk/pdf/
>
>
>
Dror Matalon