--- FM2SQL/src/Convert.java 2005/04/19 10:49:05 1.10
+++ FM2SQL/src/Convert.java 2005/05/02 12:45:36 1.13
@@ -29,8 +29,10 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;
+import java.text.DateFormat;
import java.text.ParseException;
import java.util.ArrayList;
+import java.util.Date;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
@@ -47,6 +49,8 @@ import com.exploringxml.xml.Xparse;
class Convert
{
+ private static final String _TEMP = "_temp";
+
/**
* Helper class for index creation
*
@@ -119,7 +123,7 @@ class Convert
final static int numIntervalls = 4;
- static boolean debug = !false;
+ static boolean debug = false;
static boolean isGUI = true;
@@ -133,12 +137,16 @@ class Convert
static Vector postSQLCommands = new Vector();
- static final String versionID = new String("FM2SQL Version 0.9.1b\n");
+ static final String versionID = new String("FM2SQL Version 0.9.6b\n");
private static boolean noError = false;
public static void main(String args[]) throws IOException
{
+ // DateFormat d = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT,
+ // Locale.GERMANY);
+ // System.out.println(convertText("rogoistSuper" + "_" + d.format(new Date()).replace(':', '_')));
+
/*
* try { //byte[] b = "�".getBytes("UTF-8"); //
* System.out.println("QueryString " +b[0]+" "+b[1]+(new
@@ -266,7 +274,7 @@ class Convert
// if vectors[1].get(i) != null)
if (!layout.equals(""))
{
-
+
query = addLayoutToQuery(names, query, tbIndex, layout);
}
@@ -531,7 +539,7 @@ class Convert
destTableName = prop.destTableName;
if (mode == Convert.DataBase.CONVERT_TEMP_MODE)
{
- destTableName += "_temp";
+ destTableName += _TEMP;
}
fieldNames = prop.fieldNames;
if (mode == Convert.DataBase.CONVERT_MODE || mode == Convert.DataBase.CONVERT_TEMP_MODE)
@@ -712,6 +720,25 @@ class Convert
if (isGUI)
resetGUI(dialog);
noError = true;
+ if (mode == Convert.DataBase.CONVERT_TEMP_MODE)
+ {
+ String originalName = destTableName.split(_TEMP)[0];
+ // TODO
+ if (beanDest.getTableNames().contains(originalName))
+ {
+ DateFormat d = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM);
+ d.setTimeZone(java.util.TimeZone.getTimeZone("CET"));
+
+ String date = d.format(new Date());
+ date = date.replace(':', '_');
+ String newName = addQuotes(beanDest, convertText(originalName + "_" + date));
+ // rename table to newName
+ renameTable(beanDest, addQuotes(beanDest, originalName), newName);
+ }
+ // rename Table_temp to originalName
+ renameTable(beanDest, addQuotes(beanDest, destTableName), addQuotes(beanDest,
+ originalName));
+ }
}
} catch (Exception e)
{
@@ -728,6 +755,8 @@ class Convert
}
} catch (Error e)
{
+ noError = false;
+
System.out.println(e);
e.printStackTrace();
}
@@ -735,6 +764,17 @@ class Convert
}
/**
+ *
+ * @param beanDest2
+ * @param originalName
+ * @return
+ */
+ private static String addQuotes(DBBean bean, String originalName)
+ {
+ return bean.getQC() + originalName + bean.getQC();
+ }
+
+ /**
* @param names
* @param dialog
* @param tbIndex
@@ -1106,6 +1146,21 @@ class Convert
}
}
+ /**
+ *
+ * @param database
+ * @param db
+ * @throws Exception
+ * @throws SQLException
+ */
+ private static void renameTable(DBBean database, String sourceTable, String destTable)
+ throws SQLException, Exception
+ {
+ String command = "alter table " + sourceTable + " rename " + " to " + destTable;
+ SQLCommand sqlCommand = new SQLCommand(database, command);
+ sqlCommand.executeCommand();
+ }
+
public static Vector getXMLConfig(StringBuffer sb)
{
@@ -1545,7 +1600,9 @@ class Convert
buffr.write(" " + bean.passwd + "\n");
buffr.write(" " + delimiter + "\n");
String modeString = "";
- if (mode == CONVERT_MODE)
+ if (mode == CONVERT_TEMP_MODE)
+ modeString = "convert_temp";
+ else if (mode == CONVERT_MODE)
modeString = "convert";
else if (mode == APPEND_MODE)
modeString = "append";