小编The*_*ral的帖子

postgres中的条件INSERT INTO语句

我正在为模拟航空公司预订数据库编写预订程序,我真正想做的是这样的:

IF EXISTS (SELECT * FROM LeadCustomer 
    WHERE FirstName = 'John' AND Surname = 'Smith') 
THEN
   INSERT INTO LeadCustomer (Firstname, Surname, BillingAddress, email) 
   VALUES ('John', 'Smith', '6 Brewery close,
            Buxton, Norfolk', cmp.testing@example.com');
Run Code Online (Sandbox Code Playgroud)

但Postgres不支持IF语句而不加载PL/pgSQL扩展.我想知道是否有办法做一些相当于这个或者如果在这一步中只需要进行一些用户交互?

database postgresql conditional-statements insert-into

38
推荐指数
2
解决办法
4万
查看次数

重载>>运算符以读入文本文件

有这个代码重载>>来读取文本文件:

std::istream& operator>> (std::istream &in, AlbumCollection &ac)
    {
        std::ifstream inf("albums.txt");

        // If we couldn't open the input file stream for reading
        if (!inf)
        {
        // Print an error and exit
            std::cerr << "Uh oh, file could not be opened for reading!" << std::endl;
            exit(1);
        }

        // While there's still stuff left to read
        while (inf)
        {
            std::string strInput;
            getline(inf, strInput);
            in >> strInput;
        }
Run Code Online (Sandbox Code Playgroud)

被称为:

AlbumCollection al = AlbumCollection(albums);
cin >> al;
Run Code Online (Sandbox Code Playgroud)

该文件位于源目录中,与.exe位于同一目录中,但始终表示文件无法正常处理.很抱歉,如果答案非常明显,这是我第一次尝试用C++读取文本文件; 我真的不明白为什么这不起作用,我能找到的在线帮助似乎并没有表明我做错了什么....

c++ io overloading

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

<operator不应该返回true

我正在尝试使用sort函数(sort(cards.begin(), cards.end());)将某些枚举按升序排序,但它似乎没有正确排序它们.它按顺序返回它们:

card3   {rank=SEVEN (7) suit=CLUBS (0) }
card4   {rank=TWO (2) suit=HEARTS (2) }
card5 = {rank=NINE (9) suit=SPADES (3) } 
Run Code Online (Sandbox Code Playgroud)

我怀疑这是我的比较运算符重载的问题,这是:

inline bool operator<(const Card& c1, const Card& c2)
{
    return c1.getRank() < c2.getRank() &&
           c1.getSuit() < c2.getSuit();
}
Run Code Online (Sandbox Code Playgroud)

据我所知,在比较card3和card4时,只有比较的右边是真的,因此它应该返回false但是当card3<card4它返回true时!

我可能会在这里误解逻辑,但这对我没有任何意义....

谢谢你的时间 :)

c++ sorting comparison operator-overloading

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

尝试使用cout打印向量中包含的对象列表并进行排序是错误的

我有一个专辑类,用于存储和艺术家姓名(字符串),专辑标题(字符串)和轨道对象列表(矢量).我正在尝试重载"<<"运算符以启用基于流的输出.

相关代码是这样的:

std::ostream& Album::printTracks (std::ostream &out, std::vector<Track> &t)
{
    unsigned int i;
    for (i=0; i<t.size(); i++)
        out << " " << t.at(i);
     return out;
}
std::ostream& operator<< (std::ostream &out, Album &a)
{
    out << "Artist name: " << a.artistName << "\n" <<
        "Album Title: " << a.albumTitle << "\n" <<
        "Tracks: " << a.printTracks(out,a.getTracks());
    return out;
}
Run Code Online (Sandbox Code Playgroud)

哪个应按此顺序打印:

  • 艺术家的名字
  • 专辑标题
  • 跟踪列表

相反,当我给它测试数据时,它打印出来:

  • 跟踪列表
  • 艺术家的名字
  • 专辑标题

"曲目:"后跟一个记忆位置.

Constructor for "Track Class" is:
Track::Track (std::string t, Duration* d)
    {
        title = t; …
Run Code Online (Sandbox Code Playgroud)

c++ io operator-overloading

0
推荐指数
1
解决办法
101
查看次数

VHDL时钟分频器在板上工作但在仿真中失败

我目前正在尝试使用VHDL设计交通灯控制器,我正在Altera EPM240T100C5上编程,带有用于显示交通信号灯的自定义扩展板.由于电路板上最慢的时钟设置仍然比我想要的快,我需要写一个时钟分频器,我这样做:

LIBRARY ieee;
USE ieee.std_logic_1164.all; 

entity clockdivider is 
    port
    (
        clkin :  in  std_logic;
        dividedclk :  out  std_logic
    );
end clockdivider;

architecture divider of clockdivider is 

signal  J :  std_logic;
signal  K :  std_logic;


begin
J <= '1';
K <= '1';


process(clkin)
variable tempdividedclk : std_logic;
begin
if (rising_edge(clkin)) then
    tempdividedclk := (NOT(tempdividedclk) AND J) OR (tempdividedclk AND (NOT(K)));
end if;
    dividedclk <= '0';
    dividedclk <= tempdividedclk;
end process;

END divider;
Run Code Online (Sandbox Code Playgroud)

这在主板上运行良好,但在模拟器(ModelSim)中,"divideclk"输出无法初始化为任何东西.我想知道是否有人知道为什么?

clock vhdl simulate intel-fpga divider

0
推荐指数
1
解决办法
228
查看次数