This repository has been archived by the owner on Oct 8, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'fix-sql2005' into develop
- Loading branch information
Showing
20 changed files
with
255 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System.Data; | ||
using System.Data.SqlClient; | ||
using NCore; | ||
using SisoDb.Dac; | ||
using SisoDb.DbSchema; | ||
using SisoDb.SqlServer; | ||
|
||
namespace SisoDb.Sql2005 | ||
{ | ||
public class Sql2005AdoDriver : SqlServerAdoDriver | ||
{ | ||
protected override IDbDataParameter OnParameterCreated(IDbDataParameter parameter, IDacParameter dacParameter) | ||
{ | ||
var dbParam = (SqlParameter)parameter; | ||
var setSize = false; | ||
|
||
if (DbSchemas.Parameters.ShouldBeDateTime(dacParameter)) | ||
{ | ||
dbParam.DbType = DbType.DateTime; | ||
return dbParam; | ||
} | ||
|
||
if (DbSchemas.Parameters.ShouldBeNonUnicodeString(dacParameter)) | ||
{ | ||
dbParam.SqlDbType = SqlDbType.VarChar; | ||
setSize = true; | ||
} | ||
else if (DbSchemas.Parameters.ShouldBeUnicodeString(dacParameter)) | ||
{ | ||
dbParam.SqlDbType = SqlDbType.NVarChar; | ||
setSize = true; | ||
} | ||
|
||
if (setSize) | ||
{ | ||
dbParam.Size = (dacParameter.Value.ToStringOrNull() ?? string.Empty).Length; | ||
return dbParam; | ||
} | ||
|
||
return dbParam; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System.Collections.Generic; | ||
using System.Data; | ||
using System.Linq; | ||
using EnsureThat; | ||
using NCore; | ||
using NCore.Collections; | ||
using PineCone.Structures; | ||
using PineCone.Structures.Schemas; | ||
using SisoDb.Dac; | ||
using SisoDb.DbSchema; | ||
using SisoDb.SqlServer; | ||
|
||
namespace SisoDb.Sql2005 | ||
{ | ||
public class Sql2005DbClient : SqlServerDbClient | ||
{ | ||
protected override int MaxBatchedIdsSize | ||
{ | ||
get { return 32; } | ||
} | ||
|
||
public Sql2005DbClient(IAdoDriver driver, ISisoConnectionInfo connectionInfo, IDbConnection connection, IDbTransaction transaction, IConnectionManager connectionManager, ISqlStatements sqlStatements) | ||
: base(driver, connectionInfo, connection, transaction, connectionManager, sqlStatements) {} | ||
|
||
public override void DeleteByIds(IEnumerable<IStructureId> ids, IStructureSchema structureSchema) | ||
{ | ||
Ensure.That(structureSchema, "structureSchema").IsNotNull(); | ||
var sqlFormat = SqlStatements.GetSql("DeleteByIds").Inject(structureSchema.GetStructureTableName(), "{0}"); | ||
|
||
using (var cmd = CreateCommand(string.Empty)) | ||
{ | ||
foreach (var batchedIds in ids.Batch<IStructureId, IDacParameter>(MaxBatchedIdsSize, (id, batchCount) => new DacParameter(string.Concat("id", batchCount), id.Value))) | ||
{ | ||
cmd.Parameters.Clear(); | ||
Driver.AddCommandParametersTo(cmd, batchedIds); | ||
|
||
var paramsString = string.Join(",", batchedIds.Select(p => p.Name)); | ||
cmd.CommandText = sqlFormat.Inject(paramsString); | ||
cmd.ExecuteNonQuery(); | ||
} | ||
} | ||
} | ||
|
||
public override IEnumerable<string> GetJsonByIds(IEnumerable<IStructureId> ids, IStructureSchema structureSchema) | ||
{ | ||
Ensure.That(structureSchema, "structureSchema").IsNotNull(); | ||
var sqlFormat = SqlStatements.GetSql("GetJsonByIds").Inject(structureSchema.GetStructureTableName(), "{0}"); | ||
|
||
using (var cmd = CreateCommand(string.Empty)) | ||
{ | ||
foreach (var batchedIds in ids.Batch<IStructureId, IDacParameter>(MaxBatchedIdsSize, (id, batchCount) => new DacParameter(string.Concat("id", batchCount), id.Value))) | ||
{ | ||
cmd.Parameters.Clear(); | ||
Driver.AddCommandParametersTo(cmd, batchedIds); | ||
|
||
var paramsString = string.Join(",", batchedIds.Select(p => p.Name)); | ||
cmd.CommandText = sqlFormat.Inject(paramsString); | ||
|
||
using (var reader = cmd.ExecuteReader(CommandBehavior.SingleResult | CommandBehavior.SequentialAccess)) | ||
{ | ||
while (reader.Read()) | ||
{ | ||
yield return reader.GetString(0); | ||
} | ||
reader.Close(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System.Data; | ||
using SisoDb.Dac; | ||
using SisoDb.SqlServer; | ||
|
||
namespace SisoDb.Sql2005 | ||
{ | ||
public class Sql2005ServerClient : SqlServerClient | ||
{ | ||
public Sql2005ServerClient(IAdoDriver driver, ISisoConnectionInfo connectionInfo, IConnectionManager connectionManager, ISqlStatements sqlStatements) | ||
: base(driver, connectionInfo, connectionManager, sqlStatements) {} | ||
|
||
protected override void OnInitializeSysTypes(IDbConnection cn) | ||
{ | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
Source/Projects/SisoDb.Sql2005/Sql2005WhereCriteriaBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System.Text; | ||
using SisoDb.Dac; | ||
using SisoDb.Querying.Lambdas.Nodes; | ||
using SisoDb.Querying.Sql; | ||
|
||
namespace SisoDb.Sql2005 | ||
{ | ||
public class Sql2005WhereCriteriaBuilder : SqlWhereCriteriaBuilder | ||
{ | ||
public override void AddSetOfValues(ArrayValueNode valueNode) | ||
{ | ||
var tmp = new StringBuilder(); | ||
foreach (var value in valueNode.Value) | ||
{ | ||
if(tmp.Length > 0) tmp.Append(","); | ||
|
||
var param = new DacParameter(GetNextParameterName(), value); | ||
Params.Add(param); | ||
|
||
tmp.Append(param.Name); | ||
} | ||
|
||
AddValue(string.Format("({0})", tmp)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.