Added SQL proposals
authorkhartlage <khartlage>
Mon, 19 Apr 2004 22:13:48 +0000 (22:13 +0000)
committerkhartlage <khartlage>
Mon, 19 Apr 2004 22:13:48 +0000 (22:13 +0000)
net.sourceforge.phpeclipse/icons/obj16/column_obj.gif [new file with mode: 0644]
net.sourceforge.phpeclipse/icons/obj16/table_obj.gif [new file with mode: 0644]
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/PHPUiImages.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/PHPCompletionProposalComparator.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/BuiltInProposal.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/IdentifierProposal.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/SQLProposal.java [new file with mode: 0644]
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/TemplateProposal.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPCompletionProcessor.java

diff --git a/net.sourceforge.phpeclipse/icons/obj16/column_obj.gif b/net.sourceforge.phpeclipse/icons/obj16/column_obj.gif
new file mode 100644 (file)
index 0000000..1c1e2d4
Binary files /dev/null and b/net.sourceforge.phpeclipse/icons/obj16/column_obj.gif differ
diff --git a/net.sourceforge.phpeclipse/icons/obj16/table_obj.gif b/net.sourceforge.phpeclipse/icons/obj16/table_obj.gif
new file mode 100644 (file)
index 0000000..f4056f6
Binary files /dev/null and b/net.sourceforge.phpeclipse/icons/obj16/table_obj.gif differ
index abdb1f1..e56aeff 100644 (file)
@@ -39,12 +39,16 @@ public class PHPUiImages {
        protected static final String OVR_PREFIX = "ovr16";
        protected static final String CTOOL_PREFIX = "ctool16";
 
-       public static final String IMG_CLASS = NAME_PREFIX + "class_obj.gif";
+       public static final String IMG_CLASS = NAME_PREFIX + "class_default_obj.gif";
        public static final String IMG_DEFINE = NAME_PREFIX + "define_obj.gif";
        public static final String IMG_BUILTIN = NAME_PREFIX + "builtin_obj.gif";
        public static final String IMG_FUN = NAME_PREFIX + "fun_obj.gif";
        public static final String IMG_INC = NAME_PREFIX + "impc_obj.gif";
        public static final String IMG_VAR = NAME_PREFIX + "var_obj.gif";
+       
+       public static final String IMG_TABLE = NAME_PREFIX + "table_obj.gif";
+       public static final String IMG_COLUMN = NAME_PREFIX + "column_obj.gif";
+       
        public static final String IMG_OBJS_WARNING =
                NAME_PREFIX + "warning_obj.gif";
        public static final String IMG_OBJS_INFO = NAME_PREFIX + "info_obj.gif";
@@ -66,6 +70,12 @@ public class PHPUiImages {
                createManaged(OBJ_PREFIX, IMG_INC);
        public static final ImageDescriptor DESC_VAR =
                createManaged(OBJ_PREFIX, IMG_VAR);
+       
+       public static final ImageDescriptor DESC_TABLE =
+               createManaged(OBJ_PREFIX, IMG_TABLE);
+       public static final ImageDescriptor DESC_COLUMN =
+               createManaged(OBJ_PREFIX, IMG_COLUMN);
+       
        public static final ImageDescriptor DESC_OBJS_WARNING =
                createManaged(OBJ_PREFIX, IMG_OBJS_WARNING);
        public static final ImageDescriptor DESC_OBJS_INFO =
index 77007ae..3340c92 100644 (file)
@@ -9,9 +9,9 @@ public class PHPCompletionProposalComparator implements Comparator {
        /**
         * Constructor for CompletionProposalComparator.
         */
-       public PHPCompletionProposalComparator() {
-               fOrderAlphabetically= false;
-       }
+//     public PHPCompletionProposalComparator() {
+//             fOrderAlphabetically= false;
+//     }
        
        public void setOrderAlphabetically(boolean orderAlphabetically) {
                fOrderAlphabetically= orderAlphabetically;
index 8fa33ab..87d481d 100644 (file)
@@ -145,13 +145,13 @@ public class BuiltInProposal extends AbstractProposal { // implements IPHPComple
         case '\r' :
         case '\n' :
         case '\t' :
-          return 90;
+          return 50;
 
         default :
           return 0;
       }
     } else {
-      return 90;
+      return 50;
     }
   }
 
index 8628871..32769cb 100644 (file)
@@ -3,14 +3,12 @@
  * All Rights Reserved.
  */
 package net.sourceforge.phpdt.internal.ui.text.template;
-
 import net.sourceforge.phpdt.internal.corext.template.TemplateContext;
 import net.sourceforge.phpdt.internal.corext.template.TemplateMessages;
 import net.sourceforge.phpdt.internal.corext.template.php.PHPUnitContext;
 import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionManager;
 import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionUI;
 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
-
 import org.eclipse.jface.text.BadLocationException;
 import org.eclipse.jface.text.IDocument;
 import org.eclipse.jface.text.IRegion;
@@ -20,41 +18,41 @@ import org.eclipse.swt.graphics.Image;
 //import org.eclipse.jdt.internal.ui.text.link.LinkedPositionManager;
 //import org.eclipse.jdt.internal.ui.text.link.LinkedPositionUI;
 //import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
-
 /**
  * A PHP identifier proposal.
  */
-public class IdentifierProposal extends AbstractProposal { //implements IPHPCompletionProposal {
+public class IdentifierProposal extends AbstractProposal { //implements
+                                                           // IPHPCompletionProposal
+                                                           // {
   private final TemplateContext fContext;
   private final Image fImage_fun;
   private final Image fImage_var;
-
   //private TemplateBuffer fTemplateBuffer;
   private String fOldText;
   private final IRegion fRegion;
-//  private IRegion fSelectedRegion; // initialized by apply()
-
+  //  private IRegion fSelectedRegion; // initialized by apply()
   private final String fTemplate;
-//  private final ITextViewer fViewer;
-
+  //  private final ITextViewer fViewer;
   /**
    * Creates a template proposal with a template and its context.
-   * @param template  the template
-   * @param context   the context in which the template was requested.
-   * @param image     the icon of the proposal.
+   * 
+   * @param template
+   *            the template
+   * @param context
+   *            the context in which the template was requested.
+   * @param image
+   *            the icon of the proposal.
    */
-  public IdentifierProposal(String template, TemplateContext context, IRegion region, ITextViewer viewer, Image image_fun, Image image_var) {
+  public IdentifierProposal(String template, TemplateContext context,
+      IRegion region, ITextViewer viewer, Image image_fun, Image image_var) {
     super(viewer);
-
     fTemplate = template;
     fContext = context;
-//    fViewer = viewer;
-       fImage_fun= image_fun;
-    fImage_var= image_var;
+    //    fViewer = viewer;
+    fImage_fun = image_fun;
+    fImage_var = image_var;
     fRegion = region;
   }
-
-
   /*
    * @see ICompletionProposal#apply(IDocument)
    */
@@ -62,14 +60,11 @@ public class IdentifierProposal extends AbstractProposal { //implements IPHPComp
     try {
       //                   if (fTemplateBuffer == null)
       //                               fTemplateBuffer= fContext.evaluate(fTemplate);
-
       int start = fRegion.getOffset();
       int end = fRegion.getOffset() + fRegion.getLength();
-
       // insert template string
-    //  String templateString = fTemplate; // fTemplateBuffer.getString();     
+      //  String templateString = fTemplate; // fTemplateBuffer.getString();
       document.replace(start, end - start, fTemplate);
-
       // translate positions
       LinkedPositionManager manager = new LinkedPositionManager(document);
       //                       TemplatePosition[] variables= fTemplateBuffer.getVariables();
@@ -85,24 +80,19 @@ public class IdentifierProposal extends AbstractProposal { //implements IPHPComp
       //                               for (int j= 0; j != offsets.length; j++)
       //                                       manager.addPosition(offsets[j] + start, length);
       //                       }
-
       LinkedPositionUI editor = new LinkedPositionUI(fViewer, manager);
-      editor.setFinalCaretOffset(fTemplate.length()+start);
-   //   editor.setFinalCaretOffset(getCaretOffset(fTemplateBuffer) + start);
+      editor.setFinalCaretOffset(fTemplate.length() + start);
+      //   editor.setFinalCaretOffset(getCaretOffset(fTemplateBuffer) + start);
       editor.enter();
-
       fSelectedRegion = editor.getSelectedRegion();
-
     } catch (BadLocationException e) {
       PHPeclipsePlugin.log(e);
       openErrorDialog(e);
-
     }
     //      catch (CoreException e) {
     //                 handleException(e);
-    //     }       
+    //     }
   }
-
   /*
    * @see ICompletionProposal#getAdditionalProposalInfo()
    */
@@ -110,45 +100,37 @@ public class IdentifierProposal extends AbstractProposal { //implements IPHPComp
     //     try {
     //                 if (fTemplateBuffer == null)
     //                         fTemplateBuffer= fContext.evaluate(fTemplate);
-
     return textToHTML(fTemplate); // fTemplateBuffer.getString());
-
     //     } catch (CoreException e) {
-    //                 handleException(e);                 
+    //                 handleException(e);
     //                 return null;
     //     }
   }
-
   /*
    * @see ICompletionProposal#getContextInformation()
    */
   public IContextInformation getContextInformation() {
     return null;
   }
-
   /*
    * @see ICompletionProposal#getDisplayString()
    */
   public String getDisplayString() {
-    return fTemplate + TemplateMessages.getString("TemplateProposal.delimiter") + fTemplate; // $NON-NLS-1$ //$NON-NLS-1$
-    //         return fTemplate.getName() + ObfuscatorMessages.getString("TemplateProposal.delimiter") + fTemplate.getDescription(); // $NON-NLS-1$ //$NON-NLS-1$
+    return fTemplate + TemplateMessages.getString("TemplateProposal.delimiter") + fTemplate; // $NON-NLS-1$ 
   }
-
   /*
    * @see ICompletionProposal#getImage()
    */
   public Image getImage() {
-    if (fTemplate.charAt(0)=='$') {
+    if (fTemplate.charAt(0) == '$') {
       return fImage_var;
     }
-               return fImage_fun;
+    return fImage_fun;
   }
-
   /*
    * @see IJavaCompletionProposal#getRelevance()
    */
   public int getRelevance() {
-
     if (fContext instanceof PHPUnitContext) {
       PHPUnitContext context = (PHPUnitContext) fContext;
       switch (context.getCharacterBeforeStart()) {
@@ -157,14 +139,12 @@ public class IdentifierProposal extends AbstractProposal { //implements IPHPComp
         case '\r' :
         case '\n' :
         case '\t' :
-          return 90;
-
+          return 50;
         default :
           return 0;
       }
     } else {
-      return 90;
+      return 50;
     }
   }
-
 }
\ No newline at end of file
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/SQLProposal.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/SQLProposal.java
new file mode 100644 (file)
index 0000000..0ac931d
--- /dev/null
@@ -0,0 +1,149 @@
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+package net.sourceforge.phpdt.internal.ui.text.template;
+import net.sourceforge.phpdt.internal.corext.template.TemplateContext;
+import net.sourceforge.phpdt.internal.corext.template.php.PHPUnitContext;
+import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionManager;
+import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionUI;
+import net.sourceforge.phpeclipse.PHPeclipsePlugin;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.contentassist.IContextInformation;
+import org.eclipse.swt.graphics.Image;
+/**
+ * A PHP identifier proposal.
+ */
+public class SQLProposal extends AbstractProposal { //implements
+  // IPHPCompletionProposal
+  // {
+  private final TemplateContext fContext;
+  private final Image fImage_var;
+  private final IRegion fRegion;
+  private final String fColumnName;
+  private final String fTableName;
+  
+  private int fRelevance;
+  /**
+   * Creates a template proposal with a template and its context.
+   * 
+   * @param template
+   *            the template
+   * @param context
+   *            the context in which the template was requested.
+   * @param image
+   *            the icon of the proposal.
+   */
+  public SQLProposal(String tableName, TemplateContext context, IRegion region,
+      ITextViewer viewer, Image image_var) {
+    super(viewer);
+    fTableName = tableName;
+    fColumnName = null;
+    fContext = context;
+    fImage_var = image_var;
+    fRegion = region;
+    fRelevance = 0;
+  }
+  
+  public SQLProposal(String tableName, String columnName, TemplateContext context, IRegion region,
+      ITextViewer viewer, Image image_var) {
+    super(viewer);
+    fTableName = tableName;
+    fColumnName = columnName;
+    fContext = context;
+    fImage_var = image_var;
+    fRegion = region;
+    fRelevance = 0;
+  }
+  /*
+   * @see ICompletionProposal#apply(IDocument)
+   */
+  public void apply(IDocument document) {
+    try {
+      //                   if (fTemplateBuffer == null)
+      //                               fTemplateBuffer= fContext.evaluate(fTemplate);
+      int start = fRegion.getOffset();
+      int end = fRegion.getOffset() + fRegion.getLength();
+      String resultString = fTableName;
+      if (fColumnName!=null) {
+        resultString = fColumnName;
+      }
+      // insert template string
+      //  String templateString = fTemplate; // fTemplateBuffer.getString();
+      document.replace(start, end - start, resultString);
+      // translate positions
+      LinkedPositionManager manager = new LinkedPositionManager(document);
+      //                       TemplatePosition[] variables= fTemplateBuffer.getVariables();
+      //                       for (int i= 0; i != variables.length; i++) {
+      //                               TemplatePosition variable= variables[i];
+      //
+      //                               if (variable.isResolved())
+      //                                       continue;
+      //                               
+      //                               int[] offsets= variable.getOffsets();
+      //                               int length= variable.getLength();
+      //                               
+      //                               for (int j= 0; j != offsets.length; j++)
+      //                                       manager.addPosition(offsets[j] + start, length);
+      //                       }
+      LinkedPositionUI editor = new LinkedPositionUI(fViewer, manager);
+      editor.setFinalCaretOffset(resultString.length() + start);
+      //   editor.setFinalCaretOffset(getCaretOffset(fTemplateBuffer) + start);
+      editor.enter();
+      fSelectedRegion = editor.getSelectedRegion();
+    } catch (BadLocationException e) {
+      PHPeclipsePlugin.log(e);
+      openErrorDialog(e);
+    }
+    //      catch (CoreException e) {
+    //                 handleException(e);
+    //     }
+  }
+  /*
+   * @see ICompletionProposal#getAdditionalProposalInfo()
+   */
+  public String getAdditionalProposalInfo() {
+    if (fColumnName==null) {
+      return textToHTML(fTableName);  
+    }
+    return fColumnName+" (Table: "+fTableName+")";
+  }
+  
+  /*
+   * @see ICompletionProposal#getContextInformation()
+   */
+  public IContextInformation getContextInformation() {
+    return null;
+  }
+  /*
+   * @see ICompletionProposal#getDisplayString()
+   */
+  public String getDisplayString() {
+    if (fColumnName==null) {
+      return fTableName;  
+    }
+    return fColumnName+" (Table: "+fTableName+")"; // $NON-NLS-1$
+  }
+  /*
+   * @see ICompletionProposal#getImage()
+   */
+  public Image getImage() {
+    return fImage_var;
+  }
+  /*
+   * @see IJavaCompletionProposal#getRelevance()
+   */
+  public int getRelevance() {
+    return fRelevance;
+  }
+  /**
+   * @param relevance The relevance to set.
+   */
+  public void setRelevance(int relevance) {
+    fRelevance = relevance;
+  }
+}
\ No newline at end of file
index 2c629b0..5f9911c 100644 (file)
@@ -163,7 +163,7 @@ public class TemplateProposal extends AbstractProposal {
         case '\r' :
         case '\n' :
         case '\t' :
-          return 90;
+          return 85;
 
         default :
           return 0;
index ac3f814..7881cea 100644 (file)
@@ -32,11 +32,12 @@ import net.sourceforge.phpdt.internal.ui.text.java.PHPCompletionProposalComparat
 import net.sourceforge.phpdt.internal.ui.text.template.BuiltInEngine;
 import net.sourceforge.phpdt.internal.ui.text.template.DeclarationEngine;
 import net.sourceforge.phpdt.internal.ui.text.template.IdentifierEngine;
-import net.sourceforge.phpdt.internal.ui.text.template.IdentifierProposal;
+import net.sourceforge.phpdt.internal.ui.text.template.SQLProposal;
 import net.sourceforge.phpdt.internal.ui.text.template.TemplateEngine;
 import net.sourceforge.phpeclipse.IPreferenceConstants;
 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
 import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
+import net.sourceforge.phpeclipse.overlaypages.Util;
 import net.sourceforge.phpeclipse.phpeditor.PHPEditor;
 import net.sourceforge.phpeclipse.phpeditor.PHPSyntaxRdr;
 import org.eclipse.core.resources.IFile;
@@ -56,7 +57,6 @@ import org.eclipse.jface.text.contentassist.IContextInformationValidator;
 import org.eclipse.swt.graphics.Image;
 import org.eclipse.ui.IEditorPart;
 import org.eclipse.ui.IFileEditorInput;
-import net.sourceforge.phpeclipse.overlaypages.Util;
 import com.quantum.model.Bookmark;
 import com.quantum.model.BookmarkCollection;
 import com.quantum.model.NotConnectedException;
@@ -133,6 +133,27 @@ public class PHPCompletionProcessor implements IContentAssistProcessor {
       fPosition = position;
     }
   };
+  private class TableName {
+    String fTableName;
+    TableName() {
+      fTableName = null;
+    }
+    /**
+     * @return Returns the tableName.
+     */
+    public String getTableName() {
+      if (fTableName==null) {
+        return "<!--no-table-->";
+      }
+      return fTableName;
+    }
+    /**
+     * @param tableName The tableName to set.
+     */
+    public void setTableName(String tableName) {
+      fTableName = tableName;
+    }
+  }
   private char[] fProposalAutoActivationSet;
   protected IContextInformationValidator fValidator = new Validator();
   private TemplateEngine fTemplateEngine;
@@ -175,7 +196,7 @@ public class PHPCompletionProcessor implements IContentAssistProcessor {
         contextInformationPosition);
   }
   private int getLastToken(ITextViewer viewer, int completionPosition,
-      PHPUnitContext context) {
+      PHPUnitContext context, TableName tableName) {
     IDocument document = viewer.getDocument();
     int start = context.getStart();
     int end = context.getEnd();
@@ -206,13 +227,11 @@ public class PHPCompletionProcessor implements IContentAssistProcessor {
           System.out.println(startText);
         }
         int token = ITerminalSymbols.TokenNameEOF;
-        
-        token = getLastSQLToken(startText);
-        
+//        token = getLastSQLToken(startText);
+        tableName.setTableName(getLastSQLTableName(startText));
         Scanner scanner = ToolFactory.createScanner(false, false, false);
         scanner.setSource(startText.toCharArray());
         scanner.setPHPMode(true);
-        
         int beforeLastToken = ITerminalSymbols.TokenNameEOF;
         int lastToken = ITerminalSymbols.TokenNameEOF;
         try {
@@ -245,6 +264,114 @@ public class PHPCompletionProcessor implements IContentAssistProcessor {
     return lastSignificantToken;
   }
   
+  String getSQLTableName(String sqlText, int start) {
+    int tableNameStart = -1;
+    int currentCharacterPosition = start+1;
+    char ch;
+    try {
+      while(true) {
+      ch = sqlText.charAt(currentCharacterPosition++);
+      if (tableNameStart==-1 && Character.isJavaIdentifierStart(ch)) {
+        tableNameStart = currentCharacterPosition-1;
+      } else {
+        if (!Character.isJavaIdentifierPart(ch)) {
+          return sqlText.substring(tableNameStart, currentCharacterPosition-1);
+        } 
+      }
+      }
+    } catch (IndexOutOfBoundsException e) {
+      if (tableNameStart>=0) {
+        return sqlText.substring(tableNameStart, currentCharacterPosition-1);
+      }
+    }
+    return "";
+  }
+  private String getLastSQLTableName(String startText) {
+    int token;
+    // scan for sql identifiers
+    char ch = ' ';
+    int currentSQLPosition = startText.length();
+    int identEnd = -1;
+    String ident = null;
+    boolean whiteSpace = true;
+    try {
+      while (true) {
+        ch = startText.charAt(--currentSQLPosition);
+        if (ch >= 'A' && ch <= 'Z') {
+          if (identEnd < 0) {
+            identEnd = currentSQLPosition + 1;
+          }
+        } else if (ch >= 'a' && ch <= 'z') {
+          if (identEnd < 0) {
+            identEnd = currentSQLPosition + 1;
+          }
+        } else if (identEnd >= 0) {
+          ident = startText.substring(currentSQLPosition + 1, identEnd);
+          // select -- from -- where --
+          // update -- set -- where --
+          // insert into -- ( -- ) values ( -- )
+          if (ident.length() >= 4 && ident.length() <= 6) {
+            ident = ident.toLowerCase();
+            switch (ident.length()) {
+//              case 3 :
+//                if (ident.equals("set")) {
+//                  //                  System.out.println("set");
+//                  token = ITerminalSymbols.TokenNameSQLset;
+//                  return token;
+//                }
+//                break;
+              case 4 :
+                if (ident.equals("from")) {
+                  //                  System.out.println("from");
+                  token = ITerminalSymbols.TokenNameSQLfrom;
+                  return getSQLTableName(startText, identEnd);
+                } else if (ident.equals("into")) {
+                  //                System.out.println("into");
+                  token = ITerminalSymbols.TokenNameSQLinto;
+                  return getSQLTableName(startText, identEnd);
+                }
+                break;
+//              case 5 :
+//                if (ident.equals("where")) {
+//                  //                  System.out.println("where");
+//                  token = ITerminalSymbols.TokenNameSQLwhere;
+//                  return token;
+//                }
+//                break;
+              case 6 :
+//                if (ident.equals("select")) {
+//                  //                  System.out.println("select");
+//                  token = ITerminalSymbols.TokenNameSQLselect;
+//                  return token;
+//                } else if (ident.equals("insert")) {
+//                  //                  System.out.println("insert");
+//                  token = ITerminalSymbols.TokenNameSQLinsert;
+//                  return token;
+//                } else 
+                if (ident.equals("update")) {
+                  //                  System.out.println("update");
+                  token = ITerminalSymbols.TokenNameSQLupdate;
+                  return getSQLTableName(startText, identEnd);
+                } 
+//                else if (ident.equals("values")) {
+//                  //                System.out.println("values");
+//                  token = ITerminalSymbols.TokenNameSQLvalues;
+//                  return token;
+//                }
+                break;
+            }
+          }
+          whiteSpace = false;
+          identEnd = -1;
+        } else if (Character.isWhitespace(ch)) {
+        } else {
+          whiteSpace = false;
+        }
+      }
+    } catch (IndexOutOfBoundsException e) {
+    }
+    return "<!--no-table-->";
+  }
   /**
    * Detect the last significant SQL token in the text before the completion
    * 
@@ -279,44 +406,45 @@ public class PHPCompletionProcessor implements IContentAssistProcessor {
             switch (ident.length()) {
               case 3 :
                 if (ident.equals("set")) {
-//                  System.out.println("set");
+                  //                  System.out.println("set");
                   token = ITerminalSymbols.TokenNameSQLset;
                   return token;
                 }
                 break;
               case 4 :
                 if (ident.equals("from")) {
-//                  System.out.println("from");
+                  //                  System.out.println("from");
                   token = ITerminalSymbols.TokenNameSQLfrom;
+                  //getSQLTableName();
                   return token;
                 } else if (ident.equals("into")) {
-//                System.out.println("into");
+                  //                System.out.println("into");
                   token = ITerminalSymbols.TokenNameSQLinto;
                   return token;
                 }
                 break;
               case 5 :
                 if (ident.equals("where")) {
-//                  System.out.println("where");
+                  //                  System.out.println("where");
                   token = ITerminalSymbols.TokenNameSQLwhere;
                   return token;
                 }
                 break;
               case 6 :
                 if (ident.equals("select")) {
-//                  System.out.println("select");
+                  //                  System.out.println("select");
                   token = ITerminalSymbols.TokenNameSQLselect;
                   return token;
                 } else if (ident.equals("insert")) {
-//                  System.out.println("insert");
+                  //                  System.out.println("insert");
                   token = ITerminalSymbols.TokenNameSQLinsert;
                   return token;
                 } else if (ident.equals("update")) {
-//                  System.out.println("update");
+                  //                  System.out.println("update");
                   token = ITerminalSymbols.TokenNameSQLupdate;
                   return token;
                 } else if (ident.equals("values")) {
-//                System.out.println("values");
+                  //                System.out.println("values");
                   token = ITerminalSymbols.TokenNameSQLvalues;
                   return token;
                 }
@@ -334,7 +462,6 @@ public class PHPCompletionProcessor implements IContentAssistProcessor {
     }
     return ITerminalSymbols.TokenNameEOF;
   }
-  
   private ICompletionProposal[] internalComputeCompletionProposals(
       ITextViewer viewer, int offset, int contextOffset) {
     IDocument document = viewer.getDocument();
@@ -363,7 +490,8 @@ public class PHPCompletionProcessor implements IContentAssistProcessor {
         document, offset, 0);
     PHPUnitContext context = (PHPUnitContext) phpContextType.createContext();
     String prefix = context.getKey();
-    int lastSignificantToken = getLastToken(viewer, offset, context);
+    TableName sqlTable = new TableName();
+    int lastSignificantToken = getLastToken(viewer, offset, context, sqlTable);
     boolean useClassMembers = (lastSignificantToken == ITerminalSymbols.TokenNameMINUS_GREATER)
         || (lastSignificantToken == ITerminalSymbols.TokenNameVariable)
         || (lastSignificantToken == ITerminalSymbols.TokenNamenew);
@@ -426,7 +554,7 @@ public class PHPCompletionProcessor implements IContentAssistProcessor {
               IPreferenceConstants.PHP_BOOKMARK_DEFAULT);
           if (bookmarkString != null && !bookmarkString.equals("")) {
             Bookmark bookmark = sqlBookMarks.find(bookmarkString);
-            ArrayList list = new ArrayList();
+            ArrayList sqlList = new ArrayList();
             if (bookmark != null && !bookmark.isConnected()) {
               new ConnectionUtil().connect(bookmark, null);
             }
@@ -434,43 +562,68 @@ public class PHPCompletionProcessor implements IContentAssistProcessor {
               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 = metaData.getTables(null, null, prefix + "%",
-                      null);
-                  while (set.next()) {
-                    //                  String tempSchema = set.getString("TABLE_SCHEM");
-                    //                  tempSchema = (tempSchema == null) ? "" :
-                    // tempSchema.trim();
-                    String tableName = set.getString("TABLE_NAME");
-                    tableName = (tableName == null) ? "" : tableName.trim();
-                    if (tableName != null && tableName.length() > 0) {
-                      list.add(tableName);
+                  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.close();
-                  set = metaData.getColumns(null, null, "%", prefix + "%");
+                  set = metaData.getColumns(null, null, "%",
+                      prefixWithoutDollar + "%");
+                  SQLProposal sqlProposal;
                   while (set.next()) {
-                    String tableName = set.getString("COLUMN_NAME");
-                    tableName = (tableName == null) ? "" : tableName.trim();
-                    if (tableName != null && tableName.length() > 0) {
-                      list.add(tableName);
-                    }
+                    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) {
-                      list.add(tableName);
+                    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[list.size()];
-                  for (int i = 0; i < list.size(); i++) {
-                    sqlResults[i] = new IdentifierProposal(
-                        (String) list.get(i), context, region, viewer,
-                        PHPUiImages.get(PHPUiImages.IMG_FUN), PHPUiImages
-                            .get(PHPUiImages.IMG_VAR));
+                  sqlResults = new IPHPCompletionProposal[sqlList.size()];
+                  for (int i = 0; i < sqlList.size(); i++) {
+                    sqlResults[i] = (SQLProposal) sqlList.get(i);
                   }
                 }
               } catch (NotConnectedException e) {