List:MySQL++« Previous MessageNext Message »
From:zhuang yan Date:March 19 2017 2:02pm
Subject:A bug of "Query::store(const char*, int)"
View as plain text  
Version: mysql++-3.2.3<http://tangentsoft.net/mysql++/releases/mysql++-3.2.3.tar.gz>

// ===part 1===== //
In ::store(const char* str, size_t len)
522 {
523        if ((parse_elems_.size() == 2) && !template_defaults.processing_) {
              …
              return store(SQLQueryParms() << str << len );
       }

Line 523 :  MUST change 3 from 2, like this:

StoreQueryResult
Query::store(const char* str, size_t len)
{
--   if ((parse_elems_.size() == 2) && !template_defaults.processing_) {
++   if ((parse_elems_.size() == 3 /* !!THREE!! */) && !template_defaults.processing_) {
              …
              return store(SQLQueryParms() << str << len );
       }

// ===part 2===== //

Because the “parse_elems.size() always  one more then placeholders ”
Pls  goto  “query.cpp” line 267

266 void
267 Query::parse()
268 {
       /* … */

361 parse_elems_.push_back(SQLParseElement(str, ' ', -1));
       delete[] s0;
}

Look at line 361, here ALWAYS PUSH A endl emlem to elems!

// ===part 3===== //
Why I found this bug?

Example :

Q < “SELECT %0  FROM user_table WHERE id = %1 ”;
Q.parse();
cout << Q.str(“name”,  1) << endl; //will output  good SQL : SELECT name FROM user_table WHERE id = 1
Q.store(“name”, 1);  //<< throw a exception!

Thank you for your read.


发送自 Windows 10 版邮件<https://go.microsoft.com/fwlink/?LinkId=550986>应用

Thread
A bug of "Query::store(const char*, int)"zhuang yan19 Mar 2017