我有一个使用MyBatis访问PostgreSQL数据库的Java项目.PostgreSQL允许在INSERT
语句后返回新创建的行的字段,我想用它来返回自动生成BIGSERIAL
id
的新创建的记录.因此,我insert
将XML中的命令更改为使用PostgreSQL的功能,resultType="long"
向<insert>
标记添加属性,并在映射器的Java接口中设置插入方法long
而不是返回void
.
当我尝试运行时,我得到一个org.xml.sax.SAXParseException
说法Attribute "resultType" must be declared for element type "insert"
.
现在,当我将<insert>
标签更改为<select>
一切正常时,但我使用<select>
标签执行INSERT
语句让我感到困扰.
有没有办法让映射到<insert>
标签的方法返回结果,或者MyBatis是不是为此设计的,我应该将它们作为<select>
标签保存?
在Clojure中,您需要gensym
使用在宏中创建内部使用的符号以保持其卫生.但是,有时您需要在嵌套语法引号中使用相同的符号.例如,如果我想将一个值绑定到符号let
并在展开的循环中打印三次,我会这样做
`(let [x# 1]
~@(repeat 3
`(println x#)))
Run Code Online (Sandbox Code Playgroud)
但那会产生
(clojure.core/let [x__2__auto__ 1]
(clojure.core/println x__1__auto__)
(clojure.core/println x__1__auto__)
(clojure.core/println x__1__auto__))
Run Code Online (Sandbox Code Playgroud)
x#
在let
表单中生成一个不同于println
嵌套在其中的表单中的符号- 因为它们是从不同的语法引号创建的.
为了解决这个问题,我可以预先生成符号并将其注入语法引号:
(let [x (gensym)]
`(let [~x 1]
~@(repeat 3
`(println ~x)))
)
Run Code Online (Sandbox Code Playgroud)
这将产生正确的结果,在任何地方需要相同的符号:
(clojure.core/let [G__7 1]
(clojure.core/println G__7)
(clojure.core/println G__7)
(clojure.core/println G__7))
Run Code Online (Sandbox Code Playgroud)
现在,虽然它确实产生了正确的结果,但代码本身看起来很丑陋且冗长.我不喜欢"声明"一个符号,注入语法使它看起来像是来自宏外部,或者在其中的某个地方计算.我希望能够使用auto-gensym语法,这清楚地表明这些是宏内部符号.
那么,有没有办法使用嵌套语法引号的auto-gensym并使它们产生相同的符号?
我的测试用例非常简单,我必须做一些非常愚蠢的事情.我写了一个简单的源文件test.c
:
#include<stdio.h>
int main(int argc,char* argv[]){
printf("1\n");
printf("2\n");
printf("3\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我用它编译gcc -g test.c
并启动了GDB gdb a.out
.然后我main
用with 创建了一个断点break main
并运行它run
(也试过start
) - 但是GDB只是忽略了我的断点!
这是我尝试编译test.c
和运行GDB 的shell会话:
[idanarye@idanarye_lg gdbtest]$ gcc -g test.c
[idanarye@idanarye_lg gdbtest]$ gdb a.out
GNU gdb (GDB) 7.6.1
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There …
Run Code Online (Sandbox Code Playgroud) 我正在尝试从我的C#代码运行PowerShell脚本,它将使用运行它们的程序集中的自定义Cmdlet.这是代码:
using System;
using System.Management.Automation;
[Cmdlet(VerbsCommon.Get,"Hello")]
public class GetHelloCommand:Cmdlet
{
protected override void EndProcessing()
{
WriteObject("Hello",true);
}
}
class MainClass
{
public static void Main(string[] args)
{
PowerShell powerShell=PowerShell.Create();
powerShell.AddCommand("Get-Hello");
foreach(string str in powerShell.AddCommand("Out-String").Invoke<string>())
Console.WriteLine(str);
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试运行它时,我得到一个CommandNotFoundException.我写错了Cmdlet吗?有什么我需要做的事情来在PowerShell或Runspace中注册我的Cmdlet吗?
根据MSDN,由简单选择组成的视图自动允许您在表上使用insert/update/delete语句.有没有办法防止这种情况 - 告诉Sql Server该视图是只读的,你不能用它来修改表?
我来自Ruby on Rails,我需要创建一个C#Web应用程序.目前我正在寻找ASP.NET MVC和MonoRail.我发现的大多数比较都是从2008年到2009年,当时ASP.NET MVC还是新的,而且针对MVC的大多数要点都是它太原始,不像MonoRail那么精致.
好吧,从那时起已有好几年了,微软在ASP.NET MVC上做了很多工作.两个框架的现代版本如何相互比较?
我有两个ActiveRecord模型:
class Foo < ActiveRecord::Base
has_many :bars,:dependent=>:destroy
end
class Bar < ActiveRecord::Base
belongs_to :foo
end
Run Code Online (Sandbox Code Playgroud)
我的设计要求Bar
需要与数据库依赖关联Foo
,但Foo
仅与Bar
数据库依赖关联- 以确保Foo
删除实例时,所有关联的实例Bar
也将被删除.除此之外,使用的代码Foo
不应该知道Bar
,我不希望可以从Foo
对象访问关联方法.
我已经尝试在声明private
之前has_many
声明Foo
,但它不起作用(我猜它只适用于直接用def
... 声明的方法).
有没有办法使关联私有,或实现数据库依赖而不创建Bar
关联Foo
?
我知道postgresql.conf
我可以限制PostgreSQL特定部分的内存使用,比如共享内存或工作内存,但有没有办法限制PostgreSQL服务器的总内存使用量?我找不到那样做的配置属性......
顺便说一下,我需要在Windows Server 2008机器上运行它.
我想在相同的参数化测试的不同实例之间共享夹具,其中夹具本身也是参数化的:
#!/usr/bin/py.test -sv
import pytest
numbers_for_fixture = [0]
def pytest_generate_tests(metafunc):
if "config_field" in metafunc.fixturenames:
metafunc.parametrize("config_field", [1], scope='session')
@pytest.fixture(scope = 'session')
def fixture_1(config_field):
numbers_for_fixture[0] += 1
return '\tfixture_1(%s)' % numbers_for_fixture[0]
@pytest.fixture(scope = 'session')
def fixture_2():
numbers_for_fixture[0] += 1
return '\tfixture_2(%s)' % numbers_for_fixture[0]
def test_a(fixture_1):
print('\ttest_a:', fixture_1)
def test_b(fixture_1):
print('\ttest_b:', fixture_1)
@pytest.mark.parametrize('i', range(3))
def test_c(fixture_1, i):
print('\ttest_c[%s]:' % i, fixture_1)
@pytest.mark.parametrize('i', range(3))
def test_d(fixture_2, i):
print('\ttest_d[%s]:' % i, fixture_2)
Run Code Online (Sandbox Code Playgroud)
我得到这个输出:
platform linux -- Python 3.4.1 -- py-1.4.26 -- pytest-2.6.4 -- /usr/bin/python
collecting …
Run Code Online (Sandbox Code Playgroud) 我一直在玩D,试图通过链接lambda表达式来模仿Scala风格的可编辑函数.
我想出了这个:
immutable foo=function(immutable int x)=>(immutable int y)=>(x+y);
struct S
{
static immutable foo=function(immutable int x)=>(immutable int y)=>(x+y);
}
class C static immutable foo=function(immutable int x)=>(immutable int y)=>(x+y);
}
void main()
{
writefln("global\t%s",foo(1)(2));
writefln("struct\t%s",S.foo(1)(2));
writefln("class\t%s",C.foo(1)(2));
}
Run Code Online (Sandbox Code Playgroud)
这是我运行时得到的:
global 3
struct 1528543170
Segmentation fault
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我的方法适用于全局函数变量,但struct的静态函数变量给出了垃圾结果,而类的静态函数变量完全失败.如果我x
从返回表达式中删除- function(immutable int x)=>(immutable int y)=>(y)
- struct version提供正确的result(2
),但类版本仍然失败.
如果我使用常规方法,而不是函数变量:
immutable foo=function(immutable int x)=>(immutable int y)=>(x+y);
struct S
{
static auto foo(immutable int x)
{
return (immutable int y)=>(x+y);
}
} …
Run Code Online (Sandbox Code Playgroud) c# ×2
postgresql ×2
.net ×1
activerecord ×1
associations ×1
clojure ×1
cmdlet ×1
currying ×1
d ×1
gdb ×1
gensym ×1
lambda ×1
mybatis ×1
powershell ×1
pytest ×1
python ×1
ruby ×1
sql-server ×1
views ×1