Fixed bug: Pointers to vector internas were given away and became invalid because of resizing the vector

This commit is contained in:
Adrian Imboden 2013-02-12 23:43:02 +01:00
parent 72b5b7acae
commit 6149beb920
2 changed files with 14 additions and 7 deletions

View File

@ -251,6 +251,8 @@ public:
/// Update linked times
private:
Binder(const Binder&);
/// Don't copy the binder
virtual void bind(std::size_t, const char* const&, Direction)
/// Binds a const char ptr.
@ -265,7 +267,7 @@ private:
private:
std::vector<MYSQL_BIND> _bindArray;
std::vector<MYSQL_TIME> _dates;
std::vector<MYSQL_TIME*> _dates;
};

View File

@ -49,6 +49,11 @@ Binder::Binder()
Binder::~Binder()
{
for (std::vector<MYSQL_TIME*>::iterator it = _dates.begin(); it != _dates.end(); ++it)
{
delete *it;
*it = 0;
}
}
@ -188,9 +193,9 @@ void Binder::bind(std::size_t pos, const DateTime& val, Direction dir)
mt.time_type = MYSQL_TIMESTAMP_DATETIME;
_dates.push_back(mt);
_dates.push_back(new MYSQL_TIME(mt));
realBind(pos, MYSQL_TYPE_DATETIME, &_dates.back(), sizeof(mt));
realBind(pos, MYSQL_TYPE_DATETIME, _dates.back(), sizeof(MYSQL_TIME));
}
@ -203,9 +208,9 @@ void Binder::bind(std::size_t pos, const Date& val, Direction dir)
mt.month = val.month();
mt.day = val.day();
_dates.push_back(mt);
_dates.push_back(new MYSQL_TIME(mt));
realBind(pos, MYSQL_TYPE_DATE, &_dates.back(), sizeof(mt));
realBind(pos, MYSQL_TYPE_DATE, _dates.back(), sizeof(MYSQL_TIME));
}
@ -220,9 +225,9 @@ void Binder::bind(std::size_t pos, const Time& val, Direction dir)
mt.time_type = MYSQL_TIMESTAMP_TIME;
_dates.push_back(mt);
_dates.push_back(new MYSQL_TIME(mt));
realBind(pos, MYSQL_TYPE_TIME, &_dates.back(), sizeof(mt));
realBind(pos, MYSQL_TYPE_TIME, _dates.back(), sizeof(MYSQL_TIME));
}