C++DB is the database layer that was designed to work with C++CMS. This customized version is used within Ye Ol' Pi Shack.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

30 lines
980 B

  1. /*! \page escaping Escaping Strings
  2. \note Before you read this, remember escaping strings directly and including them in SQL statements is \a bad idea, you should
  3. use \ref stat "prepared statements" instead. However if you really know what you are doing, continue reading.
  4. You can escape strings from unknown source using session's \ref cppdb::session::escape() "escape()" functions. Also
  5. note that they do not add first and last quotation marks and you are expected to do this on your own.
  6. For example:
  7. \code
  8. std::string safe_data = sql.escape(data);
  9. sql << "INSERT INTO names(name) values('" + safe_data + "')" << cppdb::exec;
  10. \endcode
  11. Please notice the quotes inserted in the query.
  12. But still it is better to do following:
  13. \code
  14. sql << "INSERT INTO names(name) values(?)" << data << cppdb::exec;
  15. \endcode
  16. \note \ref odbc "ODBC" backend does not support escaping strings and would throw \ref cppdb::not_supported_by_backend "not_supported_by_backend" exception.
  17. */