package net.sourceforge.phpdt.sql.wizards;
+import java.text.MessageFormat;
+
+import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
-import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
+import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
import net.sourceforge.phpdt.sql.sql.TableRow;
+import net.sourceforge.phpdt.sql.view.PHPSourceConsole;
import net.sourceforge.phpdt.sql.view.tableview.TableAdapter;
public class PHPInsertRowPage extends WizardPage implements SQLPage {
String[] columnNames;
Text[] values;
Label query;
+ private IPreferenceStore fStore;
+
public PHPInsertRowPage(String pageName) {
super(pageName);
}
if (DEBUG) {
System.out.println("page create control");
}
+ fStore = PHPEclipseSQLPlugin.getDefault().getPreferenceStore();
Composite container = new Composite(parent, SWT.NULL);
GridLayout layout = new GridLayout();
container.setLayout(layout);
System.out.println("Data is null");
}
}
+
columnNames = row.getColumnNames();
String[] data = row.getTableData();
if (DEBUG) {
}
public void updateQuery() {
if (DEBUG) {
- System.out.println("Updating query");
+ System.out.println("Updating insert query");
}
+ StringBuffer fieldClause = new StringBuffer();
+
StringBuffer valuesClause = new StringBuffer();
+ String text;
+ boolean first = false;
for (int i = 0; i < columnNames.length; i++) {
- valuesClause.append(values[i].getText());
- valuesClause.append(", ");
- }
- if (valuesClause.length() > 1) {
- valuesClause.deleteCharAt(valuesClause.length() - 1);
- valuesClause.deleteCharAt(valuesClause.length() - 1);
+ text = values[i].getText();
+ if (!text.equals("")) {
+ if (first) {
+ valuesClause.append(", ");
+ fieldClause.append(", ");
+ }
+ valuesClause.append("'" + values[i].getText() + "'");
+ fieldClause.append(columnNames[i]);
+ first = true;
+ }
}
- String query = "INSERT INTO " + row.getTable();
- query += " VALUES (" + valuesClause.toString();
- query += " )";
+ // if (valuesClause.length() > 1) {
+ // valuesClause.deleteCharAt(valuesClause.length() - 1);
+ // valuesClause.deleteCharAt(valuesClause.length() - 1);
+ // }
+ String[] arguments = { row.getTable(), fieldClause.toString(), valuesClause.toString()};
+ MessageFormat form = new MessageFormat(fStore.getString("phpeclipse.sql.insert.template"));
+
+ String query = form.format(arguments);
+
+ // String query = "$results = mysql_query(\"INSERT INTO " + row.getTable() + " (";
+ // query += fieldClause.toString() + ") ";
+ // query += " VALUES (" + valuesClause.toString();
+ // query += ")\");";
this.query.setText(query);
}
public boolean performFinish() {
- MultiSQLServer server = MultiSQLServer.getInstance();
- server.execute(query.getText());
+ PHPSourceConsole console = PHPSourceConsole.getInstance();
+ console.clear();
+ console.print(query.getText());
return true;
}
}
\ No newline at end of file