<commit_before>package org.opencloudb.util;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.List;

import org.opencloudb.net.mysql.FieldPacket;
import org.opencloudb.net.mysql.RowDataPacket;

/**
 * 
 * @author struct
 * 
 */
public class ResultSetUtil {

	public static int toFlag(ResultSetMetaData metaData, int column)
			throws SQLException {

		int flags = 0;
		if (metaData.isNullable(column) == 1) {
			flags |= 0001;
		}

		if (metaData.isSigned(column)) {
			flags |= 0020;
		}

		if (metaData.isAutoIncrement(column)) {
			flags |= 0200;
		}

		return flags;
	}

	public static void resultSetToPacket(String charset, Connection source,
			List<FieldPacket> fieldPks, ResultSet rs,
			List<RowDataPacket> rowsPkg) throws SQLException {
		ResultSetMetaData metaData = rs.getMetaData();
		int colunmCount = metaData.getColumnCount();
		if (colunmCount > 0) {
			for (int i = 0; i < colunmCount; i++) {
				int j = i + 1;
				FieldPacket fieldPacket = new FieldPacket();
				fieldPacket.orgName = StringUtil.encode(
						metaData.getColumnLabel(j), charset);
				fieldPacket.name = StringUtil.encode(metaData.getColumnName(j),
						charset);
				fieldPacket.orgTable = StringUtil.encode(
						metaData.getTableName(j), charset);
				fieldPacket.table = StringUtil.encode(metaData.getTableName(j),
						charset);
				fieldPacket.db = StringUtil.encode(metaData.getSchemaName(j),
						charset);
				fieldPacket.length = metaData.getColumnDisplaySize(j);
				fieldPacket.flags = toFlag(metaData, j);
				fieldPacket.decimals = (byte) metaData.getScale(j);
				int javaType = MysqlDefs.javaTypeDetect(
						metaData.getColumnType(j), fieldPacket.decimals);
				fieldPacket.type = (byte) (MysqlDefs.javaTypeMysql(javaType) & 0xff);
				fieldPks.add(fieldPacket);

			}

		}

		while (rs.next()) {
			RowDataPacket row = new RowDataPacket(fieldPks.size());
			for (int i = 0; i < colunmCount; i++) {
				int j = i + 1;
				// BindValue bindValue = new BindValue();
				// bindValue.bufferType = fieldPackets[i].type;
				// bindValue.bindLength = fieldPackets[i].length;
				// bindValue.scale = fieldPackets[i].decimals;
				// bindValue.charset = fieldPackets[i].charsetName;
				// PacketUtil.resultToBindValue(bindValue, j, rs,
				// fieldPackets[i]);
				row.add(StringUtil.encode(rs.getString(j), charset));

			}
			rowsPkg.add(row);
		}
	}

	public static RowDataPacket parseRowData(byte[] row,
			List<byte[]> fieldValues) {<commit_msg>JDBC方式， 字段有别名，报错 java.lang.IllegalArgumentException: group by<commit_after>package org.opencloudb.util;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.List;

import org.opencloudb.net.mysql.FieldPacket;
import org.opencloudb.net.mysql.RowDataPacket;

/**
 * 
 * @author struct
 * 
 */
public class ResultSetUtil {

	public static int toFlag(ResultSetMetaData metaData, int column)
			throws SQLException {

		int flags = 0;
		if (metaData.isNullable(column) == 1) {
			flags |= 0001;
		}

		if (metaData.isSigned(column)) {
			flags |= 0020;
		}

		if (metaData.isAutoIncrement(column)) {
			flags |= 0200;
		}

		return flags;
	}

	public static void resultSetToPacket(String charset, Connection source,
			List<FieldPacket> fieldPks, ResultSet rs,
			List<RowDataPacket> rowsPkg) throws SQLException {
		ResultSetMetaData metaData = rs.getMetaData();
		int colunmCount = metaData.getColumnCount();
		if (colunmCount > 0) {
			//String values="";
			for (int i = 0; i < colunmCount; i++) {
				int j = i + 1;
				FieldPacket fieldPacket = new FieldPacket();
				fieldPacket.orgName = StringUtil.encode(metaData.getColumnName(j),charset);
				fieldPacket.name = StringUtil.encode(metaData.getColumnLabel(j), charset);
				fieldPacket.orgTable = StringUtil.encode(
						metaData.getTableName(j), charset);
				fieldPacket.table = StringUtil.encode(metaData.getTableName(j),
						charset);
				fieldPacket.db = StringUtil.encode(metaData.getSchemaName(j),
						charset);
				fieldPacket.length = metaData.getColumnDisplaySize(j);
				fieldPacket.flags = toFlag(metaData, j);
				fieldPacket.decimals = (byte) metaData.getScale(j);
				int javaType = MysqlDefs.javaTypeDetect(
						metaData.getColumnType(j), fieldPacket.decimals);
				fieldPacket.type = (byte) (MysqlDefs.javaTypeMysql(javaType) & 0xff);
				fieldPks.add(fieldPacket);
				//values+=metaData.getColumnLabel(j)+"|"+metaData.getColumnName(j)+"  ";

			}
			// System.out.println(values);
		}

		while (rs.next()) {
			RowDataPacket row = new RowDataPacket(fieldPks.size());
			for (int i = 0; i < colunmCount; i++) {
				int j = i + 1;
				// BindValue bindValue = new BindValue();
				// bindValue.bufferType = fieldPackets[i].type;
				// bindValue.bindLength = fieldPackets[i].length;
				// bindValue.scale = fieldPackets[i].decimals;
				// bindValue.charset = fieldPackets[i].charsetName;
				// PacketUtil.resultToBindValue(bindValue, j, rs,
				// fieldPackets[i]);
				row.add(StringUtil.encode(rs.getString(j), charset));

			}
			rowsPkg.add(row);
		}
	}

	public static RowDataPacket parseRowData(byte[] row,
			List<byte[]> fieldValues) {
{'fraction_non_alphanumeric': 0.1300704627689964, 'fraction_numerical': 0.0076175966482574745, 'mean_word_length': 3.8855813953488374, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2136811', 'n_tokens_mistral': 2105, 'n_tokens_neox': 1755, 'n_words': 336}