public class tables {
final static String[][] tables = {
/* { "0", "SequenceReset", "Dummy", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "" },*/
{"0",""},
{ "1" },
{ "2" },
{ "3" },
{ "4" },
{ "5" },
{ "6" },
{ "7" },
{ "8" },
{ "9" },
{ "10", "table1", "Dummy",
"MsgSize", "Uint16", "2",
"MsgType", "Uint16", "2",
"field1", "String", "4",
"field2", "String", "25",
"field3", "String","3",
"field4", "Uint32", "4" },
{ "12" },
{ "13", "table3", "10,2",
"field1", "Uint16", "2",
"field2", "Uint16", "2",
"field3", "Uint32", "4",
"field4", "Uint16", "2",
"field5", "Uint16", "2" },
{ "14", "table4", "Dummy",
"field1", "Uint16", "2",
"field2", "Uint16", "2",
"field3", "String", "3",
"field4", "String", "1",
"field5", "Uint16", "2",
"field6", "String", "2",
"field7", "Uint32", "4" },
{ "15" },
{ "16" },
{ "17" },
{ "18" },
{ "19" },
{ "20", "table5", "Dummy",
"MsgSize", "Uint16", "2",
"MsgType", "Uint16", "2",
"field1", "String", "4",
"field2", "Uint8", "1",
"field3", "Uint8", "1",
"field4", "Uint8", "1",
"field5", "String", "1",
"field6", "String", "4",
"field7", "Uint64", "8",
"field8", "Uint64", "8" },
{ "99" },
{ "100", "SequenceReset", "Dummy",
"MsgSize", "Uint16", "2",
"MsgType", "Uint16", "2",
"NewSeqNo", "Uint32", "4" },
};
}
// Remark unsign the drop table for drop table
//00300 define the length
import java.sql.*;
public class createtable {
static String v_create;
static char v_delimiter;
static String v_type;
static String v_unsigned;
static String v_length;
static tables stru = new tables();
static jdbcmysql MySql = new jdbcmysql();
createtable() {}
public static void main(String[] args) {
// System.out.println(stru.tables.length);
int _1=0; int _10=0;
for (int i2 = 0; i2 < stru.tables.length; i2++)
// for (int i2= 22; i2 <23; i2++)
{
if (stru.tables[i2].length > 6) {
System.out.println(stru.tables[i2][1]);
v_create = "Create table " + stru.tables[i2][1] + " (";
v_delimiter = ' ';
for (int j = 9; j < stru.tables[i2].length; j++) {
if (j % 3 == 0) {
v_create = v_create + v_delimiter;
}
if (j % 3 == 2) {
try{
String _20=stru.tables[i2][j];
_10=Integer.valueOf(_20);
String _2=stru.tables[i2][j+3];
_1=Integer.valueOf(_2);
}
catch(NumberFormatException e){_1=0;_10=0;}
catch(ArrayIndexOutOfBoundsException e) {_1=0;_10=0;}
if (_10<255){
v_create = v_create + '(';}
}
if (j % 3 == 2) {
//00300 define the length
String t=stru.tables[i2][j-1];
if (t=="Uint8" || t=="Int8" ){v_length="4";}
else if (t=="Uint16" || t=="Int16" ){v_length="6";}
else if (t=="Uint32" || t=="Int32" ){v_length="12";}
else if (t=="Uint64" || t=="Int64" ){v_length="22";}
else {v_length=stru.tables[i2][j];}
//System.out.println(_10);
if (_10<255){
v_create = v_create +" "+v_length;
}
// v_create = v_create + stru.tables[i2][j];
} else {
/*******************************
* handle character type
*********************************/
if (j % 3 == 1) {
v_unsigned = "";
v_type = stru.tables[i2][j];
if (v_type == "String") {
v_type = "char";
}
if (v_type == "String/Binary") {
v_type = "varchar";
}
if (v_type == "Uint64" || v_type == "Uint32"
|| v_type == "Uint16" || v_type == "Uint8") {
v_type = "decimal";
v_unsigned = "unsigned";
}
if (v_type == "Int16" || v_type == "Int32"
|| v_type == "Int64") {
v_type = "decimal";
}
if (_1>255){v_type="longtext";}
v_create = v_create + v_type + " ";
} else {
v_create = v_create + stru.tables[i2][j] + " ";
}
}
if (j % 3 == 2) {
if (_10<255){
v_create = v_create + ')' + v_unsigned;}
}
v_delimiter = ',';
}
// v_create = v_create + ") engine=innodb charset=utf8 ;";
// v_create = v_create + ") engine=myisam charset=utf8 ;";
//String full = v_create;
String sub = "longtext";
boolean hadText = v_create.toUpperCase().indexOf(sub.toUpperCase()) != -1;
String TableType ="memory" ;
if (hadText) {TableType ="innodb" ;} // text cannot memory type
v_create = v_create + " , MsgSeqNo decimal(10,0) unsigned DEFAULT NULL , UniqueNum decimal(24,0) unsigned DEFAULT NULL ) engine= "+TableType+" charset=utf8 ;";
if(1==0){System.out.println(v_create);}
MySql.createdbSQL = "drop table if exists "+stru.tables[i2][1]+";";
try{MySql.RunMySql();}catch (SQLException e){e.printStackTrace();}
MySql.createdbSQL = v_create;
try{MySql.RunMySql();}catch (SQLException e){e.printStackTrace();}
}
} // endfor
MySql.createdbSQL = "CREATE DEFINER=`root`@`localhost` trigger IndexDataInsertAfter after insert on IndexData for each row Begin insert ignore into price (indexcode) value (new.indexcode) ; update price set indexstatus=new.indexstatus , indextime=new.indextime, indexvalue=new.indexvalue, netchgprevday=new.netchgprevday, highvalue=new.highvalue, lowvalue=new.lowvalue, easvalue=new.easvalue, indexturnover=new.indexturnover, openingvalue=new.openingvalue, closingvalue=new.closingvalue, previoussesclose=new.previoussesclose, indexvolume=new.indexvolume, netchgprevdaypct=new.netchgprevdaypct, exception=new.exception where indexcode=new.indexcode ; end";
try{MySql.RunMySql();}catch (SQLException e){e.printStackTrace();}
MySql.createdbSQL = "CREATE DEFINER=`root`@`localhost` trigger NominalPriceInsertAfter after insert on NominalPrice for each row Begin insert ignore into nprice (Securitycode) value (new.Securitycode) ; update nprice set nominalPrice=new.nominalPrice where securityCode=new.securityCode ; end";
try{MySql.RunMySql();}catch (SQLException e){e.printStackTrace();}
沒有留言:
張貼留言