-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from snowflakedb/pr-84
Pr 84
- Loading branch information
Showing
9 changed files
with
263 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (c) 2012-2017 Snowflake Computing Inc. All rights reserved. | ||
*/ | ||
|
||
namespace Snowflake.Data.Tests | ||
{ | ||
using NUnit.Framework; | ||
using Snowflake.Data; | ||
using System.Data.Common; | ||
|
||
[TestFixture] | ||
class SFDbFactoryIT : SFBaseTest | ||
{ | ||
[Test] | ||
public void TestSimpleDbFactory() | ||
{ | ||
#if NET46 | ||
DbProviderFactory factory = DbProviderFactories.GetFactory("Snowflake.Data"); | ||
#else | ||
// In .NET Standard, DbProviderFactories is gone. | ||
// Reference https://weblog.west-wind.com/posts/2017/Nov/27/Working-around-the-lack-of-dynamic-DbProviderFactory-loading-in-NET-Core | ||
// for more details | ||
DbProviderFactory factory = Snowflake.Data.Client.SnowflakeDbFactory.Instance; | ||
#endif | ||
DbCommand command = factory.CreateCommand(); | ||
DbConnection connection = factory.CreateConnection(); | ||
connection.ConnectionString = connectionString; | ||
connection.Open(); | ||
// set commnad's connection object | ||
command.Connection = connection; | ||
|
||
command.CommandText = "select 1"; | ||
object res = command.ExecuteScalar(); | ||
Assert.AreEqual(1, res); | ||
|
||
connection.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,114 @@ | ||
using System.Data; | ||
using System.Data.Common; | ||
using System.Globalization; | ||
|
||
namespace Snowflake.Data.Client | ||
{ | ||
public class SnowflakeDbCommandBuilder : DbCommandBuilder | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="SnowflakeDbCommandBuilder"/> class. | ||
/// </summary> | ||
public SnowflakeDbCommandBuilder() | ||
: this(null) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="SnowflakeDbCommandBuilder"/> class. | ||
/// </summary> | ||
/// <param name="adapter">The adapter.</param> | ||
public SnowflakeDbCommandBuilder(SnowflakeDbDataAdapter adapter) | ||
{ | ||
DataAdapter = adapter; | ||
QuotePrefix = "\""; | ||
QuoteSuffix = "\""; | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the beginning character or characters to use when specifying database objects (for example, tables or columns) whose names contain characters such as spaces or reserved tokens. | ||
/// </summary> | ||
/// <returns> | ||
/// The beginning character or characters to use. The default is an empty string. | ||
/// </returns> | ||
/// <PermissionSet> | ||
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" PathDiscovery="*AllFiles*" /> | ||
/// </PermissionSet> | ||
public sealed override string QuotePrefix | ||
{ | ||
get => base.QuotePrefix; | ||
// TODO: Why should it be possible to remove the QuotePrefix? | ||
set => base.QuotePrefix = string.IsNullOrEmpty(value) ? value : "\""; | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the ending character or characters to use when specifying database objects (for example, tables or columns) whose names contain characters such as spaces or reserved tokens. | ||
/// </summary> | ||
/// <returns> | ||
/// The ending character or characters to use. The default is an empty string. | ||
/// </returns> | ||
/// <PermissionSet> | ||
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" PathDiscovery="*AllFiles*" /> | ||
/// </PermissionSet> | ||
public sealed override string QuoteSuffix | ||
{ | ||
get => base.QuoteSuffix; | ||
// TODO: Why should it be possible to remove the QuoteSuffix? | ||
set => base.QuoteSuffix = string.IsNullOrEmpty(value) ? value : "\""; | ||
} | ||
|
||
/// <summary> | ||
/// Applies the parameter information. | ||
/// </summary> | ||
/// <param name="p">The parameter.</param> | ||
/// <param name="row">The row.</param> | ||
/// <param name="statementType">Type of the statement.</param> | ||
/// <param name="whereClause">if set to <c>true</c> [where clause].</param> | ||
protected override void ApplyParameterInfo(DbParameter p, DataRow row, StatementType statementType, bool whereClause) | ||
{ | ||
var param = (SnowflakeDbParameter)p; | ||
param.DbType = (DbType)row[SchemaTableColumn.ProviderType]; | ||
} | ||
|
||
/// <summary> | ||
/// Returns the name of the specified parameter in the format of #. | ||
/// </summary> | ||
/// <param name="parameterOrdinal">The number to be included as part of the parameter's name..</param> | ||
/// <returns> | ||
/// The name of the parameter with the specified number appended as part of the parameter name. | ||
/// </returns> | ||
protected override string GetParameterName(int parameterOrdinal) | ||
{ | ||
return string.Format(CultureInfo.InvariantCulture, "{0}", parameterOrdinal); | ||
} | ||
|
||
/// <summary> | ||
/// Returns the full parameter name, given the partial parameter name. | ||
/// </summary> | ||
/// <param name="parameterName">The partial name of the parameter.</param> | ||
/// <returns> | ||
/// The full parameter name corresponding to the partial parameter name requested. | ||
/// </returns> | ||
protected override string GetParameterName(string parameterName) | ||
{ | ||
return string.Format(CultureInfo.InvariantCulture, "{0}", parameterName); | ||
} | ||
|
||
/// <summary> | ||
/// Returns the placeholder for the parameter in the associated SQL statement. | ||
/// </summary> | ||
/// <param name="parameterOrdinal">The number to be included as part of the parameter's name.</param> | ||
/// <returns> | ||
/// The name of the parameter with the specified number appended. | ||
/// </returns> | ||
protected override string GetParameterPlaceholder(int parameterOrdinal) | ||
{ | ||
return GetParameterName(parameterOrdinal); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override void SetRowUpdatingHandler(DbDataAdapter adapter) | ||
{ | ||
} | ||
} | ||
} |
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
11 changes: 11 additions & 0 deletions
11
Snowflake.Data/Client/SnowflakeDbConnectionStringBuilder.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,11 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data.Common; | ||
using System.Text; | ||
|
||
namespace Snowflake.Data.Client | ||
{ | ||
public class SnowflakeDbConnectionStringBuilder : DbConnectionStringBuilder | ||
{ | ||
} | ||
} |
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,39 @@ | ||
using System.Data.Common; | ||
|
||
namespace Snowflake.Data.Client | ||
{ | ||
public sealed class SnowflakeDbFactory : DbProviderFactory | ||
{ | ||
public static readonly SnowflakeDbFactory Instance = new SnowflakeDbFactory(); | ||
|
||
/// <summary> | ||
/// Returns a strongly typed <see cref="DbCommand"/> instance. | ||
/// </summary> | ||
public override DbCommand CreateCommand() => new SnowflakeDbCommand(); | ||
|
||
/// <summary> | ||
/// Returns a strongly typed <see cref="DbConnection"/> instance. | ||
/// </summary> | ||
public override DbConnection CreateConnection() => new SnowflakeDbConnection(); | ||
|
||
/// <summary> | ||
/// Returns a strongly typed <see cref="DbParameter"/> instance. | ||
/// </summary> | ||
public override DbParameter CreateParameter() => new SnowflakeDbParameter(); | ||
|
||
/// <summary> | ||
/// Returns a strongly typed <see cref="DbConnectionStringBuilder"/> instance. | ||
/// </summary> | ||
public override DbConnectionStringBuilder CreateConnectionStringBuilder() => new SnowflakeDbConnectionStringBuilder(); | ||
|
||
/// <summary> | ||
/// Returns a strongly typed <see cref="DbCommandBuilder"/> instance. | ||
/// </summary> | ||
public override DbCommandBuilder CreateCommandBuilder() => new SnowflakeDbCommandBuilder(); | ||
|
||
/// <summary> | ||
/// Returns a strongly typed <see cref="DbDataAdapter"/> instance. | ||
/// </summary> | ||
public override DbDataAdapter CreateDataAdapter() => new SnowflakeDbDataAdapter(); | ||
} | ||
} |
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