Looks to me like it might be memory corruption. You're probably going out of bounds on one of your string buffers and text is "spilling" into your begin/end buffers. Probably 'statement' simply isn't large enough to hold all of the text you're copying to it.
You might want to consider switching from C style strings over to C++'s string and stringstream . This will make memory corruption caused by buffer overflow virtually impossible:
(also seems weird that you're using hd_begin as a string when really it's just a single char):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
int create_statement(char hd_begin, stringstream& statement, ...)
{
statement << "SELECT * FROM (SELECT * FROM dj_music WHERE hd='";
statement << hd_begin;
if(hd_begin == 'A') hd_begin = 'B';
else hd_begin = 'A';
statement << "'AND (";
for(k = begin[j]; k <= end[j]; ++k)
{
statement << "(classnumber=" << hd_begin << k << ')';
if(k < end[j])
statement << " OR ";
}
// ...
1 2 3 4 5 6 7 8 9 10
stringstream statement(stringstream::in | stringstream::out);
create_statement(hd_begin,staement,one_set_begin,one_set_end);
// to get a c-style string from that, get a std::string first
string str = statement.str();
// then get a c-string
constchar* buffer = str.c_str();
// 'buffer' remains valid until 'str' loses scope.