Mailing List
Home
Forum Home
MySQL General - General MySQL discussion
MySQL++ - Programming with the C++ API to MySQL
MaxDB - Everything about MaxDB, formerly known as SAP DB
ODBC - ODBC with the MySQL Connector/ODBC driver
MySQL on Win32 - Runing MySQL on Windows 9x/Me/NT/2000/XP
Java Help - Mostly related to the MySQL Connector/J driver
Perl - Perl support for MySQL with DBI and DBD::mysql
GUI - MySQL GUI Tools
Announcement
Subjects
mysql openssl Question
mysql:it 's a db not a dbms how it 's possible?!
Does the binary log enabling affect the MySQL performances?
Strange behavior, Table Level Permission
FULLTEXT query format question
Preventing Duplicate Entries
Comparing and writing out BLOBS
Executing MySQL Commands From Within C Program
Can 't access mysql after kernel upgrade
Mysql 4 0 Oracle Stored Procedure Trigger Conversion
Downgrade Mysql from 4 to 3 23
MySQL Cluster Software
mysql test 4 1 fails with the gis test
ERROR 2002: Can 't connect to local MySQL server through socket
Getting Identity after INSERT
Update one field with more fields from another table
ERROR 1045: Access denied for user: 'root@localhost ' (Using
password: NO)
mysql have same function mthod as Oracle decode()
 
Buffer Problems?

Buffer Problems?

2006-12-21       - By David Della Vecchia

 Back
Reply:     1     2     3  

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@(protected)

--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe:    http://lists.mysql.com/plusplus?unsub=mysql@(protected)