improved syntax highlighting (php tag/return keyword/brackets and operators)
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / wizards / BaseSQLPage.java
index 459a949..a7a84fe 100644 (file)
@@ -1,10 +1,14 @@
 package com.quantum.wizards;
 
+import java.sql.SQLException;
+
 import com.quantum.adapters.DatabaseAdapter;
 import com.quantum.model.Bookmark;
 import com.quantum.model.Column;
 import com.quantum.model.ConnectionException;
 import com.quantum.model.Entity;
+import com.quantum.model.NotConnectedException;
+import com.quantum.sql.SQLResults;
 import com.quantum.sql.TableRow;
 import com.quantum.view.ViewHelper;
 import com.quantum.view.tableview.TableAdapter;
@@ -12,7 +16,8 @@ import com.quantum.view.tableview.TableAdapter;
 import org.eclipse.jface.wizard.WizardPage;
 
 /**
- * @author BC
+ * @author BC Holmes
+ * @author Sirkware
  */
 public abstract class BaseSQLPage extends WizardPage implements SQLPage {
 
@@ -23,26 +28,45 @@ public abstract class BaseSQLPage extends WizardPage implements SQLPage {
         super(pageName);
     }
     public boolean performFinish() {
-        try {
-            Bookmark bookmark = this.adapter.getBookmark();
-            bookmark.addQuery(getQueryText());
-            ViewHelper.tryGetResults(getShell(), bookmark.getConnection(), getQueryText());
-        } catch (ConnectionException e) {
-            e.printStackTrace();
-        }
-        return true;
-    }
+               try {
+                       Bookmark bookmark = this.adapter.getBookmark();
+                       bookmark.addQuery(getQueryText());
+                       SQLResults sqlResults = ViewHelper.tryGetResults(getShell(),
+                                       bookmark.getConnection(), getQueryText());
+                       return sqlResults.isError() ? false : true;
+               } catch (ConnectionException e) {
+                       e.printStackTrace();
+                       return false;
+               }
+       }
+    
     protected abstract String getQueryText();
     protected void appendColumn(StringBuffer whereClause, Entity entity, String columnName, DatabaseAdapter adapter, String value) {
-            
-        if (adapter != null && entity != null && entity.getColumn(columnName) != null) {
-            Column column = entity.getColumn(columnName);
+        
+        if (adapter != null && entity != null && getColumn(entity, columnName) != null) {
+            Column column = getColumn(entity, columnName);
                whereClause.append(adapter.quote(value, column.getType(), column.getTypeName()));
         } else {
                whereClause.append(value);
         }
     }
-    public void init(TableRow row, TableAdapter adapter) {
+    /**
+        * @param entity
+        * @param columnName
+        * @return
+        * @throws NotConnectedException
+        * @throws SQLException
+        */
+       protected Column getColumn(Entity entity, String columnName)  {
+               try {
+                       return entity == null ? null : entity.getColumn(columnName);
+               } catch (NotConnectedException e) {
+                       return null;
+               } catch (SQLException e) {
+                       return null;
+               }
+       }
+       public void init(TableRow row, TableAdapter adapter) {
        this.row = row;
         this.adapter = adapter;
     }