package makex;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import tool.*;
public class pro {
int s,sx,datanumber,creditnumber;
String data=new String[50000];
String subdata=new String[50000][10];
String artist=new String[50000];
String type=new String[50];
String credit=new String[50];
String article=new String[50000];
int strlong=new int[50];
int year=new int[50000];
int month=new int[50000];
int point=new int[50000];
String strx,tab,str;
public static void main(String args) {
pro test=new pro();
}
pro(){
readfile sub=new readfile();
sub.makedata("wiki.txt","UTF-8");
data=sub.data;
datanumber=sub.datanumber;
for(s=2;s<datanumber+1;s++){
catchword sub2=new catchword();
artist[s-1]=sub2.makedata(data[s],"ARTIST");
strx=sub2.makedata(data[s],"POINT");
point[s-1]=Integer.parseInt(strx);
strx=sub2.makedata(data[s],"WYEAR");
year[s-1]=Integer.parseInt(strx);
strx=sub2.makedata(data[s],"WMONTH");
month[s-1]=Integer.parseInt(strx);
}
datanumber=datanumber-1;
creditnumber=4;
type[1]="VARCHAR";
type[2]="INT";
type[3]="INT";
type[4]="INT";
strlong[1]=20;
credit[1]="name";
credit[2]="wyear";
credit[3]="wmonth";
credit[4]="point";
tab="wiki2";
for(s=1;s<datanumber+1;s++){
subdata[s][1]=artist[s];
subdata[s][2]=""+year[s];
subdata[s][3]=""+month[s];
subdata[s][4]=""+point[s];
}
str=makecard();
article[0]=maketable(tab,str);
for(s=1;s<datanumber+1;s++){
str=makemessage(s);
article[s]=makeinsert(tab,str);
}
writefile("wiki.sql");
}
String makecard(){
int sx;
String str;
str="";
for(sx=1;sx<creditnumber;sx++){
if(type[sx].indexOf("VARCHAR")>-1)str=str+credit[sx]+" "+type[sx]+"("+strlong[sx]+")"+",";
if(type[sx].indexOf("INT")>-1)str=str+credit[sx]+" "+type[sx]+",";
if(type[sx].indexOf("DOUBLE")>-1)str=str+credit[sx]+" "+type[sx]+",";
}
sx=creditnumber;
if(type[sx].indexOf("VARCHAR")>-1)str=str+credit[sx]+" "+type[sx]+"("+strlong[sx]+")";
if(type[sx].indexOf("INT")>-1)str=str+credit[sx]+" "+type[sx];
if(type[sx].indexOf("DOUBLE")>-1)str=str+credit[sx]+" "+type[sx];
return str;
}
String makemessage(int s){
int sx;
String str;
str="";
for(sx=1;sx<creditnumber;sx++){
if(type[sx].indexOf("VARCHAR")>-1)str=str+change(subdata[s][sx])+",";
if(type[sx].indexOf("INT")>-1)str=str+subdata[s][sx]+",";
if(type[sx].indexOf("DOUBLE")>-1)str=str+subdata[s][sx]+",";
}
sx=creditnumber;
if(type[sx].indexOf("VARCHAR")>-1)str=str+change(subdata[s][sx]);
if(type[sx].indexOf("INT")>-1)str=str+subdata[s][sx];
if(type[sx].indexOf("DOUBLE")>-1)str=str+subdata[s][sx];
return str;
}
String maketable(String tab,String message){
String str;
str="create table "+tab+"("+message+");";
return str;
}
String makeinsert(String tab,String message){
String str;
str="insert into "+tab+" values("+message+");";
return str;
}
String change(String str){
String strx;
strx="'"+str+"'";
return strx;
}
void writefile(String file){
try{
PrintWriter pw = new PrintWriter (new BufferedWriter(new FileWriter(file)));
for(s=0;s<datanumber+1;s++){
pw.println(article[s]);
}
System.out.println("繝輔ぃ繧、繝ォ縺ォ譖ク縺阪%縺ソ縺セ縺励◆縲・);
pw.close();
} catch(IOException ep){ System.out.println("蜈・蜃コ蜉帙お繝ゥ繝シ縺ァ縺吶・); }
}
}