Permalink
Browse files

No commit message

  • Loading branch information...
1 parent a461558 commit 866fb3238fd16cadedbcf60f414b8315ef597645 @Ivony committed Oct 30, 2012
Showing with 173 additions and 102 deletions.
  1. +45 −1 Sources/Ivony.Data/ExcelDbUtility.cs
  2. +28 −1 Sources/Ivony.Data/LegacyExtensions.cs
  3. +100 −100 Sources/Ivony.Data/TemplateExtensions.cs
@@ -1,15 +1,59 @@
using System;
using System.Collections.Generic;
+using System.Data;
using System.Linq;
using System.Text;
+using Ivony.Data.Expressions;
namespace Ivony.Data
{
public class ExcelDbUtility : DbUtility
{
protected override IDbExpressionParser GetExpressionParser()
{
- throw new NotImplementedException();
+ return new ExcelExpressionParser( this );
}
+
+ private class ExcelExpressionParser : IDbExpressionParser
+ {
+
+ public ExcelDbUtility _dbUtility;
+
+ public ExcelExpressionParser( ExcelDbUtility dbUtility )
+ {
+ _dbUtility = dbUtility;
+ }
+
+
+ public IDbCommand Parse( IDbExpression expression )
+ {
+ var templateExpression = expression as TemplateExpression;
+ if ( templateExpression != null )
+ return ParseTemplate( templateExpression );
+
+ throw new NotSupportedException();
+ }
+
+ private IDbCommand ParseTemplate( TemplateExpression templateExpression )
+ {
+ var context = new ExcelTemplateParseContext();
+ var commandText = templateExpression.Parse( context );
+
+ throw new NotImplementedException();
+ }
+
+
+ private class ExcelTemplateParseContext : TemplateParseContext
+ {
+ public override string CreateParameterExpression( ParameterExpression parameter )
+ {
+ throw new NotImplementedException();
+ }
+ }
+
+
+ }
+
+
}
}
@@ -1,14 +1,41 @@
using System;
using System.Collections.Generic;
+using System.Data;
using System.Linq;
using System.Text;
-namespace Ivony.Data
+namespace Ivony.Data.LegacyAPI
{
/// <summary>
/// 提供向下兼容的API
/// </summary>
public static class LegacyExtensions
{
+
+ public static DataTable ExecuteData( this DbUtility dbUtility, string template, params object[] args )
+ {
+ return dbUtility.Data( template, args );
+ }
+
+ public static object ExecuteScalar( this DbUtility dbUtility, string template, params object[] args )
+ {
+ return dbUtility.Scalar( template, args );
+ }
+
+ public static int ExecuteNonQuery( this DbUtility dbUtility, string template, params object[] args )
+ {
+ return dbUtility.ExecuteNonQuery( template, args );
+ }
+
+ public static DataRow ExecuteSingleRow( this DbUtility dbUtility, string template, params object[] args )
+ {
+ return dbUtility.FirstRow( template, args );
+ }
+
+ public static DataTable ExecuteData( this DbUtility dbUtility, string template, params object[] args )
+ {
+ return dbUtility.Data( template, args );
+ }
+
}
}
@@ -1,102 +1,102 @@
-using System;
-using System.Collections.Generic;
-using System.Data;
-using System.Linq;
-using System.Text;
-using Ivony.Data.Expressions;
-
-namespace Ivony.Data
-{
-
- /// <summary>
- /// 有关模板的扩展方法
- /// </summary>
- public static class TemplateExtensions
- {
-
-
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Linq;
+using System.Text;
+using Ivony.Data.Expressions;
+
+namespace Ivony.Data
+{
+
+ /// <summary>
+ /// 有关模板的扩展方法
+ /// </summary>
+ public static class TemplateExtensions
+ {
+
+
/// <summary>
/// 执行查询,并返回第一个结果集
- /// </summary>
- /// <param name="template">查询字符串模板</param>
- /// <param name="parameters">查询字符串参数</param>
- /// <returns></returns>
- public static DataTable Data( this DbUtility dbUtility, string template, params object[] parameters )
- {
- return dbUtility.ExecuteData( Template( template, parameters ) );
- }
-
- /// <summary>
- /// 执行无结果的查询
- /// </summary>
- /// <param name="commandText">查询字符串模板</param>
- /// <param name="parameters">查询字符串参数</param>
- /// <returns></returns>
- public static int NonQuery( this DbUtility dbUtility, string commandText, params object[] parameters )
- {
- return dbUtility.ExecuteNonQuery( Template( commandText, parameters ) );
- }
-
- /// <summary>
- /// 执行查询,并返回首行首列
- /// </summary>
- /// <param name="commandText">查询字符串模板</param>
- /// <param name="parameters">查询字符串参数</param>
- /// <returns></returns>
- public static object Scalar( this DbUtility dbUtility, string commandText, params object[] parameters )
- {
- return dbUtility.ExecuteScalar( Template( commandText, parameters ) );
- }
-
- /// <summary>
- /// 执行查询,并返回首行
- /// </summary>
- /// <param name="commandText">查询字符串模板</param>
- /// <param name="parameters">查询字符串参数</param>
- /// <returns></returns>
- public static DataRow FirstRow( this DbUtility dbUtility, string commandText, params object[] parameters )
- {
- return dbUtility.ExecuteFirstRow( Template( commandText, parameters ) );
- }
-
- /// <summary>
- /// 查询数据库并将最后一个结果集填充实体类型
- /// </summary>
- /// <typeparam name="T">实体类型</typeparam>
- /// <param name="dbUtility">DbUtility 实例</param>
- /// <param name="template">查询字符串模版</param>
- /// <param name="parameters">模版参数</param>
- /// <returns>实体集</returns>
- public static T[] Entities<T>( this DbUtility dbUtility, string template, params object[] parameters ) where T : new()
- {
- return dbUtility.Entities<T>( TemplateExtensions.Template( template, parameters ) );
- }
-
- /// <summary>
- /// 查询数据库并将结果首行填充实体
- /// </summary>
- /// <typeparam name="T">实体类型</typeparam>
- /// <param name="dbUtility">DbUtility 实例</param>
- /// <param name="template">查询字符串模版</param>
- /// <param name="parameters">模版参数</param>
- /// <returns>实体</returns>
- public static T Entity<T>( this DbUtility dbUtility, string template, params object[] parameters ) where T : new()
- {
- return dbUtility.Entity<T>( TemplateExtensions.Template( template, parameters ) );
- }
-
-
- /// <summary>
- /// 创建模版表达式实例
- /// </summary>
- /// <param name="template">SQL 命令模版</param>
- /// <param name="parameters">模版参数列表</param>
- /// <returns>模版表达式</returns>
- public static TemplateExpression Template( string template, object[] parameters )
- {
- return new TemplateExpression( template, parameters );
- }
-
-
- }
-}
+ /// </summary>
+ /// <param name="template">查询字符串模板</param>
+ /// <param name="parameters">查询字符串参数</param>
+ /// <returns></returns>
+ public static DataTable Data( this DbUtility dbUtility, string template, params object[] parameters )
+ {
+ return dbUtility.ExecuteData( Template( template, parameters ) );
+ }
+
+ /// <summary>
+ /// 执行无结果的查询
+ /// </summary>
+ /// <param name="commandText">查询字符串模板</param>
+ /// <param name="parameters">查询字符串参数</param>
+ /// <returns></returns>
+ public static int NonQuery( this DbUtility dbUtility, string commandText, params object[] parameters )
+ {
+ return dbUtility.ExecuteNonQuery( Template( commandText, parameters ) );
+ }
+
+ /// <summary>
+ /// 执行查询,并返回首行首列
+ /// </summary>
+ /// <param name="commandText">查询字符串模板</param>
+ /// <param name="parameters">查询字符串参数</param>
+ /// <returns></returns>
+ public static object Scalar( this DbUtility dbUtility, string commandText, params object[] parameters )
+ {
+ return dbUtility.ExecuteScalar( Template( commandText, parameters ) );
+ }
+
+ /// <summary>
+ /// 执行查询,并返回首行
+ /// </summary>
+ /// <param name="commandText">查询字符串模板</param>
+ /// <param name="parameters">查询字符串参数</param>
+ /// <returns></returns>
+ public static DataRow FirstRow( this DbUtility dbUtility, string commandText, params object[] parameters )
+ {
+ return dbUtility.ExecuteFirstRow( Template( commandText, parameters ) );
+ }
+
+ /// <summary>
+ /// 查询数据库并将最后一个结果集填充实体类型
+ /// </summary>
+ /// <typeparam name="T">实体类型</typeparam>
+ /// <param name="dbUtility">DbUtility 实例</param>
+ /// <param name="template">查询字符串模版</param>
+ /// <param name="parameters">模版参数</param>
+ /// <returns>实体集</returns>
+ public static T[] Entities<T>( this DbUtility dbUtility, string template, params object[] parameters ) where T : new()
+ {
+ return dbUtility.Entities<T>( TemplateExtensions.Template( template, parameters ) );
+ }
+
+ /// <summary>
+ /// 查询数据库并将结果首行填充实体
+ /// </summary>
+ /// <typeparam name="T">实体类型</typeparam>
+ /// <param name="dbUtility">DbUtility 实例</param>
+ /// <param name="template">查询字符串模版</param>
+ /// <param name="parameters">模版参数</param>
+ /// <returns>实体</returns>
+ public static T Entity<T>( this DbUtility dbUtility, string template, params object[] parameters ) where T : new()
+ {
+ return dbUtility.Entity<T>( TemplateExtensions.Template( template, parameters ) );
+ }
+
+
+ /// <summary>
+ /// 创建模版表达式实例
+ /// </summary>
+ /// <param name="template">SQL 命令模版</param>
+ /// <param name="parameters">模版参数列表</param>
+ /// <returns>模版表达式</returns>
+ public static TemplateExpression Template( string template, object[] parameters )
+ {
+ return new TemplateExpression( template, parameters );
+ }
+
+
+ }
+}

0 comments on commit 866fb32

Please sign in to comment.