小编Jea*_*bre的帖子

可以在SQL BulkCopy之后返回PrimayKey ID吗?

我正在使用C#并使用SqlBulkCopy.我有一个问题.我需要将质量插入到一个表中然后将另一个质量插入到另一个表中.

这2个具有PK/FK关系.

Table A
Field1 -PK auto incrementing (easy to do SqlBulkCopy as straight forward)

Table B
Field1 -PK/FK - This field makes the relationship and is also the PK of this table. It is not auto incrementing and needs to have the same id as to the row in Table A.
Run Code Online (Sandbox Code Playgroud)

所以这些表有一对一的关系,但我不确定如何取回质量插入所做的所有PK Id,因为我需要它们用于表B.

编辑

我可以这样做吗?

SELECT * 
FROM Product
WHERE NOT EXISTS (SELECT * FROM ProductReview WHERE Product.ProductId = ProductReview.ProductId AND Product.Qty = NULL AND Product.ProductName != 'Ipad')
Run Code Online (Sandbox Code Playgroud)

这应该找到刚刚插入sql批量副本的所有行.我不确定如何从中获取结果,然后从SP进行质量插入. …

c# sql sql-server-2005 sqlbulkcopy

19
推荐指数
3
解决办法
1万
查看次数

下面的代码应该按照C++标准编译吗?

#include <type_traits>

template <typename T>
struct C;

template<typename T1, typename T2>
using first = T1;

template <typename T>
struct C<first<T, std::enable_if_t<std::is_same<T, int>::value>>>
{
};

int main ()
{
}
Run Code Online (Sandbox Code Playgroud)

不同编译器编译的结果:

MSVC:

错误C2753:'C':部分特化与主模板的参数列表不匹配

GCC-4.9:

错误:部分特化'C'不专门化任何模板参数

clang所有版本:

错误:类模板部分特化没有专门化任何模板参数; 要定义主模板,请删除模板参数列表

gcc-5 +:成功编译

另外我想指出那些琐碎的专业化:

template<typename T>
struct C<T>
{
};
Run Code Online (Sandbox Code Playgroud)

成功地无法由gcc编译.因此,似乎它认为我原始示例中的专业化是非平凡的.所以我的问题是 - 这样的模式是否被C++标准明确禁止?

c++ gcc templates sfinae language-lawyer

17
推荐指数
2
解决办法
654
查看次数

GDB的C ++调试/打印自定义类型:nlohmann json库的情况

我正在使用nlohmann的json C ++实现进行项目开发

如何在GDB中轻松浏览nlohmann的JSON键/值?

我尝试使用此STL gdb包装,因为它提供了帮助者探索nlohmann的JSON库正在使用的标准C ++库结构。但是我觉得不方便。

这是一个简单的用例:

json foo;
foo["flex"] = 0.2;
foo["awesome_str"] = "bleh";
foo["nested"] = {{"bar", "barz"}}; 
Run Code Online (Sandbox Code Playgroud)

我想在GDB中拥有什么:

(gdb) p foo
{
    "flex" : 0.2,
    "awesome_str": "bleh",
    "nested": etc.
}
Run Code Online (Sandbox Code Playgroud)

当前行为

(gdb) p foo
$1 = {
  m_type = nlohmann::detail::value_t::object, 
  m_value = {
    object = 0x129ccdd0, 
    array = 0x129ccdd0, 
    string = 0x129ccdd0, 
    boolean = 208, 
    number_integer = 312266192, 
    number_unsigned = 312266192, 
    number_float = 1.5427999782486669e-315
  }
}
(gdb) p foo.at("flex")
Cannot evaluate …
Run Code Online (Sandbox Code Playgroud)

c++ json gdb pretty-print nlohmann-json

17
推荐指数
1
解决办法
922
查看次数

ValueError:无法从手动字段规范切换到自动字段编号

班级:

