sunkaixuan
7 years ago
8 changed files with 11 additions and 356 deletions
@ -1,67 +0,0 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
|
|||
namespace SqlSugar |
|||
{ |
|||
public class PostgreSQLCodeFirst : CodeFirstProvider |
|||
{ |
|||
public override void NoExistLogic(EntityInfo entityInfo) |
|||
{ |
|||
var tableName = GetTableName(entityInfo); |
|||
Check.Exception(entityInfo.Columns.Where(it => it.IsPrimarykey).Count() > 1, "Use Code First ,The primary key must not exceed 1"); |
|||
List<DbColumnInfo> columns = new List<DbColumnInfo>(); |
|||
if (entityInfo.Columns.HasValue()) |
|||
{ |
|||
foreach (var item in entityInfo.Columns) |
|||
{ |
|||
DbColumnInfo dbColumnInfo = this.EntityColumnToDbColumn(entityInfo, tableName, item); |
|||
columns.Add(dbColumnInfo); |
|||
} |
|||
} |
|||
this.Context.DbMaintenance.CreateTable(tableName, columns); |
|||
} |
|||
protected override DbColumnInfo EntityColumnToDbColumn(EntityInfo entityInfo, string tableName, EntityColumnInfo item) |
|||
{ |
|||
var result = new DbColumnInfo() |
|||
{ |
|||
DataType = this.Context.Ado.DbBind.GetDbTypeName(UtilMethods.GetUnderType(item.PropertyInfo).Name), |
|||
TableId = entityInfo.Columns.IndexOf(item), |
|||
DbColumnName = item.DbColumnName.HasValue() ? item.DbColumnName : item.PropertyName, |
|||
IsPrimarykey = item.IsPrimarykey, |
|||
IsIdentity = item.IsIdentity, |
|||
TableName = tableName, |
|||
IsNullable = item.IsNullable, |
|||
DefaultValue = item.DefaultValue, |
|||
ColumnDescription = item.ColumnDescription, |
|||
Length = item.Length |
|||
}; |
|||
if (result.DataType.Equals("varchar", StringComparison.CurrentCultureIgnoreCase) && result.Length == 0) |
|||
{ |
|||
result.Length = 1; |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
protected override void ConvertColumns(List<DbColumnInfo> dbColumns) |
|||
{ |
|||
foreach (var item in dbColumns) |
|||
{ |
|||
if (item.DataType == "DateTime") |
|||
{ |
|||
item.Length = 0; |
|||
} |
|||
} |
|||
} |
|||
|
|||
protected override void ChangeKey(EntityInfo entityInfo, string tableName, EntityColumnInfo item) |
|||
{ |
|||
this.Context.DbMaintenance.UpdateColumn(tableName, EntityColumnToDbColumn(entityInfo, tableName, item)); |
|||
if (!item.IsPrimarykey) |
|||
this.Context.DbMaintenance.DropConstraint(tableName,null); |
|||
if (item.IsPrimarykey) |
|||
this.Context.DbMaintenance.AddPrimaryKey(tableName, item.DbColumnName); |
|||
} |
|||
} |
|||
} |
@ -1,92 +0,0 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
|
|||
namespace SqlSugar |
|||
{ |
|||
public class PostgreSQLDbBind : DbBindProvider |
|||
{ |
|||
public override string GetDbTypeName(string csharpTypeName) |
|||
{ |
|||
if (csharpTypeName == UtilConstants.ByteArrayType.Name) |
|||
{ |
|||
return "blob"; |
|||
} |
|||
if (csharpTypeName == "Int32") |
|||
csharpTypeName = "int"; |
|||
if (csharpTypeName == "Int16") |
|||
csharpTypeName = "short"; |
|||
if (csharpTypeName == "Int64") |
|||
csharpTypeName = "long"; |
|||
if (csharpTypeName == "Boolean") |
|||
csharpTypeName = "bool"; |
|||
var mappings = this.MappingTypes.Where(it => it.Value.ToString().Equals(csharpTypeName, StringComparison.CurrentCultureIgnoreCase)); |
|||
return mappings.HasValue() ? mappings.First().Key : "varchar"; |
|||
} |
|||
public override List<KeyValuePair<string, CSharpDataType>> MappingTypes |
|||
{ |
|||
get |
|||
{ |
|||
var extService = this.Context.CurrentConnectionConfig.ConfigureExternalServices; |
|||
if (extService != null && extService.AppendDataReaderTypeMappings.HasValue()) |
|||
{ |
|||
return extService.AppendDataReaderTypeMappings.Union(MappingTypesConst).ToList(); |
|||
} |
|||
else |
|||
{ |
|||
return MappingTypesConst; |
|||
} |
|||
} |
|||
} |
|||
public static List<KeyValuePair<string, CSharpDataType>> MappingTypesConst = new List<KeyValuePair<string, CSharpDataType>>(){ |
|||
|
|||
new KeyValuePair<string, CSharpDataType>("int",CSharpDataType.@int), |
|||
new KeyValuePair<string, CSharpDataType>("mediumint",CSharpDataType.@int), |
|||
new KeyValuePair<string, CSharpDataType>("integer",CSharpDataType.@int), |
|||
|
|||
new KeyValuePair<string, CSharpDataType>("varchar",CSharpDataType.@string), |
|||
new KeyValuePair<string, CSharpDataType>("text",CSharpDataType.@string), |
|||
new KeyValuePair<string, CSharpDataType>("char",CSharpDataType.@string), |
|||
new KeyValuePair<string, CSharpDataType>("enum",CSharpDataType.@string), |
|||
new KeyValuePair<string, CSharpDataType>("mediumtext",CSharpDataType.@string), |
|||
new KeyValuePair<string, CSharpDataType>("tinytext",CSharpDataType.@string), |
|||
new KeyValuePair<string, CSharpDataType>("longtext",CSharpDataType.@string), |
|||
|
|||
new KeyValuePair<string, CSharpDataType>("tinyint",CSharpDataType.@byte), |
|||
new KeyValuePair<string, CSharpDataType>("smallint",CSharpDataType.@short), |
|||
new KeyValuePair<string, CSharpDataType>("bigint",CSharpDataType.@long), |
|||
new KeyValuePair<string, CSharpDataType>("bit",CSharpDataType.@bool), |
|||
new KeyValuePair<string, CSharpDataType>("real",CSharpDataType.@double), |
|||
new KeyValuePair<string, CSharpDataType>("double",CSharpDataType.@double), |
|||
new KeyValuePair<string, CSharpDataType>("float",CSharpDataType.@float), |
|||
new KeyValuePair<string, CSharpDataType>("float",CSharpDataType.Single), |
|||
new KeyValuePair<string, CSharpDataType>("decimal",CSharpDataType.@decimal), |
|||
new KeyValuePair<string, CSharpDataType>("numeric",CSharpDataType.@decimal), |
|||
new KeyValuePair<string, CSharpDataType>("year",CSharpDataType.@int), |
|||
|
|||
new KeyValuePair<string, CSharpDataType>("datetime",CSharpDataType.DateTime), |
|||
new KeyValuePair<string, CSharpDataType>("timestamp",CSharpDataType.DateTime), |
|||
new KeyValuePair<string, CSharpDataType>("date",CSharpDataType.DateTime), |
|||
new KeyValuePair<string, CSharpDataType>("time",CSharpDataType.DateTime), |
|||
|
|||
new KeyValuePair<string, CSharpDataType>("blob",CSharpDataType.byteArray), |
|||
new KeyValuePair<string, CSharpDataType>("tinyblob",CSharpDataType.byteArray), |
|||
new KeyValuePair<string, CSharpDataType>("varbinary",CSharpDataType.byteArray), |
|||
new KeyValuePair<string, CSharpDataType>("binary",CSharpDataType.byteArray), |
|||
new KeyValuePair<string, CSharpDataType>("multipoint",CSharpDataType.byteArray), |
|||
new KeyValuePair<string, CSharpDataType>("geometry",CSharpDataType.byteArray), |
|||
new KeyValuePair<string, CSharpDataType>("multilinestring",CSharpDataType.byteArray), |
|||
new KeyValuePair<string, CSharpDataType>("polygon",CSharpDataType.byteArray), |
|||
new KeyValuePair<string, CSharpDataType>("mediumblob",CSharpDataType.byteArray), |
|||
|
|||
new KeyValuePair<string, CSharpDataType>("varchar",CSharpDataType.Guid), |
|||
}; |
|||
public override List<string> StringThrow |
|||
{ |
|||
get |
|||
{ |
|||
return new List<string>() { "int32", "datetime", "decimal", "double", "byte" }; |
|||
} |
|||
} |
|||
} |
|||
} |
@ -1,11 +0,0 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
|
|||
namespace SqlSugar |
|||
{ |
|||
public class PostgreSQLDbFirst : DbFirstProvider |
|||
{ |
|||
} |
|||
} |
@ -1,116 +0,0 @@ |
|||
using MySql.Data.MySqlClient; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Data; |
|||
using System.Data.SqlClient; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
namespace SqlSugar |
|||
{ |
|||
public class PostgreSQLProvider : AdoProvider |
|||
{ |
|||
public PostgreSQLProvider() { } |
|||
public override IDbConnection Connection |
|||
{ |
|||
get |
|||
{ |
|||
if (base._DbConnection == null) |
|||
{ |
|||
try |
|||
{ |
|||
var mySqlConnectionString = base.Context.CurrentConnectionConfig.ConnectionString; |
|||
if (!mySqlConnectionString.ToLower().Contains("charset")) |
|||
{ |
|||
mySqlConnectionString = mySqlConnectionString.Trim().TrimEnd(';') + ";charset=utf8;"; |
|||
} |
|||
base._DbConnection = new MySqlConnection(mySqlConnectionString); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
Check.Exception(true, ErrorMessage.ConnnectionOpen, ex.Message); |
|||
} |
|||
} |
|||
return base._DbConnection; |
|||
} |
|||
set |
|||
{ |
|||
base._DbConnection = value; |
|||
} |
|||
} |
|||
|
|||
public override void BeginTran(string transactionName) |
|||
{ |
|||
base.BeginTran(); |
|||
} |
|||
/// <summary>
|
|||
/// Only SqlServer
|
|||
/// </summary>
|
|||
/// <param name="iso"></param>
|
|||
/// <param name="transactionName"></param>
|
|||
public override void BeginTran(IsolationLevel iso, string transactionName) |
|||
{ |
|||
base.BeginTran(iso); |
|||
} |
|||
public override IDataAdapter GetAdapter() |
|||
{ |
|||
return new MySqlDataAdapter(); |
|||
} |
|||
public override IDbCommand GetCommand(string sql, SugarParameter[] parameters) |
|||
{ |
|||
MySqlCommand sqlCommand = new MySqlCommand(sql, (MySqlConnection)this.Connection); |
|||
sqlCommand.CommandType = this.CommandType; |
|||
sqlCommand.CommandTimeout = this.CommandTimeOut; |
|||
if (this.Transaction != null) |
|||
{ |
|||
sqlCommand.Transaction = (MySqlTransaction)this.Transaction; |
|||
} |
|||
if (parameters.HasValue()) |
|||
{ |
|||
IDataParameter[] ipars = ToIDbDataParameter(parameters); |
|||
sqlCommand.Parameters.AddRange((MySqlParameter[])ipars); |
|||
} |
|||
CheckConnection(); |
|||
return sqlCommand; |
|||
} |
|||
public override void SetCommandToAdapter(IDataAdapter dataAdapter, IDbCommand command) |
|||
{ |
|||
((MySqlDataAdapter)dataAdapter).SelectCommand = (MySqlCommand)command; |
|||
} |
|||
/// <summary>
|
|||
/// if mysql return MySqlParameter[] pars
|
|||
/// if sqlerver return SqlParameter[] pars ...
|
|||
/// </summary>
|
|||
/// <param name="parameters"></param>
|
|||
/// <returns></returns>
|
|||
public override IDataParameter[] ToIDbDataParameter(params SugarParameter[] parameters) |
|||
{ |
|||
if (parameters == null || parameters.Length == 0) return null; |
|||
MySqlParameter[] result = new MySqlParameter[parameters.Length]; |
|||
int index = 0; |
|||
foreach (var parameter in parameters) |
|||
{ |
|||
if (parameter.Value == null) parameter.Value = DBNull.Value; |
|||
var sqlParameter = new MySqlParameter(); |
|||
sqlParameter.ParameterName = parameter.ParameterName; |
|||
sqlParameter.Size = parameter.Size; |
|||
sqlParameter.Value = parameter.Value; |
|||
sqlParameter.DbType = parameter.DbType; |
|||
sqlParameter.Direction = parameter.Direction; |
|||
if (sqlParameter.Direction == 0) |
|||
{ |
|||
sqlParameter.Direction = ParameterDirection.Input; |
|||
} |
|||
result[index] = sqlParameter; |
|||
if (sqlParameter.Direction.IsIn(ParameterDirection.Output, ParameterDirection.InputOutput)) |
|||
{ |
|||
if (this.OutputParameters == null) this.OutputParameters = new List<IDataParameter>(); |
|||
this.OutputParameters.RemoveAll(it => it.ParameterName == sqlParameter.ParameterName); |
|||
this.OutputParameters.Add(sqlParameter); |
|||
} |
|||
++index; |
|||
} |
|||
return result; |
|||
} |
|||
} |
|||
} |
@ -1,60 +0,0 @@ |
|||
namespace SqlSugar |
|||
{ |
|||
public class PostgreSQLProviderQueryable<T> : QueryableProvider<T> |
|||
{ |
|||
public override ISugarQueryable<T> With(string withString) |
|||
{ |
|||
return this; |
|||
} |
|||
|
|||
public override ISugarQueryable<T> PartitionBy(string groupFileds) |
|||
{ |
|||
this.GroupBy(groupFileds); |
|||
return this; |
|||
} |
|||
} |
|||
public class PostgreSQLQueryable<T, T2> : QueryableProvider<T, T2> |
|||
{ |
|||
|
|||
} |
|||
public class PostgreSQLQueryable<T, T2, T3> : QueryableProvider<T, T2, T3> |
|||
{ |
|||
|
|||
} |
|||
public class PostgreSQLQueryable<T, T2, T3, T4> : QueryableProvider<T, T2, T3, T4> |
|||
{ |
|||
|
|||
} |
|||
public class PostgreSQLQueryable<T, T2, T3, T4, T5> : QueryableProvider<T, T2, T3, T4, T5> |
|||
{ |
|||
|
|||
} |
|||
public class PostgreSQLQueryable<T, T2, T3, T4, T5, T6> : QueryableProvider<T, T2, T3, T4, T5, T6> |
|||
{ |
|||
|
|||
} |
|||
public class PostgreSQLQueryable<T, T2, T3, T4, T5, T6, T7> : QueryableProvider<T, T2, T3, T4, T5, T6, T7> |
|||
{ |
|||
|
|||
} |
|||
public class PostgreSQLQueryable<T, T2, T3, T4, T5, T6, T7, T8> : QueryableProvider<T, T2, T3, T4, T5, T6, T7, T8> |
|||
{ |
|||
|
|||
} |
|||
public class PostgreSQLQueryable<T, T2, T3, T4, T5, T6, T7, T8,T9> : QueryableProvider<T, T2, T3, T4, T5, T6, T7, T8,T9> |
|||
{ |
|||
|
|||
} |
|||
public class PostgreSQLQueryable<T, T2, T3, T4, T5, T6, T7, T8,T9,T10> : QueryableProvider<T, T2, T3, T4, T5, T6, T7, T8, T9, T10> |
|||
{ |
|||
|
|||
} |
|||
public class PostgreSQLQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> : QueryableProvider<T, T2, T3, T4, T5, T6, T7, T8 ,T9, T10, T11> |
|||
{ |
|||
|
|||
} |
|||
public class PostgreSQLQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> : QueryableProvider<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> |
|||
{ |
|||
|
|||
} |
|||
} |
Loading…
Reference in new issue