首页 \ 问答 \ 表值CLR函数与SQL日期返回类型(Table Valued CLR Function with SQL date return type)

表值CLR函数与SQL日期返回类型(Table Valued CLR Function with SQL date return type)

我正在尝试创建一个CLR(C#)表值函数,它返回一个日期表。

[SqlFunction(
   DataAccess = DataAccessKind.Read,
   FillRowMethodName = "FindDates_FillRow",
   TableDefinition = "ReturnDate date")]
public static IEnumerable BusinessDays(SqlDateTime startDate, SqlDateTime endDate)
{
    //function body
}

public static void FindDates_FillRow(
object resultObj,
out SqlDateTime returnDate)
{
    dayResult result = (dayResult)resultObj;
    returnDate = result.Date;
}

上面的代码导致错误,因为SqlDateTime类型在FillRow上创建方法签名,该签名与SQL Server在给定TableDefinition属性时所期望的不同。

SQL72014:.Net SqlClient数据提供程序:消息6258,级别16,状态1,过程BusinessDays,第1行“FillRow”方法的函数签名(由SqlFunctionAttribute.FillRowMethodName指定)与表值CLR函数“BusinessDays”的SQL声明不匹配由于第1列。

如果我将TableDefinition更改为datetime类型,一切正常,但由于没有SqlDate类型,我该如何返回日期类型? 这甚至是可能的还是我只需要在CLR端使用datetime并在我的SQL查询中转换为日期?


I'm trying to create a CLR (C#) table valued function that returns a table of dates.

[SqlFunction(
   DataAccess = DataAccessKind.Read,
   FillRowMethodName = "FindDates_FillRow",
   TableDefinition = "ReturnDate date")]
public static IEnumerable BusinessDays(SqlDateTime startDate, SqlDateTime endDate)
{
    //function body
}

public static void FindDates_FillRow(
object resultObj,
out SqlDateTime returnDate)
{
    dayResult result = (dayResult)resultObj;
    returnDate = result.Date;
}

The above code results in an error because the SqlDateTime type creates a method signature on FillRow that differs from what SQL Server expects given the TableDefinition attribute.

SQL72014: .Net SqlClient Data Provider: Msg 6258, Level 16, State 1, Procedure BusinessDays, Line 1 Function signature of "FillRow" method (as designated by SqlFunctionAttribute.FillRowMethodName) does not match SQL declaration for table valued CLR function'BusinessDays' due to column 1.

If I change the TableDefinition to a datetime type, everything works but since there is no SqlDate type, how can I return a date type? Is this even possible or do I just need to use datetime on the CLR side and cast to a date in my SQL query?


原文:https://stackoverflow.com/questions/34513897
更新时间:2024-01-16 11:01

最满意答案

它看起来像使用SqlRowSet的副作用。 也许JDBC驱动程序在内部发出一些查询以支持它。

如果您不需要SqlRowSet特定功能,那么使用更传统的方法会更好。 例如,最好使用RowMapper<Contact>来查询List<Contact>


It looks like a side effect of using SqlRowSet. Perhaps JDBC driver issues some queries internally to support it.

If you don't need specific features of SqlRowSet it would be better to use more traditional approaches. For example, it would be better to use RowMapper<Contact> to query for List<Contact>.

相关问答

更多
  • 您正在使用聚合函数COUNT而没有n GROUP BY这将始终导致一行。 GROUP BY的定义 。 最好只使用2个单独的查询来获得你想要的东西,一个你选择所有其他变量,在一个中你只选择计数 所有行+变量 SELECT (SELECT GROUP_CONCAT(sp.specialization) FROM DSpecialization_Master dsp LEFT JOIN Specialization_Master sp on sp.id = dsp.specialization WHERE ds ...
  • 你不能,在PHPMyAdmin。 PHPMyAdmin使用FOUND_ROWS()本身来告诉你在最后一个查询中找到了多少行,并解析它本身以告诉你'发现了x个结果'。 每次你做一个简单的SELECT ,PHPMyAdmin都会添加一个限制并执行这个选择,然后FOUND_ROWS告诉你在没有LIMIT的情况下你会找到多少结果。 这是PHPMyAdmin如何提供分页(默认30个元素)。 另外,您不能调用FOUND_ROWS()两次:第二次调用它时,它会引用您第一次调用它。 由于第一次返回1行,因此得到1。 请注意 ...
  • 如果这是Wordpress,你可以替代第二个语句,否则你要求的数组不是数字: $count = $wpdb->get_var('SELECT FOUND_ROWS()'); 还要注意,由于过滤器,wordpress的数据库类可以更改任何查询, 并且默认情况下会根据结果集执行查询和提取来抑制错误。 您应该启用尖叫以查看是否遇到特定错误。 如果WP_DEBUG设置为true ,则$wpdb->show_errors = true自动显示错误。 ( 参考 ) If this is Wordpress, you ...
  • 检查你的模型$cacheQueries属性设置,它可能是true ,导致查询被缓存在CakePHP端。 使用第二个query()参数禁用每个查询的缓存: query('sql', false) 顺便说一下, ArticlesCategories.category_id = $categoryId看起来像是一个可能的SQL注入漏洞,你永远不应该在查询中插入数据, 总是使用key => value语法来表达条件,或者使用预处理语句! 另外,模型类不应该直接实例化,而应该使用ClassRegistry::ini ...
  • 它看起来像使用SqlRowSet的副作用。 也许JDBC驱动程序在内部发出一些查询以支持它。 如果您不需要SqlRowSet特定功能,那么使用更传统的方法会更好。 例如,最好使用RowMapper来查询List 。 It looks like a side effect of using SqlRowSet. Perhaps JDBC driver issues some queries internally to support it. If you don't nee ...
  • 不完全确定数据库类中发生了什么,所以对这个答案做了一些假设。 我假设这在你的机器上的一个阶段工作类似的代码,所以trace_mode不是答案。 我假设 $this->db->DBH() 是一个功能,它将获得一个新的数据库处理程序,以便在数据库查询中使用。 第二次调用DBH的prepare函数时,它正在创建一个新的数据库处理程序,它不会先存储来自其他DBH调用的信息。 修复就是做类似的事情 $dbh = $this->db->DBH(); 在函数的早期,然后用with替换prepare调用 $dbh- ...
  • 使用此查询 $qry ="SELECT DISTINCT user_id, login_date FROM login_members WHERE (login_date BETWEEN '2012-02-13 00:00:00' AND '2013-02-13 23:59:59') LIMIT 0, 10"; 如果前面的SELECT包含SQL_CALC_FOUND_ROWS,但如果前面的SELECT不包含SQL_CALC_FOUND_ROWS,则FOUND_ROWS()返回前面的SELECT返回的行数 ...
  • 尝试 UseAffectedRows=false 参考。 UseAffectedRows 如果为true,则连接报告已更改的行而不是找到的行。 此选项已在Connector / Net版本5.2.6中添加。 try UseAffectedRows=false reference. UseAffectedRows When true, the connection reports changed rows instead of found rows. This option was added in Co ...
  • 编辑: 这就是您要寻找的: http : //dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_found-rows 所以在你的查询中: SELECT sql_calc_found_rows ..... Edit : This is what you are looking for : http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#fun ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)