2017-06-05 39 views
-3

我想改变sqlite数据库中的sql长度限制,使用c#连接。 有人可以帮我吗?Sqlite重新定义SQLITE_MAX_SQL_LENGTH c#

这里是sqlitecommand:

json字符串是一个非常大的字符串。

try 
{ 
    string sql = "INSERT INTO SIP_JSON (sip_code, json) VALUES (" + nextSipCode 
      + ",'" + json + "')"; 
    connection.Open(); 
    SQLiteCommand command = new SQLiteCommand(sql, connection); 
    command.ExecuteNonQuery(); 
} 
catch (Exception e) 
{ 
    throw new Exception(Exceptions.GATEWAYDB_INSESRTSIPJSON_EXCEPTION, e); 
} 
finally 
{ 
     connection.Close(); 
} 

的例外是:内存

+1

如果您遇到问题,您可以发布您已经尝试过的解决方案,并提供[最小,完整和可验证的示例](https://stackoverflow.com/帮助/ MCVE)。我建议阅读[如何问](http://stackoverflow.com/help/how-to-ask)一个很好的问题。此外,一定要采取[旅游](https://stackoverflow.com/tour) –

+1

超过该限制的错误消息将是“语句太长”。 *是那个JSON的长度?你为什么不使用SQL参数? –

+0

以上所有内容,加上[从此SQLite文档页面的第3部分](https://www.sqlite.org/limits.html)**(a)**您只能在运行时降低_ **此值(即在连接字符串中) - 你需要重新编译SQLite来提升它;和**(b)**你不应该这样做 - 使用准备好的陈述和装订。 – TripeHound

回答

1

感谢TripeHound,我改变我的查询使用准备好的语句。

try 
       { 
        connection.Open(); 
        SQLiteCommand command = new SQLiteCommand(connection); 
        command.CommandText = "INSERT INTO SIP_JSON (sip_code, json) VALUES (?,?)"; 
        command.Parameters.Add(new SQLiteParameter("sip_code",nextSipCode)); 
        command.Parameters.Add(new SQLiteParameter("json", json)); 
        command.ExecuteNonQuery(); 
       } 
       catch (Exception e) 
       { 
        throw new Exception(Exceptions.GATEWAYDB_INSESRTSIPJSON_EXCEPTION, e); 
       } 
       finally 
       { 
        connection.Close(); 
       }