none
Sqlite如何把字符串当成sql语句执行? RRS feed

  • 问题

  • 如题,

    我使用sqlite,用select语句的一些技巧,组成成了一个select语句的sql形式的字符串,现在要如何把这段sql形式的语句的字符串当成sql语句执行了,目前我在网上没有查到相关函数。有知道的吗?难道只能把组成的sql语句发给客户端程序,客户端在用sqlite的dll执行吗?

    例如

    select 'select * from t_test'
    这句select语句查询出单个字符串结果怎么当成sql语句执行


    2019年8月3日 4:30

全部回复

  • Hi,

    我不太明白你想要实现的是什么,你能详细说一下吗。一般执行sqlite中执行查询语句会使用如下代码,

        SQLiteCommand sqlCom = new SQLiteCommand("Select * From Table1", m_dbConnection);
    
        SQLiteDataReader sqlDataReader = sqlCom.ExecuteReader();

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2019年8月5日 5:15
  • Hi,

    我不太明白你想要实现的是什么,你能详细说一下吗。一般执行sqlite中执行查询语句会使用如下代码,

        SQLiteCommand sqlCom = new SQLiteCommand("Select * From Table1", m_dbConnection);
    
        SQLiteDataReader sqlDataReader = sqlCom.ExecuteReader();

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    与C#无关,我的目的是需要通过sqlite来动态拼接一个select语句,交给sqlite帮我执行拼接好的动态select语句,换成sql server,那就是使用exec函数,执行把字符串当成sql执行,例如 exec ('select 1,1+2'),请问sqlite有类似操作吗?
    2019年8月5日 9:29
  • Hi,

    SQLite中存在类似的“execute”方法,你可以看一下这个链接中的示例。

    https://www.php.net/manual/zh/sqlite3.exec.php

    https://www.liaoxuefeng.com/wiki/897692888725344/926177394024864

    Regards,

    Kyle

    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2019年8月6日 3:05
  • 请参考一下脚本:


    ericzhou

    2019年8月6日 9:05