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

namespace LinqToDB.DataProvider.Sybase
{
	using Common;
	using Data;
	using SchemaProvider;

	class SybaseSchemaProvider : SchemaProviderBase
	{
		protected override DataType GetDataType(string dataType, string columnType, long? length, int? prec, int? scale)
		{
			switch (dataType)
			{
				case "smallint"          : return DataType.Int16;
				case "unsigned smallint" : return DataType.UInt16;
				case "int"               : return DataType.Int32;
				case "unsigned int"      : return DataType.UInt32;
				case "real"              : return DataType.Single;
				case "float"             : return DataType.Double;
				case "money"             : return DataType.Money;
				case "smallmoney"        : return DataType.SmallMoney;
				case "bit"               : return DataType.Boolean;
				case "tinyint"           : return DataType.SByte;
				case "bigint"            : return DataType.Int64;
				case "unsigned bigint"   : return DataType.UInt64;
				case "timestamp"         : return DataType.Timestamp;
				case "binary"            : return DataType.Binary;
				case "image"             : return DataType.Image;
				case "text"              : return DataType.Text;
				case "unitext"           :
				case "ntext"             : return DataType.NText;
				case "decimal"           : return DataType.Decimal;
				case "numeric"           : return DataType.Decimal;
				case "datetime"          : return DataType.DateTime;
				case "smalldatetime"     : return DataType.SmallDateTime;
				case "sql_variant"       : return DataType.Variant;
				case "xml"               : return DataType.Xml;
				case "varchar"           : return DataType.VarChar;
				case "char"              : return DataType.Char;
				case "nchar"             : return DataType.NChar;
				case "nvarchar"          : return DataType.NVarChar;
				case "varbinary"         : return DataType.VarBinary;
				case "uniqueidentifier"  : return DataType.Guid;
			}

			return DataType.Undefined;
		}

		protected override string GetProviderSpecificTypeNamespace()
		{
			return "Sybase.Data.AseClient";
		}

		protected override List<TableInfo> GetTables(DataConnection dataConnection)
		{
			return dataConnection.Query<TableInfo>(@"
				SELECT
					id                                                 as TableID,
					@db                                                as CatalogName,
					USER_NAME(uid)                                     as SchemaName,
					name                                               as TableName,
					CASE WHEN type = 'V' THEN 1 ELSE 0 END             as IsView,
					CASE WHEN USER_NAME(uid) = 'dbo' THEN 1 ELSE 0 END as IsDefaultSchema
				FROM
					sysobjects
				WHERE
					type IN ('U','V') AND name like 'allocation%'",
				new { @db = dataConnection.Connection.Database})
				.ToList();
		}

		protected override List<PrimaryKeyInfo> GetPrimaryKeys(DataConnection dataConnection)
		{
			return dataConnection.Query<PrimaryKeyInfo>(@"
				SELECT
					i.id                                                              as TableID,
					i.name                                                            as PrimaryKeyName,
					INDEX_COL(USER_NAME(o.uid) + '.' + o.name, i.indid, c.colid)      as ColumnName,
					INDEX_COLORDER(USER_NAME(o.uid) + '.' + o.name, i.indid, c.colid),
					c.colid                                                           as Ordinal
				FROM
					sysindexes i
						JOIN sysobjects o ON i.id = o.id
						JOIN syscolumns c ON i.id = c.id
				WHERE
					i.status2 & 2 = 2 AND
					i.status & 2048 = 2048 AND<commit_msg>can load a lot of tables - no problem (how to save the dynamically generate data context to a static one?)<commit_after>﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;

namespace LinqToDB.DataProvider.Sybase
{
	using Common;
	using Data;
	using SchemaProvider;

	class SybaseSchemaProvider : SchemaProviderBase
	{
		protected override DataType GetDataType(string dataType, string columnType, long? length, int? prec, int? scale)
		{
			switch (dataType)
			{
				case "smallint"          : return DataType.Int16;
				case "unsigned smallint" : return DataType.UInt16;
				case "int"               : return DataType.Int32;
				case "unsigned int"      : return DataType.UInt32;
				case "real"              : return DataType.Single;
				case "float"             : return DataType.Double;
				case "money"             : return DataType.Money;
				case "smallmoney"        : return DataType.SmallMoney;
				case "bit"               : return DataType.Boolean;
				case "tinyint"           : return DataType.SByte;
				case "bigint"            : return DataType.Int64;
				case "unsigned bigint"   : return DataType.UInt64;
				case "timestamp"         : return DataType.Timestamp;
				case "binary"            : return DataType.Binary;
				case "image"             : return DataType.Image;
				case "text"              : return DataType.Text;
				case "unitext"           :
				case "ntext"             : return DataType.NText;
				case "decimal"           : return DataType.Decimal;
				case "numeric"           : return DataType.Decimal;
				case "datetime"          : return DataType.DateTime;
				case "smalldatetime"     : return DataType.SmallDateTime;
				case "sql_variant"       : return DataType.Variant;
				case "xml"               : return DataType.Xml;
				case "varchar"           : return DataType.VarChar;
				case "char"              : return DataType.Char;
				case "nchar"             : return DataType.NChar;
				case "nvarchar"          : return DataType.NVarChar;
				case "varbinary"         : return DataType.VarBinary;
				case "uniqueidentifier"  : return DataType.Guid;
			}

			return DataType.Undefined;
		}

		protected override string GetProviderSpecificTypeNamespace()
		{
			return "Sybase.Data.AseClient";
		}

		protected override List<TableInfo> GetTables(DataConnection dataConnection)
		{
			return dataConnection.Query<TableInfo>(@"
				SELECT
					id                                                 as TableID,
					@db                                                as CatalogName,
					USER_NAME(uid)                                     as SchemaName,
					name                                               as TableName,
					CASE WHEN type = 'V' THEN 1 ELSE 0 END             as IsView,
					CASE WHEN USER_NAME(uid) = 'dbo' THEN 1 ELSE 0 END as IsDefaultSchema
				FROM
					sysobjects
				WHERE
					type IN ('U')  --,'V') 
                AND name = lower(name) AND name not like 'aud%'",
				new { @db = dataConnection.Connection.Database})
				.ToList();
		}

		protected override List<PrimaryKeyInfo> GetPrimaryKeys(DataConnection dataConnection)
		{
			return dataConnection.Query<PrimaryKeyInfo>(@"
				SELECT
					i.id                                                              as TableID,
					i.name                                                            as PrimaryKeyName,
					INDEX_COL(USER_NAME(o.uid) + '.' + o.name, i.indid, c.colid)      as ColumnName,
					INDEX_COLORDER(USER_NAME(o.uid) + '.' + o.name, i.indid, c.colid),
					c.colid                                                           as Ordinal
				FROM
					sysindexes i
						JOIN sysobjects o ON i.id = o.id
						JOIN syscolumns c ON i.id = c.id
				WHERE
					i.status2 & 2 = 2 AND
					i.status & 2048 = 2048 AND
{'fraction_non_alphanumeric': 0.08363393453573814, 'fraction_numerical': 0.007214428857715431, 'mean_word_length': 1.7361111111111112, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5038334', 'n_tokens_mistral': 2532, 'n_tokens_neox': 2032, 'n_words': 567}