package sqlconnect;

import java.util.ArrayList;
import java.util.Scanner;
import java.io.File;

public class Readclass {
    public static void init(){
        try{
            Scanner fin=new Scanner(new File("src/sqlconnect/variable"));
            while(fin.hasNext()){
                String className=fin.next();
                int count=fin.nextInt();
                Item item=new Item();
                item.size=count;
                for(int i=0;i<count;i++){
                    String name=fin.next();
                    String type=fin.next();
                    item.key.add(name);
                    item.type.add(type);
                }
                Database.Maps.put(className,item);
            }
        }catch (Exception e){
            System.err.println("配置文件错误");
            e.printStackTrace();
        }

    }
    public static ArrayList<String> getWord(String table,ArrayList<String> value){
        Item item=Database.Maps.get(table);
        ArrayList<String> arrayList=new ArrayList<String>();
        for(int i=0;i<item.size;i++){
            String type=item.type.get(i);
            String val=value.get(i);
            if(val.equals("NULL")) {
                arrayList.add("NULL");
            }else if(type.equals("NUM")){
                arrayList.add(SQLfilter.filter(val));
            }else if(type.equals("STRING")){
                arrayList.add("'"+SQLfilter.filter(val)+"'");
            }
        }
        return arrayList;
    }
}
