<commit_before>﻿using System.Collections.Generic;
using System.Data;
using MicroORM.Mapping;
using MicroORM.Storage;

namespace MicroORM.Query.Generic
{
    internal sealed class SqlQuery<T> : SqlQuery
    {
        private object _primaryKey = null;
        private string _additionalPredicate = null;

        internal SqlQuery(object primaryKey, string additionalPredicate = null, params object[] arguments)
            : base(string.Empty, arguments)
        {
            _primaryKey = primaryKey;
            _additionalPredicate = additionalPredicate;
        }

        internal SqlQuery(string sqlStatement, params object[] arguments)
            : base(sqlStatement, arguments) { }

        public override IDbCommand Compile(IDbProvider provider)
        {
            PrepareSqlStatement(provider);
            PrepareArguments();

            return base.Compile(provider);
        }

        private void PrepareSqlStatement(IDbProvider provider)
        {
            TableInfo typeMapping = TableInfo.GetTableInfo(typeof(T));
            base._sql = typeMapping.CreateSelectStatement(provider);
            if (string.IsNullOrEmpty(_additionalPredicate)) return;

            base._sql = string.Format("{0} and {1}", base._sql, _additionalPredicate);
        }

        private void PrepareArguments()
        {
            List<object> arguments = new List<object>(base.Arguments);
            arguments.Add(_primaryKey);
            base._arguments = arguments.ToArray();
        }
    }
}<commit_msg>PrimaryKey-Feld wird nur hinzugefügt wenn es NICHT null ist.<commit_after>﻿using System.Collections.Generic;
using System.Data;
using MicroORM.Mapping;
using MicroORM.Storage;

namespace MicroORM.Query.Generic
{
    internal sealed class SqlQuery<T> : SqlQuery
    {
        private object _primaryKey = null;
        private string _additionalPredicate = null;

        internal SqlQuery(object primaryKey, string additionalPredicate = null, params object[] arguments)
            : base(string.Empty, arguments)
        {
            _primaryKey = primaryKey;
            _additionalPredicate = additionalPredicate;
        }

        internal SqlQuery(string sqlStatement, params object[] arguments)
            : base(sqlStatement, arguments) { }

        public override IDbCommand Compile(IDbProvider provider)
        {
            if (_primaryKey != null)
                PrepareSqlStatement(provider);
            PrepareArguments();

            return base.Compile(provider);
        }

        private void PrepareSqlStatement(IDbProvider provider)
        {
            TableInfo typeMapping = TableInfo.GetTableInfo(typeof(T));
            base._sql = typeMapping.CreateSelectStatement(provider);
            if (string.IsNullOrEmpty(_additionalPredicate)) return;

            base._sql = string.Format("{0} and {1}", base._sql, _additionalPredicate);
        }

        private void PrepareArguments()
        {
            List<object> arguments = new List<object>(base.Arguments);
            if (_primaryKey != null)
                arguments.Add(_primaryKey);
            base._arguments = arguments.ToArray();
        }
    }
}
{'fraction_non_alphanumeric': 0.08525418377012946, 'fraction_numerical': 0.0012630249447426586, 'mean_word_length': 2.424864864864865, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '5378814', 'n_tokens_mistral': 796, 'n_tokens_neox': 770, 'n_words': 180}