Contributors:
IBM Corporation - Initial implementation
- Klaus Hartlage - www.eclipseproject.de
**********************************************************************/
package net.sourceforge.phpeclipse.phpeditor.php;
}
IPHPCompletionProposal[] sqlResults = new IPHPCompletionProposal[0];
if (project != null) {
- // Get The Database bookmark from the Quantum SQL plugin:
- BookmarkCollection sqlBookMarks = BookmarkCollection.getInstance();
- if (sqlBookMarks != null) {
- String bookmarkString = Util.getMiscProjectsPreferenceValue(project,
- IPreferenceConstants.PHP_BOOKMARK_DEFAULT);
- if (bookmarkString != null && !bookmarkString.equals("")) {
- Bookmark bookmark = sqlBookMarks.find(bookmarkString);
- ArrayList sqlList = new ArrayList();
- if (bookmark != null && !bookmark.isConnected()) {
- new ConnectionUtil().connect(bookmark, null);
- }
- if (bookmark != null && bookmark.isConnected()) {
- try {
- Connection connection = bookmark.getConnection();
- DatabaseMetaData metaData = connection.getMetaData();
-
- if (metaData != null) {
- int start = context.getStart();
- int end = context.getEnd();
- String foundSQLTableName = sqlTable.getTableName();
- String tableName;
- String columnName;
- String prefixWithoutDollar = prefix;
- boolean isDollarPrefix = false;
- if (prefix.length() > 0 && prefix.charAt(0) == '$') {
- prefixWithoutDollar = prefix.substring(1);
- isDollarPrefix = true;
- }
- IRegion region = new Region(start, end - start);
- ResultSet set;
- if (!isDollarPrefix) {
- set = metaData.getTables(null, null, prefixWithoutDollar
- + "%", null);
- while (set.next()) {
- // String tempSchema = set.getString("TABLE_SCHEM");
- // tempSchema = (tempSchema == null) ? "" :
- // tempSchema.trim();
- tableName = set.getString("TABLE_NAME");
- tableName = (tableName == null) ? "" : tableName.trim();
- if (tableName != null && tableName.length() > 0) {
- sqlList.add(new SQLProposal(tableName, context, region,
- viewer, PHPUiImages.get(PHPUiImages.IMG_TABLE)));
- }
- }
- set.close();
- }
- set = metaData.getColumns(null, null, "%",
- prefixWithoutDollar + "%");
- SQLProposal sqlProposal;
- while (set.next()) {
- columnName = set.getString("COLUMN_NAME");
- columnName = (columnName == null) ? "" : columnName.trim();
- tableName = set.getString("TABLE_NAME");
- tableName = (tableName == null) ? "" : tableName.trim();
- if (tableName != null && tableName.length() > 0
- && columnName != null && columnName.length() > 0) {
- if (isDollarPrefix) {
- sqlProposal = new SQLProposal(tableName, "$"
- + columnName, context, region, viewer, PHPUiImages
- .get(PHPUiImages.IMG_COLUMN));
- } else {
- sqlProposal = new SQLProposal(tableName, columnName,
- context, region, viewer, PHPUiImages
- .get(PHPUiImages.IMG_COLUMN));
- }
- if (tableName.equals(foundSQLTableName)) {
- sqlProposal.setRelevance(90);
- } else if (tableName.indexOf(foundSQLTableName) >= 0) {
- sqlProposal.setRelevance(75);
- }
- sqlList.add(sqlProposal);
- }
- }
- set.close();
- sqlResults = new IPHPCompletionProposal[sqlList.size()];
- for (int i = 0; i < sqlList.size(); i++) {
- sqlResults[i] = (SQLProposal) sqlList.get(i);
- }
- }
- } catch (NotConnectedException e) {
- // ignore this - not mission critical
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
+ sqlResults = getSQLProposals(viewer, project, context, prefix, sqlTable, sqlResults);
}
// concatenate the result arrays
IPHPCompletionProposal[] total;
return new IPHPCompletionProposal[0];
}
+ /**
+ * @param viewer
+ * @param project
+ * @param context
+ * @param prefix
+ * @param sqlTable
+ * @param sqlResults
+ * @return
+ */
+ private IPHPCompletionProposal[] getSQLProposals(ITextViewer viewer, IProject project, JavaContext context, String prefix, TableName sqlTable, IPHPCompletionProposal[] sqlResults) {
+ // Get The Database bookmark from the Quantum SQL plugin:
+ BookmarkCollection sqlBookMarks = BookmarkCollection.getInstance();
+ if (sqlBookMarks != null) {
+ String bookmarkString = Util.getMiscProjectsPreferenceValue(project,
+ IPreferenceConstants.PHP_BOOKMARK_DEFAULT);
+ if (bookmarkString != null && !bookmarkString.equals("")) {
+ Bookmark bookmark = sqlBookMarks.find(bookmarkString);
+ ArrayList sqlList = new ArrayList();
+ if (bookmark != null && !bookmark.isConnected()) {
+ new ConnectionUtil().connect(bookmark, null);
+ }
+ if (bookmark != null && bookmark.isConnected()) {
+ try {
+ Connection connection = bookmark.getConnection();
+ DatabaseMetaData metaData = connection.getMetaData();
+
+ if (metaData != null) {
+ int start = context.getStart();
+ int end = context.getEnd();
+ String foundSQLTableName = sqlTable.getTableName();
+ String tableName;
+ String columnName;
+ String prefixWithoutDollar = prefix;
+ boolean isDollarPrefix = false;
+ if (prefix.length() > 0 && prefix.charAt(0) == '$') {
+ prefixWithoutDollar = prefix.substring(1);
+ isDollarPrefix = true;
+ }
+ IRegion region = new Region(start, end - start);
+ ResultSet set;
+ if (!isDollarPrefix) {
+ set = metaData.getTables(null, null, prefixWithoutDollar
+ + "%", null);
+ while (set.next()) {
+ // String tempSchema = set.getString("TABLE_SCHEM");
+ // tempSchema = (tempSchema == null) ? "" :
+ // tempSchema.trim();
+ tableName = set.getString("TABLE_NAME");
+ tableName = (tableName == null) ? "" : tableName.trim();
+ if (tableName != null && tableName.length() > 0) {
+ sqlList.add(new SQLProposal(tableName, context, region,
+ viewer, PHPUiImages.get(PHPUiImages.IMG_TABLE)));
+ }
+ }
+ set.close();
+ }
+ set = metaData.getColumns(null, null, "%",
+ prefixWithoutDollar + "%");
+ SQLProposal sqlProposal;
+ while (set.next()) {
+ columnName = set.getString("COLUMN_NAME");
+ columnName = (columnName == null) ? "" : columnName.trim();
+ tableName = set.getString("TABLE_NAME");
+ tableName = (tableName == null) ? "" : tableName.trim();
+ if (tableName != null && tableName.length() > 0
+ && columnName != null && columnName.length() > 0) {
+ if (isDollarPrefix) {
+ sqlProposal = new SQLProposal(tableName, "$"
+ + columnName, context, region, viewer, PHPUiImages
+ .get(PHPUiImages.IMG_COLUMN));
+ } else {
+ sqlProposal = new SQLProposal(tableName, columnName,
+ context, region, viewer, PHPUiImages
+ .get(PHPUiImages.IMG_COLUMN));
+ }
+ if (tableName.equals(foundSQLTableName)) {
+ sqlProposal.setRelevance(90);
+ } else if (tableName.indexOf(foundSQLTableName) >= 0) {
+ sqlProposal.setRelevance(75);
+ }
+ sqlList.add(sqlProposal);
+ }
+ }
+ set.close();
+ sqlResults = new IPHPCompletionProposal[sqlList.size()];
+ for (int i = 0; i < sqlList.size(); i++) {
+ sqlResults[i] = (SQLProposal) sqlList.get(i);
+ }
+ }
+ } catch (NotConnectedException e) {
+ // ignore this - not mission critical
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ return sqlResults;
+ }
+
private int guessContextInformationPosition(ITextViewer viewer, int offset) {
int contextPosition = offset;
IDocument document = viewer.getDocument();