<commit_before>using System;
using System.Collections.Generic;
using System.Data;
using System.Reflection;
using ServiceStack.Common.Utils;
using System.Text;
using ServiceStack.Common;
using System.Data.OracleClient;

namespace ServiceStack.OrmLite.Oracle
{
    public class OracleOrmLiteDialectProvider : OrmLiteDialectProviderBase<OracleOrmLiteDialectProvider>
	{
		private readonly List<string> RESERVED = new List<string>(new[] {
			"USER","ORDER","PASSWORD", "ACTIVE","LEFT","DOUBLE", "FLOAT", "DECIMAL","STRING", "DATE","DATETIME", "TYPE","TIMESTAMP", "COMMENT"
		});
		
		public static OracleOrmLiteDialectProvider Instance = new OracleOrmLiteDialectProvider();
		
		internal long LastInsertId { get; set; }
		protected bool CompactGuid;

		internal const string DefaultGuidDefinition = "VARCHAR(37)";
		internal const string CompactGuidDefinition = "CHAR(16) CHARACTER SET OCTETS";

		public OracleOrmLiteDialectProvider()
			: this(false)
		{
		}

		public OracleOrmLiteDialectProvider(bool compactGuid)
		{
			CompactGuid = compactGuid;
			base.BoolColumnDefinition = base.IntColumnDefinition;
			base.GuidColumnDefinition = CompactGuid ? CompactGuidDefinition : DefaultGuidDefinition;
			base.AutoIncrementDefinition= string.Empty;
			base.DateTimeColumnDefinition="TIMESTAMP";
			base.TimeColumnDefinition = "TIME";
			base.RealColumnDefinition= "FLOAT";
			base.DefaultStringLength=128;
			base.InitColumnTypeMap();
            base.ParamString = ":";
		}
		
		public override IDbConnection CreateConnection(string connectionString, Dictionary<string, string> options)
		{
			if (options != null)
			{
				foreach (var option in options)
				{
					connectionString += option.Key + "=" + option.Value + ";";
				}
			}

            return new OracleConnection(connectionString);
		}
		
		public override long GetLastInsertId(IDbCommand dbCmd)
		{
			return LastInsertId;			
		}
		
		public override object ConvertDbValue(object value, Type type)
		{
			if (value == null || value is DBNull) return null;

			if (type == typeof(bool))
			{
				var intVal = int.Parse(value.ToString());
				return intVal != 0;
			}
			
			if(type == typeof(System.Double))
				return double.Parse(value.ToString());

			if (type == typeof(Guid) && BitConverter.IsLittleEndian) // TODO: check big endian
			{
				if (CompactGuid)
				{
					byte[] raw = ((Guid)value).ToByteArray();
					return new Guid(System.Net.IPAddress.NetworkToHostOrder(BitConverter.ToInt32(raw, 0)),
						System.Net.IPAddress.NetworkToHostOrder(BitConverter.ToInt16(raw, 4)),
						System.Net.IPAddress.NetworkToHostOrder(BitConverter.ToInt16(raw, 6)),
						raw[8], raw[9], raw[10], raw[11], raw[12], raw[13], raw[14], raw[15]);
				}
				return new Guid(value.ToString());
			}

			try
			{
				return base.ConvertDbValue(value, type);
			}
			catch (Exception )
			{				
				throw;
			}
		}

		public override string GetQuotedValue(object value, Type fieldType)
		{
						
			if (value == null) return "NULL";

			if (fieldType == typeof(Guid))
			{<commit_msg>Fixed byte issue for oracle<commit_after>using System;
using System.Collections.Generic;
using System.Data;
using System.Reflection;
using ServiceStack.Common.Utils;
using System.Text;
using ServiceStack.Common;
using System.Data.OracleClient;

namespace ServiceStack.OrmLite.Oracle
{
    public class OracleOrmLiteDialectProvider : OrmLiteDialectProviderBase<OracleOrmLiteDialectProvider>
	{
		private readonly List<string> RESERVED = new List<string>(new[] {
			"USER","ORDER","PASSWORD", "ACTIVE","LEFT","DOUBLE", "FLOAT", "DECIMAL","STRING", "DATE","DATETIME", "TYPE","TIMESTAMP", "COMMENT"
		});
		
		public static OracleOrmLiteDialectProvider Instance = new OracleOrmLiteDialectProvider();
		
		internal long LastInsertId { get; set; }
		protected bool CompactGuid;

		internal const string DefaultGuidDefinition = "VARCHAR(37)";
		internal const string CompactGuidDefinition = "CHAR(16) CHARACTER SET OCTETS";

		public OracleOrmLiteDialectProvider()
			: this(false)
		{
		}

		public OracleOrmLiteDialectProvider(bool compactGuid)
		{
			CompactGuid = compactGuid;
			base.BoolColumnDefinition = base.IntColumnDefinition;
			base.GuidColumnDefinition = CompactGuid ? CompactGuidDefinition : DefaultGuidDefinition;
			base.AutoIncrementDefinition= string.Empty;
			base.DateTimeColumnDefinition="TIMESTAMP";
			base.TimeColumnDefinition = "TIME";
			base.RealColumnDefinition= "FLOAT";
			base.DefaultStringLength=128;
			base.InitColumnTypeMap();
            base.ParamString = ":";
		}
		
		public override IDbConnection CreateConnection(string connectionString, Dictionary<string, string> options)
		{
			if (options != null)
			{
				foreach (var option in options)
				{
					connectionString += option.Key + "=" + option.Value + ";";
				}
			}

            return new OracleConnection(connectionString);
		}
		
		public override long GetLastInsertId(IDbCommand dbCmd)
		{
			return LastInsertId;			
		}
		
		public override object ConvertDbValue(object value, Type type)
		{
			if (value == null || value is DBNull) return null;

			if (type == typeof(bool))
			{
				var intVal = int.Parse(value.ToString());
				return intVal != 0;
			}
			
			if(type == typeof(System.Double))
				return double.Parse(value.ToString());

			if (type == typeof(Guid) && BitConverter.IsLittleEndian) // TODO: check big endian
			{
				if (CompactGuid)
				{
					byte[] raw = ((Guid)value).ToByteArray();
					return new Guid(System.Net.IPAddress.NetworkToHostOrder(BitConverter.ToInt32(raw, 0)),
						System.Net.IPAddress.NetworkToHostOrder(BitConverter.ToInt16(raw, 4)),
						System.Net.IPAddress.NetworkToHostOrder(BitConverter.ToInt16(raw, 6)),
						raw[8], raw[9], raw[10], raw[11], raw[12], raw[13], raw[14], raw[15]);
				}
				return new Guid(value.ToString());
			}

            if (type == typeof(byte[]))
                return value;

			try
			{
				return base.ConvertDbValue(value, type);
			}
			catch (Exception )
			{				
				throw;
			}
		}

		public override string GetQuotedValue(object value, Type fieldType)
		{
						
			if (value == null) return "NULL";

			if (fieldType == typeof(Guid))
			{
{'fraction_non_alphanumeric': 0.11909017059301381, 'fraction_numerical': 0.01007311129163282, 'mean_word_length': 3.909090909090909, 'pattern_counts': {'":': 2, '<': 11, '<?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': '6540352', 'n_tokens_mistral': 2274, 'n_tokens_neox': 1868, 'n_words': 403}