* @throws Exception if something goes wrong
*/
private void writeStructure() throws Exception{
StringBuffer query = new StringBuffer();
Instances structure = getInstances();
query.append("CREATE TABLE ");
if(m_tabName || m_tableName.equals(""))
m_tableName = m_DataBaseConnection.maskKeyword(structure.relationName());
if(m_DataBaseConnection.getUpperCase()){
m_tableName = m_tableName.toUpperCase();
m_createInt = m_createInt.toUpperCase();
m_createDouble = m_createDouble.toUpperCase();
m_createText = m_createText.toUpperCase();
m_createDate = m_createDate.toUpperCase();
}
m_tableName = m_tableName.replaceAll("[^\\w]","_");
m_tableName = m_DataBaseConnection.maskKeyword(m_tableName);
query.append(m_tableName);
if(structure.numAttributes() == 0)
throw new Exception("Instances have no attribute.");
query.append(" ( ");
if(m_id){
if(m_DataBaseConnection.getUpperCase())
m_idColumn = m_idColumn.toUpperCase();
query.append(m_DataBaseConnection.maskKeyword(m_idColumn));
query.append(" ");
query.append(m_createInt);
query.append(" PRIMARY KEY,");
}
for(int i = 0;i < structure.numAttributes(); i++){
Attribute att = structure.attribute(i);
String attName = att.name();
attName = attName.replaceAll("[^\\w]","_");
attName = m_DataBaseConnection.maskKeyword(attName);
if(m_DataBaseConnection.getUpperCase())
query.append(attName.toUpperCase());
else
query.append(attName);
if(att.isDate())
query.append(" " + m_createDate);
else{
if(att.isNumeric())
query.append(" "+m_createDouble);
else
query.append(" "+m_createText);
}
if(i != structure.numAttributes()-1)
query.append(", ");
}
query.append(" )");
//System.out.println(query.toString());
m_DataBaseConnection.update(query.toString());