package com.database_util;
|
|
import java.sql.ResultSet;
|
import java.sql.SQLException;
|
|
import com.sql.MysqlConnPool;
|
import com.sql.Sql_Mysql;
|
|
public class DB_Ld9_Testdata {
|
public static void init(MysqlConnPool pool, boolean recreate) {
|
createDB_LD9_TESTDATA(pool);
|
|
createLd9testdata_Inf_Table(pool, recreate);
|
|
repireLD9TestDataTable(pool);
|
}
|
|
/**
|
* ´´½¨ db_ld9_testdata Êý¾Ý¿â
|
* @param pool
|
*/
|
public static void createDB_LD9_TESTDATA(MysqlConnPool pool) {
|
Sql_Mysql sql = new Sql_Mysql(pool.getConn());
|
try {
|
sql.sqlMysqlExecute("CREATE DATABASE IF NOT EXISTS " + Sql_Mysql.DB_LD9_TESTDATA);
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} finally {
|
sql.close_con();
|
}
|
}
|
|
|
/**
|
* ´´½¨ tb_ld9testdata_inf ±í
|
* @param pool
|
* @param recreate
|
*/
|
public static void createLd9testdata_Inf_Table(MysqlConnPool pool, boolean recreate) {
|
String sql_str01 = " DROP TABLE IF EXISTS "+Sql_Mysql.Ld9testdata_Inf_Table;
|
String sql_str02 = " CREATE TABLE IF NOT EXISTS " + Sql_Mysql.Ld9testdata_Inf_Table + " (" +
|
" num bigint(20) NOT NULL AUTO_INCREMENT," +
|
" BattGroupId int(11) NOT NULL DEFAULT '0'," +
|
" test_record_count int(11) NOT NULL DEFAULT '0'," +
|
" test_record_count_ex int(11) NOT NULL DEFAULT '0'," +
|
" test_type int(11) NOT NULL DEFAULT '0'," +
|
" record_time_interval int(11) NOT NULL DEFAULT '0'," +
|
" record_num int(11) NOT NULL DEFAULT '0'," +
|
" test_starttime datetime NOT NULL DEFAULT '1982-01-01 00:00:00'," +
|
" test_starttime_ex datetime NOT NULL DEFAULT '1982-01-01 00:00:00'," +
|
" record_time datetime NOT NULL DEFAULT '1982-01-01 00:00:00'," +
|
" test_timelong int(11) NOT NULL DEFAULT '0'," +
|
" test_stoptype int(11) NOT NULL DEFAULT '0'," +
|
" test_stopreason int(11) NOT NULL DEFAULT '0'," +
|
" group_vol float NOT NULL DEFAULT '0'," +
|
" test_curr float NOT NULL DEFAULT '0'," +
|
" test_cap float NOT NULL DEFAULT '0'," +
|
" mon_num int(11) NOT NULL DEFAULT '0'," +
|
" mon_vol float NOT NULL DEFAULT '0'," +
|
" max_monnum int(11) NOT NULL DEFAULT '1'," +
|
" max_monvol float NOT NULL DEFAULT '12.5'," +
|
" min_monnum int(11) NOT NULL DEFAULT '1'," +
|
" min_monvol float NOT NULL DEFAULT '12'," +
|
" PRIMARY KEY (num)," +
|
" KEY index_battgroup_id (BattGroupId)," +
|
" KEY index_test_record_count (test_record_count)," +
|
" KEY index_test_starttime (test_starttime)" +
|
") ENGINE=InnoDB DEFAULT CHARSET=utf8;";
|
Sql_Mysql sql = new Sql_Mysql(pool.getConn());
|
try {
|
if(true == recreate) {
|
sql.sqlMysqlExecute(sql_str01);
|
}
|
sql.sqlMysqlExecute(sql_str02);
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} finally {
|
sql.close_con();
|
}
|
}
|
|
public static void repireLD9TestDataTable(MysqlConnPool pool) {
|
String sql_str_sel = " SELECT table_name from information_schema.columns " +
|
" where table_schema = 'db_ld9_testdata' " +
|
" AND (table_name like 'tb_ld9testdata_%' AND table_name != 'tb_ld9testdata_inf') " +
|
" group by table_name;";
|
ResultSet res = null;
|
ResultSet rs = null;
|
Sql_Mysql sql = new Sql_Mysql(pool.getConn());
|
res = sql.sqlMysqlQuery(sql_str_sel);
|
try {
|
while(res.next()) {
|
String tname = res.getString("table_name");
|
//Ìí¼Ómon_cap-ʵ¼ÊÈÝÁ¿
|
rs = sql.sqlMysqlQuery("SELECT * FROM information_schema.columns"
|
+ " WHERE table_schema='db_ld9_testdata'"
|
+ " AND table_name='"+tname+"'"
|
+ " AND column_name='mon_cap'");
|
if(false == rs.next()) {
|
sql.sqlMysqlExecute("ALTER TABLE db_ld9_testdata." + tname
|
+ " ADD COLUMN `mon_cap` float NOT NULL DEFAULT '0' COMMENT 'ʵ¼ÊÈÝÁ¿';");
|
}
|
|
rs = null;
|
//Ìí¼Ómon_rest_cap-Ê£ÓàÈÝÁ¿
|
rs = sql.sqlMysqlQuery("SELECT * FROM information_schema.columns"
|
+ " WHERE table_schema='db_ld9_testdata'"
|
+ " AND table_name='"+tname+"'"
|
+ " AND column_name='mon_rest_cap'");
|
if(false == rs.next()) {
|
sql.sqlMysqlExecute("ALTER TABLE db_ld9_testdata." + tname
|
+ " ADD COLUMN `mon_rest_cap` float NOT NULL DEFAULT '0' COMMENT 'Ê£ÓàÈÝÁ¿';");
|
}
|
}
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} finally {
|
try {
|
if(null != rs) {
|
rs.close();
|
}
|
} catch (SQLException e) {
|
e.printStackTrace();
|
}
|
try {
|
if(null != res) {
|
res.close();
|
}
|
} catch (SQLException e) {
|
e.printStackTrace();
|
}
|
sql.close_con();
|
}
|
|
|
}
|
}
|