<commit_before>﻿using System.Collections.Generic;
using System.Linq;

namespace SchemaZen.model {
	public class Constraint {
		public bool Clustered;
		public List<string> Columns = new List<string>();
		public List<string> IncludedColumns = new List<string>();
		public string Name;
		public Table Table;
		public string Type;
		public bool Unique;
    public bool IgnoreDupKey;
    public byte FillFactor;
	  public bool IsPadded;
	  public bool AllowRowLocks;
	  public bool AllowPageLocks;
	  public bool StatisticsNoRecompute;

	  public Constraint(string name,
	    string type,
	    string columns,
	    bool ignoreDupKey,
      byte fillFactor,
      bool isPadded,
      bool allowRowLocks,
      bool allowPageLocks,
      bool statisticsNoRecompute) {
	    Name = name;
	    Type = type;
	    IgnoreDupKey = ignoreDupKey;
	    FillFactor = fillFactor;
      IsPadded = isPadded;
	    AllowRowLocks = allowRowLocks;
	    AllowPageLocks = allowPageLocks;
      StatisticsNoRecompute = statisticsNoRecompute;
	    if (!string.IsNullOrEmpty(columns)) {
	      Columns = new List<string>(columns.Split(','));
	    }
	  }

	  public string ClusteredText {
			get { return !Clustered ? "NONCLUSTERED" : "CLUSTERED"; }
		}

		public string UniqueText {
			get { return !Unique ? "" : "UNIQUE"; }
		}

		public string Script() {
		  string flags;
		  {
        var flagsBuilder = new System.Text.StringBuilder();
        AddFlag(flagsBuilder, "IGNORE_DUP_KEY", IgnoreDupKey);
        AddFlag(flagsBuilder, "FILLFACTOR", FillFactor);
        AddFlag(flagsBuilder, "PAD_INDEX", IsPadded);
        AddFlag(flagsBuilder, "ALLOW_ROW_LOCKS", AllowRowLocks);
        AddFlag(flagsBuilder, "ALLOW_PAGE_LOCKS", AllowPageLocks);
        AddFlag(flagsBuilder, "STATISTICS_NORECOMPUTE", StatisticsNoRecompute);
		    flags = flagsBuilder.ToString();
		  }
			if (Type == "INDEX") {
        string sql = string.Format("CREATE {0} {1} INDEX [{2}] ON [{3}].[{4}] ([{5}])" + System.Environment.NewLine + "  WITH({6})", UniqueText, ClusteredText, Name,
					Table.Owner, Table.Name,
					string.Join("], [", Columns.ToArray()),
          flags);
				if (IncludedColumns.Count > 0) {
					sql += string.Format(" INCLUDE ([{0}])", string.Join("], [", IncludedColumns.ToArray()));
				}
				return sql;
			}
      return string.Format("CONSTRAINT [{0}] {1} {2} ([{3}])" + System.Environment.NewLine + "  WITH({4})", Name, Type, ClusteredText,
				string.Join("], [", Columns.ToArray()), flags);
		}

    private void AddFlag(System.Text.StringBuilder builder, string name, bool value)
    {
      if (builder.Length > 0) {
        builder.Append(", ");
      }
      builder.Append(name);
      builder.Append(" = ");
      builder.Append(value ? "ON" : "OFF");
    }
    private void AddFlag(System.Text.StringBuilder builder, string name, byte value)
    {
      if (builder.Length > 0)
      {
        builder.Append(", ");
      }
      builder.Append(name);
      builder.Append(" = ");
      builder.Append(value.ToString(System.Globalization.CultureInfo.InvariantCulture));
    }
  }
}
<commit_msg>- Fixed FILLFACTOR: Only define if > 0<commit_after>﻿using System.Collections.Generic;
using System.Linq;

namespace SchemaZen.model {
	public class Constraint {
		public bool Clustered;
		public List<string> Columns = new List<string>();
		public List<string> IncludedColumns = new List<string>();
		public string Name;
		public Table Table;
		public string Type;
		public bool Unique;
    public bool IgnoreDupKey;
    public byte FillFactor;
	  public bool IsPadded;
	  public bool AllowRowLocks;
	  public bool AllowPageLocks;
	  public bool StatisticsNoRecompute;

	  public Constraint(string name,
	    string type,
	    string columns,
	    bool ignoreDupKey,
      byte fillFactor,
      bool isPadded,
      bool allowRowLocks,
      bool allowPageLocks,
      bool statisticsNoRecompute) {
	    Name = name;
	    Type = type;
	    IgnoreDupKey = ignoreDupKey;
	    FillFactor = fillFactor;
      IsPadded = isPadded;
	    AllowRowLocks = allowRowLocks;
	    AllowPageLocks = allowPageLocks;
      StatisticsNoRecompute = statisticsNoRecompute;
	    if (!string.IsNullOrEmpty(columns)) {
	      Columns = new List<string>(columns.Split(','));
	    }
	  }

	  public string ClusteredText {
			get { return !Clustered ? "NONCLUSTERED" : "CLUSTERED"; }
		}

		public string UniqueText {
			get { return !Unique ? "" : "UNIQUE"; }
		}

		public string Script() {
		  string flags;
		  {
        var flagsBuilder = new System.Text.StringBuilder();
        AddFlag(flagsBuilder, "IGNORE_DUP_KEY", IgnoreDupKey);
		    if (FillFactor > 0) {
		      AddFlag(flagsBuilder, "FILLFACTOR", FillFactor);
		    }
		    AddFlag(flagsBuilder, "PAD_INDEX", IsPadded);
        AddFlag(flagsBuilder, "ALLOW_ROW_LOCKS", AllowRowLocks);
        AddFlag(flagsBuilder, "ALLOW_PAGE_LOCKS", AllowPageLocks);
        AddFlag(flagsBuilder, "STATISTICS_NORECOMPUTE", StatisticsNoRecompute);
		    flags = flagsBuilder.ToString();
		  }
			if (Type == "INDEX") {
        string sql = string.Format("CREATE {0} {1} INDEX [{2}] ON [{3}].[{4}] ([{5}])" + System.Environment.NewLine + "  WITH({6})", UniqueText, ClusteredText, Name,
					Table.Owner, Table.Name,
					string.Join("], [", Columns.ToArray()),
          flags);
				if (IncludedColumns.Count > 0) {
					sql += string.Format(" INCLUDE ([{0}])", string.Join("], [", IncludedColumns.ToArray()));
				}
				return sql;
			}
      return string.Format("CONSTRAINT [{0}] {1} {2} ([{3}])" + System.Environment.NewLine + "  WITH({4})", Name, Type, ClusteredText,
				string.Join("], [", Columns.ToArray()), flags);
		}

    private void AddFlag(System.Text.StringBuilder builder, string name, bool value)
    {
      if (builder.Length > 0) {
        builder.Append(", ");
      }
      builder.Append(name);
      builder.Append(" = ");
      builder.Append(value ? "ON" : "OFF");
    }
    private void AddFlag(System.Text.StringBuilder builder, string name, byte value)
    {
      if (builder.Length > 0)
      {
        builder.Append(", ");
      }
      builder.Append(name);
      builder.Append(" = ");
      builder.Append(value.ToString(System.Globalization.CultureInfo.InvariantCulture));
    }
  }
}

{'fraction_non_alphanumeric': 0.13187871009144875, 'fraction_numerical': 0.005454837157067223, 'mean_word_length': 3.09861932938856, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 21, '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': '6569904', 'n_tokens_mistral': 2126, 'n_tokens_neox': 1939, 'n_words': 441}