<commit_before>﻿//MIT 2015, brezza27, EngineKit and contributors
using System.Text;

namespace SharpConnect.MySql.Utils
{
    public class SimpleInsert : IHasParameters
    {
        MySqlCommand sqlCommand;
        bool isPrepared;
        public SimpleInsert(string targetTableName)
        {
            TargetTableName = targetTableName;
            Pars = new CommandParams();
        }
        public CommandParams Pars
        {
            get;
            private set;
        }
        public string TargetTableName { get; private set; }
        public MySqlConnection Connection { get; set; }
        public void ExecuteNonQuery(MySqlConnection conn)
        {
            Connection = conn;
            ExecuteNonQuery();
        }
        public void ExecuteNonQuery()
        {
            //create insert sql
            //then exec
            if (isPrepared)
            {

                sqlCommand.ExecuteNonQuery();
            }
            else
            {
                StringBuilder sql = CreateSqlText();
                sqlCommand = new MySqlCommand(sql.ToString(), Pars, Connection);
                sqlCommand.ExecuteNonQuery();
            }
        }
        public void Prepare()
        {
            if (isPrepared)
            {
                throw new System.NotSupportedException("double prepare");
            }
            isPrepared = true;
            StringBuilder sql = CreateSqlText();
            sqlCommand = new MySqlCommand(sql.ToString(), Pars, Connection);
            sqlCommand.Prepare();
        }
        public void Prepare(MySqlConnection conn)
        {
            if (isPrepared)
            {
                throw new System.NotSupportedException("double prepare");
            }
            Connection = conn;
            Prepare();
        }
        StringBuilder CreateSqlText()
        {
            CommandParams pars = Pars;
            string[] valueKeys = pars.GetAttachedValueKeys();
            var stBuilder = new StringBuilder();
            stBuilder.Append("insert into ");
            stBuilder.Append(TargetTableName);
            stBuilder.Append('(');

            int j = valueKeys.Length;
            for (int i = 0; i < j; ++i)
            {
                string k = valueKeys[i];
                //sub string
                if (k[0] != '?')
                {
                    throw new System.NotSupportedException();
                }
                stBuilder.Append(k.Substring(1)); //remove ?

                if (i < j - 1)
                {
                    stBuilder.Append(',');
                }

            }
            stBuilder.Append(")  values(");
            for (int i = 0; i < j; ++i)
            {
                stBuilder.Append(valueKeys[i]);
                if (i < j - 1)
                {
                    stBuilder.Append(',');
                }
            }
            stBuilder.Append(")");
            return stBuilder;
        }
    }



}<commit_msg>79: SimpleInsert's fieldname<commit_after>﻿//MIT 2015, brezza27, EngineKit and contributors
using System.Text;

namespace SharpConnect.MySql.Utils
{
    public class SimpleInsert : IHasParameters
    {
        MySqlCommand _sqlCommand;
        bool _isPrepared;
        public SimpleInsert(string targetTableName)
        {
            TargetTableName = targetTableName;
            Pars = new CommandParams();
        }
        public CommandParams Pars
        {
            get;
            private set;
        }
        public string TargetTableName { get; private set; }
        public MySqlConnection Connection { get; set; }
        public void ExecuteNonQuery(MySqlConnection conn)
        {
            Connection = conn;
            ExecuteNonQuery();
        }
        public void ExecuteNonQuery()
        {
            //create insert sql
            //then exec
            if (_isPrepared)
            {

                _sqlCommand.ExecuteNonQuery();
            }
            else
            {
                StringBuilder sql = CreateSqlText();
                _sqlCommand = new MySqlCommand(sql.ToString(), Pars, Connection);
                _sqlCommand.ExecuteNonQuery();
            }
        }
        public void Prepare()
        {
            if (_isPrepared)
            {
                throw new System.NotSupportedException("double prepare");
            }
            _isPrepared = true;
            StringBuilder sql = CreateSqlText();
            _sqlCommand = new MySqlCommand(sql.ToString(), Pars, Connection);
            _sqlCommand.Prepare();
        }
        public void Prepare(MySqlConnection conn)
        {
            if (_isPrepared)
            {
                throw new System.NotSupportedException("double prepare");
            }
            Connection = conn;
            Prepare();
        }
        StringBuilder CreateSqlText()
        {
            CommandParams pars = Pars;
            string[] valueKeys = pars.GetAttachedValueKeys();
            var stBuilder = new StringBuilder();
            stBuilder.Append("insert into ");
            stBuilder.Append(TargetTableName);
            stBuilder.Append('(');

            int j = valueKeys.Length;
            for (int i = 0; i < j; ++i)
            {
                string k = valueKeys[i];
                //sub string
                if (k[0] != '?')
                {
                    throw new System.NotSupportedException();
                }
                stBuilder.Append(k.Substring(1)); //remove ?

                if (i < j - 1)
                {
                    stBuilder.Append(',');
                }

            }
            stBuilder.Append(")  values(");
            for (int i = 0; i < j; ++i)
            {
                stBuilder.Append(valueKeys[i]);
                if (i < j - 1)
                {
                    stBuilder.Append(',');
                }
            }
            stBuilder.Append(")");
            return stBuilder;
        }
    } 
}
{'fraction_non_alphanumeric': 0.09142475809142475, 'fraction_numerical': 0.004337671004337671, 'mean_word_length': 1.2113611213574327, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, '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': '7140637', 'n_tokens_mistral': 1493, 'n_tokens_neox': 1417, 'n_words': 332}