diff --git a/CMakeLists.txt b/CMakeLists.txt index 655c32f..d6d9f8d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,6 +106,7 @@ else() crypto lua5.3 pthread + sqlite3 ) endif() diff --git a/src/core/log.cpp b/src/core/log.cpp index 9e8c5c9..8833da9 100644 --- a/src/core/log.cpp +++ b/src/core/log.cpp @@ -36,6 +36,15 @@ #include #endif #define DEBUG_INFO 0 +std::string escapeString(const std::string& str) { + std::string escapedStr = str; + size_t pos = 0; + while ((pos = escapedStr.find("'", pos)) != std::string::npos) { + escapedStr.insert(pos, "'"); + pos += 2; + } + return escapedStr; +} inline std::string typestring(fastweb::log::log_type type) { @@ -220,7 +229,7 @@ bool fastweb::log::write() #endif m_file.appead(logcontent); if(app()->config->log.sqlite) - m_sqlite.exec("INSERT INTO log(type,create_at,content,flag)VALUES(" + std::to_string(li.type) + ",'"+li.create_at+"','"+li.msg+"',0)"); + m_sqlite.exec("INSERT INTO log(type,create_at,content,flag)VALUES(" + std::to_string(li.type) + ",'"+li.create_at+"','"+ escapeString(li.msg)+"',0)"); } return true; }