Hi, ive been having this problem, and I believe i've narrowed it down to
something im doing wrong with mysqlpp.
I've asked on other forums and they told me they dont know whats wrong
because, barring mysqlpp, my code is fine.
The problem is: This loop runs every 5 seconds and my intention is to
write to a file the results of the query each iteration, however, this
file keeps growing bigger and bigger instead of being truncated to 0 each
time and starting over from scratch. I've tried flushing the file, using
ofstream::trunc while opening, and as far as i know, the ofstream handler
is doing its job. The file is opened and truncated, however when i write
to the file (using <<), it writes all data that has been written in the
past as well as any new data (i assume there is some buffer that never
gets cleared), this is my problem.
I know it may seem confusing, maybe my spaghetti code will clear things up
:)
------------------------------------------------------------------------------
#include "util.h"
#include <mysql++.h>
#include <custom.h>
#include "tastatus_ssqls.h"
#include <iostream>
#include <iomanip>
#include <vector>
#include <fstream>
using namespace std;
using namespace mysqlpp;
int main(int argc, const char *argv[]) {
vector<tastatus> ta;
char delim[5] = ",";
cout << "Connecting to MySQL...";
Connection conn("--EDITED--","--EDITED--","--EDITED--","--EDITED--");
cout << "success!" << endl;
Query ta_status = conn.query();
string query = "SELECT * FROM --EDITED--";
int run = 0;
while (run < 1) { //Run forever
ofstream tafile("tafile.txt");
//ofstream tafile("tafile.txt", ofstream::out | ofstream::trunc); //
This doesnt make a difference
ta_status << query;
ta_status.storein(ta);
for (vector<tastatus>::iterator it = ta.begin(); it != ta.end(); ++it)
{
tafile << it->address << delim << it->status << delim
<<
it->last_req << delim << it->last_command << delim <<
it->updated << endl;
//basically creating a CSV
}
sleep(5); //Loop every 5 seconds...
//tafile.flush(); //no difference
//cout.flush(); //no difference
//tafile.close(); // This doesnt make a difference either
}
conn.close();
return 0;
}
---------------------------------------------------------------------------------------
Here is my SSQLS declaration (inside "tastatus_ssqls.h"):
------------------------------------------------------------
sql_create_6(tastatus, 1, 0,
mysqlpp::sql_char, address,
mysqlpp::sql_char, host,
mysqlpp::sql_char, status,
mysqlpp::sql_int, last_req,
mysqlpp::sql_char, last_command,
mysqlpp::sql_char, updated)
------------------------------------------------------------
Thanks for any help!,
--
David Della Vecchia
Vacation Express
davidd@stripped