/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package customer;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import database.model_postgre;
/**
 *
 * @author Administrator
 */
@WebService()
public class serveCustomer {

/**
     * Web service operation
     */
    @WebMethod(operationName = "listData")
    public java.lang.String[][] listData(String table,int limit) {
        model_postgre model=new model_postgre();
        model.q("SELECT * FROM "+table+" LIMIT "+limit);
        return model.data;
    }
    
    @WebMethod(operationName = "listCols")
    public java.lang.String[][] listCols(String table){
        model_postgre model=new model_postgre();
        model.q("select column_name from information_schema.columns WHERE table_name='"+table+"'");
        return model.data;
    }
    
    @WebMethod(operationName = "updateRow")
    public String updateRow(int ColIndex, String ColValue, String[] RowValue, String table){
        model_postgre model=new model_postgre();
        String[][] arrCols=this.listCols(table);
        String strSQL="UPDATE "+table+" SET ";
        String strWhere="";
        int i=0;
        
        for(String[] row:arrCols)
        for(String col:row){
            if (i==ColIndex) strSQL+=col+"='"+ColValue+"' WHERE ";
            else {
                strWhere+=col+"='"+RowValue[i]+"' AND ";
            }
            i++;
        }
        
        model.q(strSQL+strWhere+"1=1");
        
        //if (model.error==null) 
            return strSQL+strWhere+"1=1";
       // else return model.error;
    }

}

