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("oricon.txt","UTF-8");
data=sub.data;
datanumber=sub.datanumber;
for(s=2;s<datanumber+1;s++){
catchword sub2=new catchword();
subdata[s-1][1]=sub2.makedata(data[s],"WYEAR");
subdata[s-1][2]=sub2.makedata(data[s],"WMONTH");
subdata[s-1][3]=sub2.makedata(data[s],"WWEEK");
subdata[s-1][4]=sub2.makedata(data[s],"RANK");
subdata[s-1][5]=sub2.makedata(data[s],"ARTIST");
subdata[s-1][6]=sub2.makedata(data[s],"TITLE");
}
datanumber=datanumber-1;
creditnumber=6;
datanumber=100;
type[1]="INT";
type[2]="INT";
type[3]="INT";
type[4]="INT";
type[5]="VARCHAR";
type[6]="VARCHAR";
strlong[6]=20;
strlong[5]=20;
credit[1]="wyear";
credit[2]="wmonth";
credit[3]="wweek";
credit[4]="rank";
credit[5]="artist";
credit[6]="title";
tab="or7";
datanumber=10000;
str=makecard();
article[0]=maketable(tab,str);
for(s=1;s<datanumber+1;s++){
str=makemessage(s);
article[s]=makeinsert(tab,str);
}
writefile("or7.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("入出力エラーです。"); }
}
}