io.odysz.transact.sql.parts.insert.InsertValues Maven / Gradle / Ivy
package io.odysz.transact.sql.parts.insert;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import io.odysz.common.LangExt;
import io.odysz.common.Utils;
import io.odysz.semantics.ISemantext;
import io.odysz.semantics.meta.TableMeta;
import io.odysz.transact.sql.parts.AbsPart;
import io.odysz.transact.sql.parts.antlr.ExprsVisitor;
import io.odysz.transact.sql.parts.condition.ExprPart;
import io.odysz.transact.x.TransException;
public class InsertValues extends AbsPart {
protected List> values;
protected Map cols;
protected String tablName;
public InsertValues(String tabl, Map cols, List> values) {
this.tablName = tabl;
this.cols = cols;
this.values = values;
}
@Override
public String sql(ISemantext sctx) throws TransException {
if (values == null)
return "";
return values.stream().map(row -> getValue(sctx, row, cols).sql(sctx))
.collect(Collectors.joining(", ", "values ", ""));
}
/**Get row's value list used in sql values.
* @param sctx
* @param row
* @param colIdx
* @return value list
*/
protected ValueList getValue(ISemantext sctx, ArrayList