class Book(object):
    def __init__(self, title, author):
        self.title = title
        self.author = author

    def get_entry(self):
        return "{0} by {1} on {}".format(self.title, self.author, self.press)
Run Code Online (Sandbox Code Playgroud)

从中创建我的书的实例:

In [72]: mybook = Book('HTML','Lee')
In [75]: mybook.title
Out[75]: 'HTML'
In [76]: mybook.author
Out[76]: 'Lee'
Run Code Online (Sandbox Code Playgroud)

请注意,我没有初始化属性'self.press',而是在get_entry方法中使用它.继续输入数据.

mybook.press = 'Murach'
mybook.price = 'download'
Run Code Online (Sandbox Code Playgroud)

直到现在,我可以指定所有输入的数据 vars

In [77]: vars(mybook)
Out[77]: {'author': 'Lee', 'title': 'HTML',...}
Run Code Online (Sandbox Code Playgroud)

我在控制台中输入了很多关于mybook的数据.当尝试调用get_entry方法时,错误报告.

mybook.get_entry()
ValueError: cannot switch from manual field specification to automatic field numbering.
Run Code Online (Sandbox Code Playgroud)

所有这一切都在控制台上以交互模式进行.我珍惜数据输入,进一步mybook在文件中挑选对象.但是,它有缺陷.如何在交互模式下拯救它.或者我必须重新开始.

python string-formatting python-3.x

16
推荐指数
1
解决办法
2万
查看次数

为什么000在Python 3中评估为0?

由于八进制前缀现在0o在Python 3中,因此再写不合法0777.好的.

那么为什么编写00哪个评估正确0而其他数字触发语法错误是合法的呢?

>>> 01
  ...
  File "<interactive input>", line 1
    01
     ^
SyntaxError: invalid token
>>> 
>>> 00
0
Run Code Online (Sandbox Code Playgroud)

python int literals

15
推荐指数
1
解决办法
833
查看次数

合并多个CSV文件而不重复标题(使用Python)

我是Python的初学者.我有多个CSV文件(超过10个),并且它们都具有相同数量的列.我想将它们合并到一个CSV文件中,我不会重复标题.

所以基本上我需要只有第一行包含所有标题,然后我需要合并所有CSV文件中的所有行.我该怎么做呢?

任何帮助表示赞赏.

谢谢!

python csv

14
推荐指数
3
解决办法
3万
查看次数

为什么我没有在这个琐碎的例子中得到gcc的"未使用的未初始化"警告?

如何在序列反转程序中修复此分段错误再一次是一个愚蠢的未初始化的变量错误.

所以我打算重复"请使用-Wall标志"评论,但当我测试代码反对警告时,我发现没有任何警告报告给我的惊喜.

所以我把它修改为下面这个(这段代码对执行目的毫无意义,但它说明了我想要展示的内容):

#include <stdio.h>

int main()
{

  int i,len=12;

  /* printf("%d\n",i); */

  while(i!=len-1)
  {

    i++;
    len--;
  }

 return 0;
 }
Run Code Online (Sandbox Code Playgroud)

使用gcc4.7.3和6.2.1 编译时

gcc -Wall -Wextra -pedantic
Run Code Online (Sandbox Code Playgroud)

我没有得到任何警告,而iwhile循环中使用之前公然没有初始化.

现在如果我取消注释printf我得到的陈述:

warning: 'i' is used uninitialized in this function [-Wuninitialized]
Run Code Online (Sandbox Code Playgroud)

那么,为什么经过时发出警告,iprintf,但不是在while考验?

(不同的gcc没有警告未初始化的变量,因为在我的情况下,没有分支)

(听起来像一个小虫,但它是如此微不足道,我想知道我是不是错过了一些巨大的东西.)

c gcc compiler-warnings

14
推荐指数
1
解决办法
786
查看次数

如果用户输入非数字字符,如何仅扫描整数并重复读取?

