mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-06-28 13:16:37 +08:00
Update Gbase
This commit is contained in:
parent
295e2b4ba6
commit
17ec5dba52
@ -16,16 +16,16 @@ namespace OrmTest
|
||||
/// Account have permission to create database
|
||||
/// 用有建库权限的数据库账号
|
||||
/// </summary>
|
||||
public static string ConnectionString = "Driver={GBase ODBC DRIVER (64-Bit)};Host=localhost;Service=19088;Server=gbase01;Database=testdb1;Protocol=onsoctcp;Uid=gbasedbt;Pwd=GBase123;Db_locale=zh_CN.utf8;Client_locale=zh_CN.utf8";
|
||||
public static string ConnectionString = "Driver={GBase ODBC DRIVER (64-Bit)};Host=localhost;Service=19088;Server=gbase01;Database=testdb;Protocol=onsoctcp;Uid=gbasedbt;Pwd=GBase123;Db_locale=zh_CN.utf8;Client_locale=zh_CN.utf8";
|
||||
/// <summary>
|
||||
/// Account have permission to create database
|
||||
/// 用有建库权限的数据库账号
|
||||
/// </summary>
|
||||
public static string ConnectionString2 = "Driver={GBase ODBC DRIVER (64-Bit)};Host=localhost;Service=19088;Server=gbase01;Database=testdb2;Protocol=onsoctcp;Uid=gbasedbt;Pwd=GBase123;Db_locale=zh_CN.utf8;Client_locale=zh_CN.utf8";
|
||||
public static string ConnectionString2 = "Driver={GBase ODBC DRIVER (64-Bit)};Host=localhost;Service=19088;Server=gbase01;Database=testdb;Protocol=onsoctcp;Uid=gbasedbt;Pwd=GBase123;Db_locale=zh_CN.utf8;Client_locale=zh_CN.utf8";
|
||||
/// <summary>
|
||||
/// Account have permission to create database
|
||||
/// 用有建库权限的数据库账号
|
||||
/// </summary>
|
||||
public static string ConnectionString3 = "Driver={GBase ODBC DRIVER (64-Bit)};Host=localhost;Service=19088;Server=gbase01;Database=testdb3;Protocol=onsoctcp;Uid=gbasedbt;Pwd=GBase123;Db_locale=zh_CN.utf8;Client_locale=zh_CN.utf8";
|
||||
public static string ConnectionString3 = "Driver={GBase ODBC DRIVER (64-Bit)};Host=localhost;Service=19088;Server=gbase01;Database=testdb;Protocol=onsoctcp;Uid=gbasedbt;Pwd=GBase123;Db_locale=zh_CN.utf8;Client_locale=zh_CN.utf8";
|
||||
}
|
||||
}
|
||||
|
@ -79,6 +79,7 @@ from systables a
|
||||
left join syscomments b on b.tabname = a.tabname
|
||||
where a.tabtype in ('T', 'V') and not (a.tabname like 'sys%') AND a.tabname <>'dual'");
|
||||
|
||||
|
||||
//Create tables
|
||||
db.CodeFirst.InitTables(typeof(OrderItem),typeof(Order));
|
||||
var id = db.Insertable(new Order() { Name = "order1", CustomId = 1, Price = 0, CreateTime = DateTime.Now }).ExecuteReturnIdentity();
|
||||
|
@ -6,9 +6,10 @@ namespace SqlSugar.GBase
|
||||
{
|
||||
public class GBaseCodeFirst:CodeFirstProvider
|
||||
{
|
||||
protected override void ExistLogicEnd(List<EntityColumnInfo> dbColumns)
|
||||
public virtual bool IsNoTran { get; set; } = true;
|
||||
public override void ExistLogic(EntityInfo entityInfo)
|
||||
{
|
||||
|
||||
this.Context.Ado.ExecuteCommand("select '不支持修改表' from dual ");
|
||||
}
|
||||
protected override string GetTableName(EntityInfo entityInfo)
|
||||
{
|
||||
|
@ -377,6 +377,10 @@ where a.tabtype in ('V') and not (a.tabname like 'sys%') AND a.tabname <>'dual'
|
||||
public override bool CreateDatabase(string databaseName, string databaseDirectory = null)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
public override void AddDefaultValue(EntityInfo entityInfo)
|
||||
{
|
||||
|
||||
}
|
||||
public override bool CreateTable(string tableName, List<DbColumnInfo> columns, bool isCreatePrimaryKey = true)
|
||||
{
|
||||
|
@ -7,6 +7,8 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
using System.Data.Odbc;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace SqlSugar.GBase
|
||||
{
|
||||
public class GBaseProvider : AdoProvider
|
||||
@ -34,6 +36,96 @@ namespace SqlSugar.GBase
|
||||
base._DbConnection = value;
|
||||
}
|
||||
}
|
||||
|
||||
public string SplitCommandTag => UtilConstants.ReplaceCommaKey.Replace("{", "").Replace("}", "");
|
||||
|
||||
|
||||
public override object GetScalar(string sql, params SugarParameter[] parameters)
|
||||
{
|
||||
if (sql == null) throw new Exception("sql is null");
|
||||
if (sql.IndexOf(this.SplitCommandTag) > 0)
|
||||
{
|
||||
var sqlParts = Regex.Split(sql, this.SplitCommandTag).Where(it => !string.IsNullOrEmpty(it)).ToList();
|
||||
object result = 0;
|
||||
foreach (var item in sqlParts)
|
||||
{
|
||||
if (item.TrimStart('\r').TrimStart('\n') != "")
|
||||
{
|
||||
result = base.GetScalar(item, parameters);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
return base.GetScalar(sql, parameters);
|
||||
}
|
||||
}
|
||||
public override async Task<object> GetScalarAsync(string sql, params SugarParameter[] parameters)
|
||||
{
|
||||
if (sql == null) throw new Exception("sql is null");
|
||||
if (sql.IndexOf(this.SplitCommandTag) > 0)
|
||||
{
|
||||
var sqlParts = Regex.Split(sql, this.SplitCommandTag).Where(it => !string.IsNullOrEmpty(it)).ToList();
|
||||
object result = 0;
|
||||
foreach (var item in sqlParts)
|
||||
{
|
||||
if (item.TrimStart('\r').TrimStart('\n') != "")
|
||||
{
|
||||
result = await base.GetScalarAsync(item, parameters);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
return await base.GetScalarAsync(sql, parameters);
|
||||
}
|
||||
}
|
||||
|
||||
public override int ExecuteCommand(string sql, SugarParameter [] parameters)
|
||||
{
|
||||
if (sql == null) throw new Exception("sql is null");
|
||||
if (sql.IndexOf(this.SplitCommandTag) > 0)
|
||||
{
|
||||
var sqlParts = Regex.Split(sql, this.SplitCommandTag).Where(it => !string.IsNullOrEmpty(it)).ToList();
|
||||
int result = 0;
|
||||
foreach (var item in sqlParts)
|
||||
{
|
||||
if (item.TrimStart('\r').TrimStart('\n') != "")
|
||||
{
|
||||
result += base.ExecuteCommand(item, parameters);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
return base.ExecuteCommand(sql, parameters);
|
||||
}
|
||||
}
|
||||
public override async Task<int> ExecuteCommandAsync(string sql, SugarParameter [] parameters)
|
||||
{
|
||||
if (sql == null) throw new Exception("sql is null");
|
||||
if (sql.IndexOf(this.SplitCommandTag) > 0)
|
||||
{
|
||||
var sqlParts = Regex.Split(sql, this.SplitCommandTag).Where(it => !string.IsNullOrEmpty(it)).ToList();
|
||||
int result = 0;
|
||||
foreach (var item in sqlParts)
|
||||
{
|
||||
if (item.TrimStart('\r').TrimStart('\n') != "")
|
||||
{
|
||||
result +=await base.ExecuteCommandAsync(item, parameters);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
return base.ExecuteCommand(sql, parameters);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Only GBase
|
||||
/// </summary>
|
||||
@ -53,12 +145,22 @@ namespace SqlSugar.GBase
|
||||
CheckConnection();
|
||||
base.Transaction = ((OdbcConnection)this.Connection).BeginTransaction(iso);
|
||||
}
|
||||
|
||||
public override IDataAdapter GetAdapter()
|
||||
{
|
||||
return new GBaseDataAdapter();
|
||||
}
|
||||
public override DbCommand GetCommand(string sql, SugarParameter[] parameters)
|
||||
{
|
||||
var helper = new GBaseInsertBuilder();
|
||||
helper.Context = this.Context;
|
||||
if (parameters != null)
|
||||
{
|
||||
foreach (var param in parameters.OrderByDescending(it => it.ParameterName.Length))
|
||||
{
|
||||
sql = sql.Replace(param.ParameterName, helper.FormatValue(param.Value) + "");
|
||||
}
|
||||
}
|
||||
OdbcCommand sqlCommand = new OdbcCommand(sql, (OdbcConnection)this.Connection);
|
||||
sqlCommand.CommandType = this.CommandType;
|
||||
sqlCommand.CommandTimeout = this.CommandTimeOut;
|
||||
@ -66,11 +168,11 @@ namespace SqlSugar.GBase
|
||||
{
|
||||
sqlCommand.Transaction = (OdbcTransaction)this.Transaction;
|
||||
}
|
||||
if (parameters.HasValue())
|
||||
{
|
||||
OdbcParameter[] ipars = GetSqlParameter(parameters);
|
||||
sqlCommand.Parameters.AddRange(ipars);
|
||||
}
|
||||
//if (parameters.HasValue())
|
||||
//{
|
||||
// OdbcParameter[] ipars = GetSqlParameter(parameters);
|
||||
// sqlCommand.Parameters.AddRange(ipars);
|
||||
//}
|
||||
CheckConnection();
|
||||
return sqlCommand;
|
||||
}
|
||||
|
@ -15,6 +15,36 @@ namespace SqlSugar.GBase
|
||||
{
|
||||
return name;
|
||||
}
|
||||
public override string GetTranslationTableName(string name)
|
||||
{
|
||||
Check.ArgumentNullException(name, string.Format(ErrorMessage.ObjNotExist, "Table Name"));
|
||||
if (!name.Contains("<>f__AnonymousType") && name.IsContainsIn("(", ")") && name != "Dictionary`2")
|
||||
{
|
||||
return name;
|
||||
}
|
||||
if (Context.MappingTables == null)
|
||||
{
|
||||
return name;
|
||||
}
|
||||
var context = this.Context;
|
||||
var mappingInfo = context
|
||||
.MappingTables
|
||||
.FirstOrDefault(it => it.EntityName.Equals(name, StringComparison.CurrentCultureIgnoreCase));
|
||||
name = (mappingInfo == null ? name : mappingInfo.DbTableName);
|
||||
if (name.IsContainsIn("(", ")", SqlTranslationLeft))
|
||||
{
|
||||
return name;
|
||||
}
|
||||
if (name.Contains("."))
|
||||
{
|
||||
return string.Join(".", name.Split('.').Select(it => SqlTranslationLeft + it + SqlTranslationRight));
|
||||
}
|
||||
else
|
||||
{
|
||||
return SqlTranslationLeft + name + SqlTranslationRight;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,6 +8,40 @@ namespace SqlSugar.GBase
|
||||
{
|
||||
public class GBaseInsertBuilder:InsertBuilder
|
||||
{
|
||||
public override string SqlTemplate
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsReturnIdentity)
|
||||
{
|
||||
return @"INSERT INTO {0}
|
||||
({1})
|
||||
VALUES
|
||||
({2})"+UtilConstants.ReplaceCommaKey.Replace("{","").Replace("}", "") + " SELECT dbinfo('sqlca.sqlerrd1') FROM dual";
|
||||
}
|
||||
else
|
||||
{
|
||||
return @"INSERT INTO {0}
|
||||
({1})
|
||||
VALUES
|
||||
({2}) "+UtilConstants.ReplaceCommaKey.Replace("{", "").Replace("}", "") + "SELECT dbinfo('sqlca.sqlerrd1') FROM dual";
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
public override string GetTableNameString
|
||||
{
|
||||
get
|
||||
{
|
||||
var result = Builder.GetTranslationTableName(EntityInfo.EntityName);
|
||||
result += UtilConstants.Space;
|
||||
if (this.TableWithString.HasValue())
|
||||
{
|
||||
result += TableWithString + UtilConstants.Space;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
public override string ToSqlString()
|
||||
{
|
||||
if (IsNoInsertNull)
|
||||
@ -48,19 +82,83 @@ namespace SqlSugar.GBase
|
||||
{
|
||||
batchInsetrSql.Append(SqlTemplateBatchUnion);
|
||||
}
|
||||
batchInsetrSql.Append("\r\n SELECT " + string.Join(",", columns.Select(it => string.Format(SqlTemplateBatchSelect, FormatValue(it.Value), Builder.GetTranslationColumnName(it.DbColumnName)))));
|
||||
batchInsetrSql.Append("\r\n SELECT " + string.Join(",", columns.Select(it => string.Format(SqlTemplateBatchSelect, FormatValue(it.Value), Builder.GetTranslationColumnName(it.DbColumnName))))+" from dual");
|
||||
++i;
|
||||
}
|
||||
pageIndex++;
|
||||
batchInsetrSql.Append("\r\n;\r\n");
|
||||
}
|
||||
var result = batchInsetrSql.ToString();
|
||||
if (this.Context.CurrentConnectionConfig.DbType == DbType.GBase)
|
||||
{
|
||||
result += "select SCOPE_IDENTITY();";
|
||||
}
|
||||
//if (this.Context.CurrentConnectionConfig.DbType == DbType.GBase)
|
||||
//{
|
||||
// result += "";
|
||||
//}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
public override object FormatValue(object value)
|
||||
{
|
||||
var n = "";
|
||||
if (value == null)
|
||||
{
|
||||
return "NULL";
|
||||
}
|
||||
else
|
||||
{
|
||||
var type = UtilMethods.GetUnderType(value.GetType());
|
||||
if (type == UtilConstants.DateType)
|
||||
{
|
||||
return GetDateTimeString(value);
|
||||
}
|
||||
else if (value is DateTimeOffset)
|
||||
{
|
||||
return GetDateTimeOffsetString(value);
|
||||
}
|
||||
else if (type == UtilConstants.ByteArrayType)
|
||||
{
|
||||
string bytesString = "0x" + BitConverter.ToString((byte[])value).Replace("-", "");
|
||||
return bytesString;
|
||||
}
|
||||
else if (type.IsEnum())
|
||||
{
|
||||
if (this.Context.CurrentConnectionConfig.MoreSettings?.TableEnumIsString == true)
|
||||
{
|
||||
return value.ToSqlValue(); ;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Convert.ToInt64(value);
|
||||
}
|
||||
}
|
||||
else if (type == UtilConstants.BoolType)
|
||||
{
|
||||
return value.ObjToBool() ? "1" : "0";
|
||||
}
|
||||
else
|
||||
{
|
||||
return n + "'" + value + "'";
|
||||
}
|
||||
}
|
||||
}
|
||||
private object GetDateTimeOffsetString(object value)
|
||||
{
|
||||
var date = UtilMethods.ConvertFromDateTimeOffset((DateTimeOffset)value);
|
||||
if (date < UtilMethods.GetMinDate(this.Context.CurrentConnectionConfig))
|
||||
{
|
||||
date = UtilMethods.GetMinDate(this.Context.CurrentConnectionConfig);
|
||||
}
|
||||
return "'" + date.ToString("yyyy-MM-dd HH:mm:ss.fff") + "'";
|
||||
}
|
||||
|
||||
private object GetDateTimeString(object value)
|
||||
{
|
||||
var date = value.ObjToDate();
|
||||
if (date < UtilMethods.GetMinDate(this.Context.CurrentConnectionConfig))
|
||||
{
|
||||
date = UtilMethods.GetMinDate(this.Context.CurrentConnectionConfig);
|
||||
}
|
||||
return "'" + date.ToString("yyyy-MM-dd HH:mm:ss.fff") + "'";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user