<commit_before>﻿using System;
using System.Text;

namespace ADatabase.Oracle.Columns
{
    public class OracleRawColumn: OracleColumn
    {
        public OracleRawColumn(string name, ColumnTypeName type, int length, bool isNullable, string def) 
            : base(name, type, isNullable, def)
        {
            Details["Length"] = length;
            if (IsGuid)
            {
                base.Default = ConvertNativeFunctionToKeyword(def);
            }
        }

        public override string TypeToString()
        {
            // Workaround to get OracleDataReader to work with raw(16):
            //    create column as raw(17)
            //    copy data
            //    resize to raw(16)
            return $"raw({Details["Length"]})";
        }

        protected override string ParseDefaultValue(string def)
        {
            switch (def)
            {
                case "GUID":
                    return "sys_guid()";
            }

            return def;
        }

        public override string Default
        {
            get { return base.Default; }
            set { base.Default = IsGuid ? ConvertNativeFunctionToKeyword(value) : value; }
        }

        private bool IsGuid => Type == ColumnTypeName.Guid;

        private static string ConvertNativeFunctionToKeyword(string guid)
        {
            if (guid.IndexOf("sys_guid", StringComparison.Ordinal) >= 0)
            {
                return "GUID";
            }

            return guid;
        }

        public override string ToString(object value)
        {
            if (IsGuid) return OracleGuidHelper.ConvertToGuid((byte[])value).ToString();
            return Encoding.UTF8.GetString((byte[])value);
        }

        public override object ToInternalType(string value)
        {
            if (value == null)
            {
                return DBNull.Value;
            }
            if (IsGuid) return OracleGuidHelper.ConvertToByteArray(Guid.Parse(value));
            return Encoding.UTF8.GetBytes(value);
        }

        public override Type GetDotNetType()
        {
            return typeof(byte[]);
        }

    }<commit_msg>Fixed bug: OracleRaw didn't base64 encode value.<commit_after>﻿using System;
using System.Text;

namespace ADatabase.Oracle.Columns
{
    public class OracleRawColumn: OracleColumn
    {
        public OracleRawColumn(string name, ColumnTypeName type, int length, bool isNullable, string def) 
            : base(name, type, isNullable, def)
        {
            Details["Length"] = length;
            if (IsGuid)
            {
                base.Default = ConvertNativeFunctionToKeyword(def);
            }
        }

        public override string TypeToString()
        {
            // Workaround to get OracleDataReader to work with raw(16):
            //    create column as raw(17)
            //    copy data
            //    resize to raw(16)
            return $"raw({Details["Length"]})";
        }

        protected override string ParseDefaultValue(string def)
        {
            switch (def)
            {
                case "GUID":
                    return "sys_guid()";
            }

            return def;
        }

        public override string Default
        {
            get { return base.Default; }
            set { base.Default = IsGuid ? ConvertNativeFunctionToKeyword(value) : value; }
        }

        private bool IsGuid => Type == ColumnTypeName.Guid;

        private static string ConvertNativeFunctionToKeyword(string guid)
        {
            if (guid.IndexOf("sys_guid", StringComparison.Ordinal) >= 0)
            {
                return "GUID";
            }

            return guid;
        }

        public override string ToString(object value)
        {
            if (IsGuid) return OracleGuidHelper.ConvertToGuid((byte[])value).ToString();
            return Convert.ToBase64String((byte[])value);
        }

        public override object ToInternalType(string value)
        {
            if (value == null)
            {
                return DBNull.Value;
            }
            if (IsGuid) return OracleGuidHelper.ConvertToByteArray(Guid.Parse(value));
            return Convert.FromBase64String(value);
        }

        public override Type GetDotNetType()
        {
            return typeof(byte[]);
        }

    }
{'fraction_non_alphanumeric': 0.0886801099908341, 'fraction_numerical': 0.005041246562786435, 'mean_word_length': 1.546674445740957, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 7, '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': '4503515', 'n_tokens_mistral': 1100, 'n_tokens_neox': 1063, 'n_words': 266}