这是一个年轻的tyro问题,C代码试图阻止用户输入一个小于0或大于23的字符或整数.

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    const char *input;
    char *iPtr;
    int count = 0;
    int rows;

    printf("Enter an integer: ");
    scanf("%s", input);
    rows = strtol(input, &iPtr, 0);
    while( *iPtr != '\0') // Check if any character has been inserted
    {
        printf("Enter an integer between 1 and 23: ");
        scanf("%s", input);
    }
    while(0 < rows && rows < 24) // check if the user input is within the boundaries
    {
        printf("Select an integer from 1 to 23: "); …
Run Code Online (Sandbox Code Playgroud)

c validation user-input

13
推荐指数
1
解决办法
10万
查看次数

python如何优化条件列表推导

在Python中没有[]读过关于列表理解的内容,所以现在我知道了

''.join([str(x) for x in mylist])
Run Code Online (Sandbox Code Playgroud)

比...更快

''.join(str(x) for x in mylist)
Run Code Online (Sandbox Code Playgroud)

因为"列表推导得到高度优化"

所以我认为优化依赖于for表达式的解析,查看mylist,计算其长度,并使用它来预先分配精确的数组大小,这节省了大量的重新分配.

使用时''.join(str(x) for x in mylist),join盲目地接收发电机,并且必须在不事先知道尺寸的情况下建立其列表.

但现在考虑一下:

mylist = [1,2,5,6,3,4,5]
''.join([str(x) for x in mylist if x < 4])
Run Code Online (Sandbox Code Playgroud)

python如何决定列表理解的大小?它是根据大小计算的mylist,并且在迭代完成时缩小(如果列表很大并且条件过滤掉99%的元素,这可能非常糟糕),或者它是否会恢复为"不知道提前大小"案例?

编辑:我做了一些小基准测试,似乎确认有一个优化:

没有条件:

import timeit

print(timeit.timeit("''.join([str(x) for x in [1,5,6,3,5,23,334,23234]])"))
print(timeit.timeit("''.join(str(x) for x in [1,5,6,3,5,23,334,23234])"))
Run Code Online (Sandbox Code Playgroud)

收益率(如预期):

3.11010817019474
3.3457350077491026
Run Code Online (Sandbox Code Playgroud)

有条件:

print(timeit.timeit("''.join([str(x) for x in [1,5,6,3,5,23,334,23234] if x < 50])"))
print(timeit.timeit("''.join(str(x) for x in [1,5,6,3,5,23,334,23234] if …
Run Code Online (Sandbox Code Playgroud)

python performance list-comprehension

13
推荐指数
1
解决办法
616
查看次数

R v3.4.0-2无法在Arch上找到libgfortran.so.3

我刚刚度假一个月,所以无法说明发生这种情况的确切点,但是R从官方的Arch repos现在无法启动,引用

/usr/lib64/R/bin/exec/R: error while loading shared libraries: 
libgfortran.so.3: cannot open shared object file: No such file or directory
Run Code Online (Sandbox Code Playgroud)

我认为也许一个符号链接被错误地放置或销毁,所以我查看了/ usr/lib来尝试找到它:

ls -halt /usr/lib/libgfortran.so.*

lrwxrwxrwx 1 root root   20 May 16 03:01 /usr/lib/libgfortran.so.4 -> libgfortran.so.4.0.0
-rwxr-xr-x 1 root root 7.1M May 16 03:01 /usr/lib/libgfortran.so.4.0.0
Run Code Online (Sandbox Code Playgroud)

libfortran.so.3libgfortran.so.4Arch 取代?如果是这样,是否有任何可能的解决方法R来运行旧版本?


pacman -Qi r

Name            : r
Version         : 3.4.0-2
Description     : Language and environment for statistical computing and graphics
Architecture    : x86_64
URL             : http://www.r-project.org/
Licenses …
Run Code Online (Sandbox Code Playgroud)

r gfortran archlinux pacman-package-manager

12
推荐指数
1
解决办法
6840
查看次数