在评估表达式时,如何自定义符号的搜索路径?(How can I customize the search path of symbols when evaluating an expression?)
在我需要自定义某些符号的搜索路径的情况下。 例如,当我评估表达式
f(x,y,z)
,我需要在以下环境链中对其进行评估:首先,在
env1
中找到定义x
和y
符号,但f
和z
不定义。然后,在
env2
中找到定义了两者的f
和z
。问题是
env1
和env2
不是我自己定义的,也就是说,当我可以使用它们时,它们的父环境是确定的。对于这种特定情况,我可以手动调用
exists
并找到这些符号。 但这似乎不适用于一般情况下用户输入和未知的表达式。是否有一种通用且快速的方法适用于任何用户输入表达式,以便在一系列给定环境中使用
inherits = FALSE
(最后一个除外)评估此表达式。 假设该函数名为evalc
那么用法可能是:
evalc(quote(f(x,y,z)), env1, env2, env3)
给出一系列环境的地方。 对于
env1
和env2
,使用inherits = FALSE
查找符号; 但是对于env3
,使用inherits = TRUE
查找符号。In a case I need to customize the search path of some symbols. For example, when I evaluate an expression
f(x,y,z)
, I need to evaluate it in the following chain of environments:first, find symbols in
env1
wherex
andy
are defined, butf
andz
are not.then, find
f
andz
inenv2
where both are defined.The problem is that
env1
andenv2
are not defined by myself, that is, their parent environment is determined when I can use them.For this specific case, I can manually call
exists
andget
to find those symbols. But this seems not to work in general case where the expression in user-input and unknown in advance.Is there a general and fast way that work for any user-input expression so that this expression is evaluated within a series of given environment with
inherits = FALSE
except the last one. Suppose the function is namedevalc
then a usage may be:
evalc(quote(f(x,y,z)), env1, env2, env3)
where a series of environments are given. For
env1
andenv2
, the symbols are looked for withinherits = FALSE
; but forenv3
the symbols are looked for withinherits = TRUE
.
原文:https://stackoverflow.com/questions/25235152
最满意答案
哪个版本的SQL Server?
对于SQL Server 2005及更高版本,您可以获取用于创建视图的SQL脚本,如下所示:
select definition from sys.objects o join sys.sql_modules m on m.object_id = o.object_id where o.object_id = object_id( 'dbo.MyView') and o.type = 'V'
这将返回一行,其中包含用于创建/更改视图的脚本。
表中的其他列会说明在编译视图时有关的选项。
注意事项
如果视图最后使用ALTER VIEW进行了修改,那么脚本将是ALTER VIEW语句,而不是CREATE VIEW语句。
该脚本反映了创建的名称。 只有当您执行ALTER VIEW或者使用CREATE VIEW删除并重新创建视图时,才能更新它。 如果视图已被重命名(例如,通过
sp_rename
)或所有权已转移到不同的模式,则您返回的脚本将反映原始的CREATE / ALTER VIEW语句:它不会反映当前名称的对象。一些工具截断输出。 例如,MS-SQL命令行工具sqlcmd.exe会将数据截断为255个字符。 您可以传递参数
-y N
以获得N
字符的结果。Which version of SQL Server?
For SQL Server 2005 and later, you can obtain the SQL script used to create the view like this:
select definition from sys.objects o join sys.sql_modules m on m.object_id = o.object_id where o.object_id = object_id( 'dbo.MyView') and o.type = 'V'
This returns a single row containing the script used to create/alter the view.
Other columns in the table tell about about options in place at the time the view was compiled.
Caveats
If the view was last modified with ALTER VIEW, then the script will be an ALTER VIEW statement rather than a CREATE VIEW statement.
The script reflects the name as it was created. The only time it gets updated is if you execute ALTER VIEW, or drop and recreate the view with CREATE VIEW. If the view has been renamed (e.g., via
sp_rename
) or ownership has been transferred to a different schema, the script you get back will reflect the original CREATE/ALTER VIEW statement: it will not reflect the objects current name.Some tools truncate the output. For example, the MS-SQL command line tool sqlcmd.exe truncates the data at 255 chars. You can pass the parameter
-y N
to get the result withN
chars.
相关问答
更多-
TCP/IP模型是一个________。[2023-10-02]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
哪个版本的SQL Server? 对于SQL Server 2005及更高版本,您可以获取用于创建视图的SQL脚本,如下所示: select definition from sys.objects o join sys.sql_modules m on m.object_id = o.object_id where o.object_id = object_id( 'dbo.MyView') and o.type = 'V' 这将返回一行,其中包含用于创建/更改视图的脚本。 表中的其 ...
-
READ COMMITTED是Microsoft SQL Server数据库引擎的默认隔离级别。 资源: 自定义事务隔离级别@ MSDN 。 以下是与其他隔离级别的比较: MSDN上的事务隔离级别 。 READ COMMITTED is the default isolation level for the Microsoft SQL Server Database Engine. Source: Customizing Transaction Isolation Level @ MSDN. Here is ...
-
如何使用ADO.NET从C#中的SQL Server中检索数据?(How to retrieve data from SQL Server in C# using ADO.NET?)[2023-03-25]
有多种方法可以实现这一点。 您可以使用DataReader或DataSet \ DataTable 。 这些是分别连接和断开的体系结构。 如果您只想检索一个值,您也可以使用ExecuteScalar 。 建议: 在using块中包含SqlConnection (和任何其他IDisposable对象)。 我的代码使用try-catch块。 始终使用参数化查询。 以下是DataReader一些示例代码,以防您的查询返回多行。 代码从这里复制。 //Declare the SqlDataReader SqlDat ... -
视觉设计师无法将视图中可以使用的每个构造都视觉化。 语法错误也会导致此错误。 如果你得到这个错误,你唯一的选择就是不要使用可视化设计器,而是手动编辑SQL。 你可以使用这个 Right-Click -> Script View As -> ALTER to -> New Query Editor Window 一旦纠正了错误,并且可以成功运行ALTER VIEW ,您可以使用设计器。 The visual designer is not capable of visualising every const ...
-
SELECT ... FROM dbo.viewFirst vf INNER JOIN dbo.Table1 t1 ON vf.MVOID = t1.MVOID AND vf.ValidFrom = t1.ValidFrom LEFT OUTER JOIN dbo.Table2 t2 RIGHT OUTER JOIN dbo.Table3 t3 ...
-
一般来说,根据你的描述,你可以使用Linq-to-sql 一句警告 - 你写下你的问题 从逻辑上讲,似乎它可能(或可能不)通过批量更新/插入提交,缓存读取和延迟加载来提高性能。 在批量更新/插入的情况下,Linq肯定不会提高您的性能。 相反,使用SP或使用SqlBulkCopy进行批量插入的批量更新比Linq-sql快一些。 In general, given your description you will do fine with Linq-to-sql A word of warning - you ...
-
如何从Ado.Net中的VARCHAR中检索Bytes []?(How to get to retrieve Bytes[] from VARCHAR in Ado.Net?)[2022-04-26]
给出一张桌子 create table foobar ( id int not null primary key , some_text varchar(2000) not null , ) 要将some_text检索为八位字节: select id = id , some_octets = convert(varbinary(2000),some_text) from foobar 插入和更新: declare @id int ... -
由于您似乎使用的是Entity Framework,因此该代码将是这样的: using (YourDatabaseContext context = new YourDatabaseContext()) { User firstUser = context.Users.FirstOrDefault(u => u.statusUser == 0); if (firstUser != null) { lblUserName.Text = firstUser.nameUs ...