List:MySQL++« Previous MessageNext Message »
From:Mathieu Pagé Date:November 13 2006 12:38am
Subject:Exception of type std::length_error
View as plain text  
Hi everyone,

I hope this has not been asked before, I searched the online archives of 
the list and could not find any references to my problem.

I'm trying to run a simple test program based on the simple1 example. I 
can get connected to the DB, I create a query and execute it. q.size() 
return 4 wich is the number of row I expected so the query is fine. Then 
I try to enumerate the result of the query like this :

<code>
mysqlpp::Row row;
mysqlpp::Row::size_type i;
for (i = 0; row = res.at(i); ++i)
   cout <<row.at(0) <<endl;
</code>

however I get an length_error exception on "row = res.at(i)".

Since I'm new to MySQL++, maybe i'm doing something stupid and someone 
can point me to it.

Thanks in advance.

Mathieu Pagé








Complete code :
#include <mysql++.h>

#include <iostream>
#include <exception>

using namespace std;

int main(int argc, char* argv[])
{
   try
   {
      // On se connecte à la DB
      mysqlpp::Connection con(true);
      con.connect("chess", "localhost", "root", "SomePassword");

      if (!con)
      {
         cout <<"erreur" <<endl
              <<con.error() <<endl;

         return 1;
      }

      // On créer une requête
      mysqlpp::Query q = con.query();
      q <<"SELECT NomJoueur FROM tblJoueurs";

      // On exécute la requête
      mysqlpp::Result res = q.store();

      cout <<"Il y as : " <<res.size() <<" lignes." <<endl;

      // On affiche la liste des joueurs
      if (res && res.size() > 0)
      {
         mysqlpp::Row row;
         mysqlpp::Row::size_type i;
         for (i = 0; row = res.at(i); ++i)
         {
            cout <<row.at(0) <<endl;
         }
      }
      else
      {
         cout <<"Erreur dans la requête : " <<q.error() <<endl;
         return 1;
      }


   }
   catch (mysqlpp::ConnectionFailed e)
   {
      cout <<e.what() <<endl;
   }

   return 0;
}
Thread
Exception of type std::length_errorMathieu Pagé13 Nov
  • Re: Exception of type std::length_errorWarren Young14 Nov
    • Re: Exception of type std::length_errorMathieu Pagé14 Nov
Re: Exception of type std::length_errorMathieu Pagé19 Nov
  • Re: Exception of type std::length_errorWarren Young20 Nov
    • Running Totals with MySQLKerry Frater21 Nov
      • RE: Running Totals with MySQLKerry Frater21 Nov
      • Re: Running Totals with MySQLWarren Young22 Nov
        • RE: Running Totals with MySQLKerry Frater28 Nov