Aidenboss
V2EX  ›  C

作为初学者,写了一个简单的 C++ 使用代码转换成 SQL 语句的小小小程序

  •  
  •   Aidenboss · Nov 18, 2018 · 3543 views
    This topic created in 2756 days ago, the information mentioned may be changed or developed.

    RT,作为 C++ 的初学者,写了一个简单的小工具。 DELETE 语句可以写成:

    Condition *passwordCondition = new Condition();
    passwordCondition->field(new string("password"))->ship(Ship::NOT_EXISTED);
    Where *where = new Where();
    where->condition(passwordCondition);
    
    Delete *aDelete = new Delete();
    aDelete->table(new string("user"))->where(where);
    cout << *aDelete->toString() << endl;
    

    output

    DELETE FROM user
    WHERE (`password` IS NULL)
    

    github 地址: https://github.com/yemingfeng/csql

    10 replies    2018-11-19 14:08:23 +08:00
    misaka19000
        1
    misaka19000  
       Nov 18, 2018 via Android
    资瓷
    1010543618
        2
    1010543618  
       Nov 18, 2018
    感觉可以参考下这个 http://codeigniter.org.cn/user_guide/database/examples.html

    php 和 c 也很靠边嘛
    Aidenboss
        3
    Aidenboss  
    OP
       Nov 18, 2018
    @1010543618 现在只生成了 SQL 语句哈,可以准备和 MySQL Client 配合使用了。感谢提供的参考文档~
    Kilerd
        4
    Kilerd  
       Nov 18, 2018
    考虑下在 readme 里面吧代码块加上 语言标志,不然没有代码高亮
    Aidenboss
        5
    Aidenboss  
    OP
       Nov 18, 2018
    @Kilerd 谢谢反馈,已加
    lwh0328
        6
    lwh0328  
       Nov 19, 2018
    同样在学 C++,一起加油哦!
    shoujiaxin
        7
    shoujiaxin  
       Nov 19, 2018 via iPhone
    main 里 new 的指针好像都没有 delete ?还是用 shared_ptr 吧
    Aidenboss
        8
    Aidenboss  
    OP
       Nov 19, 2018
    @shoujiaxin 好的好的,确实没有 delete,老师教的都忘记了。过会儿补上。顺便学习下 shared_ptr。
    lqxandxy
        9
    lqxandxy  
       Nov 19, 2018
    要 c++11 吗? 还是 c++98 就可以用了
    Aidenboss
        10
    Aidenboss  
    OP
       Nov 19, 2018
    @lqxandxy IDE 是 clion,C++ 11 才可以。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3006 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 44ms · UTC 09:04 · PVG 17:04 · LAX 02:04 · JFK 05:04
    ♥ Do have faith in what you're doing.