/** * Returns true if table has a Primary key. * * @return true if table is having a primary key, otherwise returns false. * @throws SQLException if there sql statement can not be completed or an error occures. */ protected boolean tableHasPrimaryKey() throws SQLException { if (!(_info[0] instanceof ITableInfo)) { return false; } ITableInfo ti = (ITableInfo) _info[0]; SQLDatabaseMetaData md = _session.getSQLConnection().getSQLMetaData(); PrimaryKeyInfo[] pks = md.getPrimaryKey(ti); return (pks != null && pks.length > 0); } }
/** * Create the <TT>IDataSet</TT> to be displayed in this tab. */ protected IDataSet createDataSet() throws DataSetException { final ISQLConnection conn = getSession().getSQLConnection(); IDataSet result = null; SQLDatabaseMetaData md = conn.getSQLMetaData(); result = md.getPrimaryKey(getTableInfo(), new int[] { 6, 5, 4 }, true); return result; } }
/** * Create the <TT>IDataSet</TT> to be displayed in this tab. */ protected IDataSet createDataSet() throws DataSetException { final ISQLConnection conn = getSession().getSQLConnection(); IDataSet result = null; SQLDatabaseMetaData md = conn.getSQLMetaData(); result = md.getPrimaryKey(getTableInfo(), new int[] { 6, 5, 4 }, true); return result; } }
PrimaryKeyInfo[] pkinfos = md.getPrimaryKey(catalog, schema, tableName);
public String getPrimaryKeyColumn() { String primaryKey = ""; try { ISQLConnection con = _session.getSQLConnection(); SQLDatabaseMetaData db = con.getSQLMetaData(); PrimaryKeyInfo[] infos = db.getPrimaryKey(getTableInfo()); for (int i=0; i < infos.length; i++) { primaryKey = infos[i].getColumnName(); } } catch (SQLException ex) { _session.showErrorMessage(ex); } return primaryKey; } }
/** * @throws SQLException */ private void showCustomDialog() throws SQLException { ITableInfo ti = (ITableInfo) _info[0]; TableColumnInfo[] columns = getPkTableColumns(ti); // Show the user a dialog with a list of columns and ask them to select customDialog = new ColumnListDialog(columns, ColumnListDialog.DROP_PRIMARY_KEY_MODE); customDialog.addColumnSelectionListener(new ExecuteListener()); customDialog.addEditSQLListener(new EditSQLListener(customDialog)); customDialog.addShowSQLListener(new ShowSQLListener(i18n.SHOWSQL_DIALOG_TITLE, customDialog)); customDialog.setLocationRelativeTo(SessionUtils.getOwningFrame(_session)); customDialog.setMultiSelection(); // We use simple name here so that the user can choose for themselves whether or not to qualify the // table name. This also addresses Bug #3171762 which results in "double qualifying" the table name // if the user's preference is to qualify table names. customDialog.setTableName(ti.getSimpleName()); SQLDatabaseMetaData md = _session.getSQLConnection().getSQLMetaData(); PrimaryKeyInfo[] infos = md.getPrimaryKey(ti); String pkName = infos[0].getSimpleName(); customDialog.setPrimaryKeyName(pkName); customDialog.setVisible(true); }